Pārlūkot izejas kodu

passed first 3 test classes

mpierse 6 gadus atpakaļ
vecāks
revīzija
b0709498a1

+ 20
- 1
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Parādīt failu

@@ -22,7 +22,26 @@ public class ArrayUtility<E> {
22 22
         return counter;
23 23
     }
24 24
 
25
-    public  merge(E[] arrayToMerge) {
25
+    public void merge(E[] arrayToMerge) {
26
+        for(E el : arrayToMerge){
27
+            list.add(el);
28
+        }
29
+    }
30
+
31
+    public E getMostCommonFromMerge(E[] arrayToMerge) {
32
+       merge(arrayToMerge);
33
+       int frequencey = Integer.MIN_VALUE;
34
+        E mostCommonElement =null;
35
+        for (E el : list){
36
+            if (getNumberOfOccurrences(el)>frequencey){
37
+                frequencey = getNumberOfOccurrences(el);
38
+                mostCommonElement = el;}
39
+        }
40
+        return mostCommonElement;
41
+    }
26 42
 
43
+    public int countDuplicatesInMerge(E[] arrayToMerge, E valueToEvaluate) {
44
+        merge(arrayToMerge);
45
+       return getNumberOfOccurrences(valueToEvaluate);
27 46
     }
28 47
 }

+ 2
- 2
src/test/java/com/zipcodewilmington/arrayutility/ArrayUtilityTestSuite.java Parādīt failu

@@ -10,8 +10,8 @@ import org.junit.runners.Suite;
10 10
 @RunWith(Suite.class)
11 11
 
12 12
 @Suite.SuiteClasses({
13
-//        CountDuplicatesInMergeTest.class,
14
-//        GetMostCommonFromMergeTest.class,
13
+        CountDuplicatesInMergeTest.class,
14
+        GetMostCommonFromMergeTest.class,
15 15
         GetNumberOfOccurrencesTest.class,
16 16
 //        RemoveValueTest.class
17 17
 })

+ 67
- 67
src/test/java/com/zipcodewilmington/arrayutility/CountDuplicatesInMergeTest.java Parādīt failu

@@ -7,70 +7,70 @@ import org.junit.Test;
7 7
  * Created by leon on 3/1/18.
8 8
  * The purpose of this class is to thoroughly test the method countDuplicatesInMerge()
9 9
  */
10
-//public class CountDuplicatesInMergeTest {
11
-//    @Test
12
-//    public void integerTest() {
13
-//        // Given
14
-//        Integer valueToEvaluate = 7;
15
-//        Integer expected = 5;
16
-//        Integer[] inputArray = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8, valueToEvaluate};
17
-//        Integer[] arrayToMerge = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8};
18
-//        ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
19
-//
20
-//        // When
21
-//        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
22
-//
23
-//        // Then
24
-//        Assert.assertEquals(expected, actual);
25
-//    }
26
-//
27
-//    @Test
28
-//    public void longTest() {
29
-//        // Given
30
-//        Long valueToEvaluate = 7L;
31
-//        Integer expected = 6;
32
-//        Long[] inputArray = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate};
33
-//        Long[] arrayToMerge = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate};
34
-//        ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
35
-//
36
-//        // When
37
-//        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
38
-//
39
-//        // Then
40
-//        Assert.assertEquals(expected, actual);
41
-//    }
42
-//
43
-//    @Test
44
-//    public void stringTest() {
45
-//        // Given
46
-//        String valueToEvaluate = "a";
47
-//        Integer expected = 7;
48
-//        String[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate};
49
-//        String[] arrayToMerge = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate, valueToEvaluate};
50
-//
51
-//        ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
52
-//
53
-//        // When
54
-//        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
55
-//
56
-//        // Then
57
-//        Assert.assertEquals(expected, actual);
58
-//    }
59
-//
60
-//    @Test
61
-//    public void objectTest() {
62
-//        // Given
63
-//        Object valueToEvaluate = "a";
64
-//        Integer expected = 8;
65
-//        Object[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate};
66
-//        Object[] arrayToMerge = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate, valueToEvaluate, valueToEvaluate};
67
-//
68
-//        ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
69
-//
70
-//        // When
71
-//        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
72
-//
73
-//        // Then
74
-//        Assert.assertEquals(expected, actual);
75
-//    }
76
-//}
10
+public class CountDuplicatesInMergeTest {
11
+    @Test
12
+    public void integerTest() {
13
+        // Given
14
+        Integer valueToEvaluate = 7;
15
+        Integer expected = 5;
16
+        Integer[] inputArray = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8, valueToEvaluate};
17
+        Integer[] arrayToMerge = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8};
18
+        ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
19
+
20
+        // When
21
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
22
+
23
+        // Then
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void longTest() {
29
+        // Given
30
+        Long valueToEvaluate = 7L;
31
+        Integer expected = 6;
32
+        Long[] inputArray = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate};
33
+        Long[] arrayToMerge = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate};
34
+        ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
35
+
36
+        // When
37
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
38
+
39
+        // Then
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void stringTest() {
45
+        // Given
46
+        String valueToEvaluate = "a";
47
+        Integer expected = 7;
48
+        String[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate};
49
+        String[] arrayToMerge = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate, valueToEvaluate};
50
+
51
+        ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
52
+
53
+        // When
54
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
55
+
56
+        // Then
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+    @Test
61
+    public void objectTest() {
62
+        // Given
63
+        Object valueToEvaluate = "a";
64
+        Integer expected = 8;
65
+        Object[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate};
66
+        Object[] arrayToMerge = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate, valueToEvaluate, valueToEvaluate};
67
+
68
+        ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
69
+
70
+        // When
71
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
72
+
73
+        // Then
74
+        Assert.assertEquals(expected, actual);
75
+    }
76
+}