Leon 6 years ago
parent
commit
5e84ce3089
24 changed files with 327 additions and 75 deletions
  1. 15
    0
      src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java
  2. 4
    2
      src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java
  3. 5
    1
      src/main/java/rocks/zipcode/io/quiz3/collections/Student.java
  4. 18
    0
      src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java
  5. 0
    16
      src/test/java/rocks/zipcode/io/quiz3/TestUtils.java
  6. 0
    22
      src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/ConstructorTest.java
  7. 1
    1
      src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/GetColumnTest.java
  8. 1
    1
      src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/GetRowTest.java
  9. 1
    1
      src/test/java/rocks/zipcode/io/quiz3/arrays/wavegenerator/WaveTest.java
  10. 41
    0
      src/test/java/rocks/zipcode/io/quiz3/collections/student/GetLabTest.java
  11. 12
    9
      src/test/java/rocks/zipcode/io/quiz3/collections/student/SetLabStatusOfForkedLab.java
  12. 10
    6
      src/test/java/rocks/zipcode/io/quiz3/collections/student/SetLabStatusOfUnforkedLab.java
  13. 8
    5
      src/test/java/rocks/zipcode/io/quiz3/collections/student/ToStringTest.java
  14. 6
    0
      src/test/java/rocks/zipcode/io/quiz3/fundamentals/piglatin/TranslateSingleWordStartingWithConsonant.java
  15. 2
    2
      src/test/java/rocks/zipcode/io/quiz3/fundamentals/piglatin/TranslateSingleWordStartingWithVowel.java
  16. 86
    0
      src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/GetAllSubStrings.java
  17. 36
    0
      src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/GetNumberOfSubStrings.java
  18. 8
    1
      src/test/java/rocks/zipcode/io/quiz3/generics/arrayutility/integer/IntegerFilterTest.java
  19. 10
    5
      src/test/java/rocks/zipcode/io/quiz3/generics/arrayutility/string/StringFilterTest.java
  20. 6
    0
      src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/labstatus/TestEnumerations.java
  21. 1
    1
      src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/PaperTest.java
  22. 1
    1
      src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/RockTest.java
  23. 2
    1
      src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java
  24. 53
    0
      src/test/java/rocks/zipcode/io/quiz3/utils/TestUtils.java

+ 15
- 0
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java View File

@@ -8,6 +8,9 @@ public class TicTacToe {
8 8
     public TicTacToe(String[][] board) {
9 9
     }
10 10
 
11
+    public TicTacToe() {
12
+    }
13
+
11 14
     public String[] getRow(Integer value) {
12 15
         return null;
13 16
     }
@@ -25,6 +28,18 @@ public class TicTacToe {
25 28
     }
26 29
 
27 30
     public String getWinner() {
31
+        for (int i = 0; i < 3 ; i++) {
32
+            if(isRowHomogenous(i)) {
33
+                return getRow(i)[0];
34
+            }
35
+            if(isColumnHomogeneous(i)){
36
+                return getColumn(i)[0];
37
+            }
38
+        }
39
+        return null;
40
+    }
41
+
42
+    public String[][] getBoard() {
28 43
         return null;
29 44
     }
30 45
 }

+ 4
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java View File

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.collections;
2 2
 
3
+import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
4
+
3 5
 /**
4 6
  * @author leon on 10/12/2018.
5 7
  */
@@ -11,11 +13,11 @@ public class Lab {
11 13
     public Lab(String labName) {
12 14
     }
13 15
 
14
-    public String getLabStatus() {
16
+    public LabStatus getLabStatus() {
15 17
         return null;
16 18
     }
17 19
 
18
-    public void setLabStatus(String labStatus) {
20
+    public void setLabStatus(LabStatus labStatus) {
19 21
     }
20 22
 
21 23
     public String getName() {

+ 5
- 1
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java View File

@@ -15,7 +15,11 @@ public class Student {
15 15
     public Student(Map<Lab, LabStatus> map) {
16 16
     }
17 17
 
18
-    public void setLabStatus(Lab lab, LabStatus labStatus) {
18
+    public Lab getLab(String labName) {
19
+        return null;
20
+    }
21
+
22
+    public void setLabStatus(String labName, LabStatus labStatus) {
19 23
     }
20 24
 
21 25
 

+ 18
- 0
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java View File

@@ -1,5 +1,8 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
3 6
 /**
4 7
  * @author leon on 09/12/2018.
5 8
  */
@@ -11,4 +14,19 @@ public class StringUtils {
11 14
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12 15
         return null;
13 16
     }
17
+
18
+    public static String[] getAllSubStrings(String string) {
19
+        List<String> result = new ArrayList<>();
20
+        int length = string.length();
21
+        for (int c = 0; c < length; c++) {
22
+            for (int i = 1; i <= length - c; i++) {
23
+                result.add(string.substring(c, c + i));
24
+            }
25
+        }
26
+        return result.stream().distinct().toArray(String[]::new);
27
+    }
28
+
29
+    public static Integer getNumberOfSubStrings(String input) {
30
+        return getAllSubStrings(input).length;
31
+    }
14 32
 }

+ 0
- 16
src/test/java/rocks/zipcode/io/quiz3/TestUtils.java View File

@@ -1,16 +0,0 @@
1
-package rocks.zipcode.io.quiz3;
2
-
3
-import org.junit.Assert;
4
-
5
-import java.util.Arrays;
6
-
7
-/**
8
- * @author leon on 09/12/2018.
9
- */
10
-public class TestUtils {
11
-    public static <ObjectType> void assertArrayEquals(ObjectType[] array1, ObjectType[] array2) {
12
-        Arrays.sort(array1);
13
-        Arrays.sort(array2);
14
-        Assert.assertEquals(Arrays.toString(array1), Arrays.toString(array2));
15
-    }
16
-}

+ 0
- 22
src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/ConstructorTest.java View File

@@ -1,22 +0,0 @@
1
-package rocks.zipcode.io.quiz3.arrays.tictactoe;
2
-
3
-import org.junit.Test;
4
-import rocks.zipcode.io.quiz3.arrays.TicTacToe;
5
-
6
-/**
7
- * @author leon on 10/12/2018.
8
- */
9
-public class ConstructorTest {
10
-    //    @Test
11
-    public void nullaryConstructor() {
12
-    }
13
-
14
-    @Test
15
-    public void parametrizedConstructor() {
16
-        String[] row1 = {"X", "O", "X"};
17
-        String[] row2 = {"O", "X", "O"};
18
-        String[] row3 = {"O", "X", "O"};
19
-        String[][] board = {row1, row2, row3};
20
-        TicTacToe ticTacToe = new TicTacToe(board);
21
-    }
22
-}

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/GetColumnTest.java View File

@@ -1,7 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.arrays.tictactoe;
2 2
 
3 3
 import org.junit.Test;
4
-import rocks.zipcode.io.quiz3.TestUtils;
4
+import rocks.zipcode.io.quiz3.utils.TestUtils;
5 5
 import rocks.zipcode.io.quiz3.arrays.TicTacToe;
6 6
 
7 7
 /**

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/GetRowTest.java View File

@@ -1,7 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.arrays.tictactoe;
2 2
 
3 3
 import org.junit.Test;
4
-import rocks.zipcode.io.quiz3.TestUtils;
4
+import rocks.zipcode.io.quiz3.utils.TestUtils;
5 5
 import rocks.zipcode.io.quiz3.arrays.TicTacToe;
6 6
 
7 7
 /**

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/arrays/wavegenerator/WaveTest.java View File

@@ -1,7 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.arrays.wavegenerator;
2 2
 
3 3
 import org.junit.Test;
4
-import rocks.zipcode.io.quiz3.TestUtils;
4
+import rocks.zipcode.io.quiz3.utils.TestUtils;
5 5
 import rocks.zipcode.io.quiz3.arrays.WaveGenerator;
6 6
 
7 7
 /**

+ 41
- 0
src/test/java/rocks/zipcode/io/quiz3/collections/student/GetLabTest.java View File

@@ -0,0 +1,41 @@
1
+package rocks.zipcode.io.quiz3.collections.student;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz3.collections.Lab;
6
+import rocks.zipcode.io.quiz3.collections.Student;
7
+
8
+/**
9
+ * @author leon on 10/12/2018.
10
+ */
11
+public class GetLabTest {
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        String labName = "duplicate deleter";
16
+        Lab expected = new Lab(labName);
17
+        Student student = new Student();
18
+        student.forkLab(expected);
19
+
20
+        // when
21
+        Lab actual = student.getLab(labName);
22
+
23
+        // then
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void test2() {
29
+        // given
30
+        String labName = "learner lab";
31
+        Lab expected = new Lab(labName);
32
+        Student student = new Student();
33
+        student.forkLab(expected);
34
+
35
+        // when
36
+        Lab actual = student.getLab(labName);
37
+
38
+        // then
39
+        Assert.assertEquals(expected, actual);
40
+    }
41
+}

+ 12
- 9
src/test/java/rocks/zipcode/io/quiz3/collections/student/SetLabStatusOfForkedLab.java View File

@@ -13,14 +13,15 @@ public class SetLabStatusOfForkedLab {
13 13
     @Test
14 14
     public void testCompleted() {
15 15
         // given
16
-        Lab lab = new Lab("duplicate deleter");
16
+        String labName = "duplicate deleter";
17
+        Lab lab = new Lab(labName);
17 18
         Student student = new Student();
18 19
         LabStatus expected = LabStatus.valueOf("COMPLETED");
19 20
 
20 21
         // when
21 22
         student.forkLab(lab);
22
-        student.setLabStatus(lab, expected);
23
-        LabStatus actual = student.getLabStatus(lab.getName());
23
+        student.setLabStatus(labName, expected);
24
+        LabStatus actual = student.getLabStatus(labName);
24 25
 
25 26
         // then
26 27
         Assert.assertEquals(expected, actual);
@@ -29,14 +30,15 @@ public class SetLabStatusOfForkedLab {
29 30
     @Test
30 31
     public void testPending() {
31 32
         // given
32
-        Lab lab = new Lab("duplicate deleter");
33
+        String labName = "duplicate deleter";
34
+        Lab lab = new Lab(labName);
33 35
         Student student = new Student();
34 36
         LabStatus expected = LabStatus.valueOf("PENDING");
35 37
 
36 38
         // when
37 39
         student.forkLab(lab);
38
-        student.setLabStatus(lab, expected);
39
-        LabStatus actual = student.getLabStatus(lab.getName());
40
+        student.setLabStatus(labName, expected);
41
+        LabStatus actual = student.getLabStatus(labName);
40 42
 
41 43
         // then
42 44
         Assert.assertEquals(expected, actual);
@@ -45,14 +47,15 @@ public class SetLabStatusOfForkedLab {
45 47
     @Test
46 48
     public void testIncomplete() {
47 49
         // given
48
-        Lab lab = new Lab("duplicate deleter");
50
+        String labName = "duplicate deleter";
51
+        Lab lab = new Lab(labName);
49 52
         Student student = new Student();
50 53
         LabStatus expected = LabStatus.valueOf("INCOMPLETE");
51 54
 
52 55
         // when
53 56
         student.forkLab(lab);
54
-        student.setLabStatus(lab, expected);
55
-        LabStatus actual = student.getLabStatus(lab.getName());
57
+        student.setLabStatus(labName, expected);
58
+        LabStatus actual = student.getLabStatus(labName);
56 59
 
57 60
         // then
58 61
         Assert.assertEquals(expected, actual);

+ 10
- 6
src/test/java/rocks/zipcode/io/quiz3/collections/student/SetLabStatusOfUnforkedLab.java View File

@@ -12,33 +12,37 @@ public class SetLabStatusOfUnforkedLab {
12 12
     @Test(expected = UnsupportedOperationException.class)
13 13
     public void testCompleted() {
14 14
         // given
15
-        Lab lab = new Lab("duplicate deleter");
15
+        String labName = "duplicate deleter";
16
+        Lab lab = new Lab(labName);
16 17
         Student student = new Student();
17 18
         LabStatus expected = LabStatus.valueOf("COMPLETED");
18 19
 
19 20
         // when : setting the lab status of an unforked-lab results in UnsupportedOperationException
20
-        student.setLabStatus(lab, expected);
21
+        student.setLabStatus(labName, expected);
21 22
     }
22 23
 
23 24
     @Test(expected = UnsupportedOperationException.class)
24 25
     public void testPending() {
25 26
         // given
26
-        Lab lab = new Lab("duplicate deleter");
27
+        String labName = "duplicate deleter";
28
+        Lab lab = new Lab(labName);
27 29
         Student student = new Student();
28 30
         LabStatus expected = LabStatus.valueOf("PENDING");
29 31
 
30 32
         // when : setting the lab status of an unforked-lab results in UnsupportedOperationException
31
-        student.setLabStatus(lab, expected);
33
+        student.setLabStatus(labName, expected);
32 34
     }
33 35
 
34 36
     @Test(expected = UnsupportedOperationException.class)
35 37
     public void testIncomplete() {
36 38
         // given
37
-        Lab lab = new Lab("duplicate deleter");
39
+        String labName = "duplicate deleter";
40
+        Lab lab = new Lab(labName);
41
+
38 42
         Student student = new Student();
39 43
         LabStatus expected = LabStatus.valueOf("INCOMPLETE");
40 44
 
41 45
         // when : setting the lab status of an unforked-lab results in UnsupportedOperationException
42
-        student.setLabStatus(lab, expected);
46
+        student.setLabStatus(labName, expected);
43 47
     }
44 48
 }

+ 8
- 5
src/test/java/rocks/zipcode/io/quiz3/collections/student/ToStringTest.java View File

@@ -13,6 +13,7 @@ public class ToStringTest {
13 13
     @Test
14 14
     public void test1() {
15 15
         // given
16
+        String labName = "duplicate deleter";
16 17
         Lab duplicateDeleter = new Lab("duplicate deleter");
17 18
         Lab learnerLab = new Lab("learner lab");
18 19
         Student student = new Student();
@@ -22,7 +23,7 @@ public class ToStringTest {
22 23
         // when
23 24
         student.forkLab(learnerLab);
24 25
         student.forkLab(duplicateDeleter);
25
-        student.setLabStatus(duplicateDeleter, completed);
26
+        student.setLabStatus(labName, completed);
26 27
         String actual = student.toString();
27 28
 
28 29
         Assert.assertEquals(expected, actual);
@@ -31,8 +32,10 @@ public class ToStringTest {
31 32
     @Test
32 33
     public void test2() {
33 34
         // given
34
-        Lab casino = new Lab("casino");
35
-        Lab learnerLab = new Lab("learner lab");
35
+        String casinoLabName = "casino";
36
+        String learnerLabName = "learner lab";
37
+        Lab casino = new Lab(casinoLabName);
38
+        Lab learnerLab = new Lab(learnerLabName);
36 39
         Student student = new Student();
37 40
         LabStatus completed = LabStatus.valueOf("COMPLETED");
38 41
         LabStatus incomplete = LabStatus.valueOf("INCOMPLETE");
@@ -41,8 +44,8 @@ public class ToStringTest {
41 44
         // when
42 45
         student.forkLab(learnerLab);
43 46
         student.forkLab(casino);
44
-        student.setLabStatus(casino, completed);
45
-        student.setLabStatus(learnerLab, incomplete);
47
+        student.setLabStatus(casinoLabName, completed);
48
+        student.setLabStatus(learnerLabName, incomplete);
46 49
         String actual = student.toString();
47 50
 
48 51
         Assert.assertEquals(expected, actual);

+ 6
- 0
src/test/java/rocks/zipcode/io/quiz3/fundamentals/piglatin/TranslateSingleWordStartingWithConsonant.java View File

@@ -52,4 +52,10 @@ public class TranslateSingleWordStartingWithConsonant {
52 52
     public void testRuby() {
53 53
         Assert.assertEquals("ubyRay", p.translate("Ruby"));
54 54
     }
55
+
56
+
57
+    @Test
58
+    public void testCCC() {
59
+        Assert.assertEquals("CCCCay", p.translate("CCCC"));
60
+    }
55 61
 }

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/piglatin/TranslateSingleWordStartingWithVowel.java View File

@@ -22,7 +22,7 @@ public class TranslateSingleWordStartingWithVowel {
22 22
     }
23 23
 
24 24
     @Test
25
-    public void testCCC() {
26
-        Assert.assertEquals("CCCCay", p.translate("CCCC"));
25
+    public void testapple() {
26
+        Assert.assertEquals("appleway", p.translate("apple"));
27 27
     }
28 28
 }

+ 86
- 0
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/GetAllSubStrings.java View File

@@ -0,0 +1,86 @@
1
+package rocks.zipcode.io.quiz3.fundamentals.stringutils;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz3.utils.TestUtils;
5
+import rocks.zipcode.io.quiz3.fundamentals.StringUtils;
6
+
7
+import java.util.Arrays;
8
+
9
+/**
10
+ * @author leon on 10/12/2018.
11
+ */
12
+public class GetAllSubStrings {
13
+    @Test
14
+    public void test1() {
15
+        // given
16
+        String input = "Hello";
17
+        String[] expected = {
18
+                "H",
19
+                "He",
20
+                "Hel",
21
+                "Hell",
22
+                "Hello",
23
+                "e",
24
+                "el",
25
+                "ell",
26
+                "ello",
27
+                "l",
28
+                "ll",
29
+                "llo",
30
+                "lo",
31
+                "o"};
32
+
33
+        // when
34
+        String[] actual = StringUtils.getAllSubStrings(input);
35
+
36
+        // then
37
+        TestUtils.assertArrayEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void test5() {
42
+        // given
43
+        String input = "Janitor";
44
+        String[] expected = {
45
+                "J",
46
+                "Ja",
47
+                "Jan",
48
+                "Jani",
49
+                "Janit",
50
+                "Janito",
51
+                "Janitor",
52
+                "a",
53
+                "an",
54
+                "ani",
55
+                "anit",
56
+                "anito",
57
+                "anitor",
58
+                "i",
59
+                "it",
60
+                "ito",
61
+                "itor",
62
+                "n",
63
+                "ni",
64
+                "nit",
65
+                "nito",
66
+                "nitor",
67
+                "o",
68
+                "or",
69
+                "r",
70
+                "t",
71
+                "to",
72
+                "tor"};
73
+
74
+        // when
75
+        String[] actual = StringUtils.getAllSubStrings(input);
76
+        Arrays.sort(actual);
77
+        System.out.println("String[] expected = {");
78
+        for (String s : actual) {
79
+            System.out.println("\"" + s + "\",");
80
+        }
81
+
82
+        // then
83
+        TestUtils.assertArrayEquals(expected, actual);
84
+    }
85
+
86
+}

+ 36
- 0
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/GetNumberOfSubStrings.java View File

@@ -0,0 +1,36 @@
1
+package rocks.zipcode.io.quiz3.fundamentals.stringutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz3.fundamentals.StringUtils;
6
+
7
+/**
8
+ * @author leon on 10/12/2018.
9
+ */
10
+public class GetNumberOfSubStrings {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        String input = "Hello";
15
+        Integer expected = 14;
16
+
17
+        // when
18
+        Integer actual = StringUtils.getNumberOfSubStrings(input);
19
+
20
+        // then
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        String input = "The Quick Brown";
28
+        Integer expected = 119;
29
+
30
+        // when
31
+        Integer actual = StringUtils.getNumberOfSubStrings(input);
32
+
33
+        // then
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+}

+ 8
- 1
src/test/java/rocks/zipcode/io/quiz3/generics/arrayutility/integer/IntegerFilterTest.java View File

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.generics.arrayutility.integer;
2 2
 
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz3.utils.TestUtils;
3 5
 import rocks.zipcode.io.quiz3.generics.ArrayUtility;
4 6
 
5 7
 import java.util.function.Function;
@@ -9,6 +11,7 @@ import java.util.function.Function;
9 11
  */
10 12
 public class IntegerFilterTest {
11 13
 
14
+    @Test
12 15
     public void test1() {
13 16
         // given
14 17
         Integer[] array = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -24,6 +27,7 @@ public class IntegerFilterTest {
24 27
     }
25 28
 
26 29
 
30
+    @Test
27 31
     public void test2() {
28 32
         // given
29 33
         Integer[] array = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -39,6 +43,7 @@ public class IntegerFilterTest {
39 43
     }
40 44
 
41 45
 
46
+    @Test
42 47
     public void test3() {
43 48
         // given
44 49
         Integer[] array = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -54,6 +59,7 @@ public class IntegerFilterTest {
54 59
     }
55 60
 
56 61
 
62
+    @Test
57 63
     public void test4() {
58 64
         // given
59 65
         Integer[] array = new Integer[]{10, 15, 20, 25, 55, 100, 150, 300, 900, 1000};
@@ -69,6 +75,7 @@ public class IntegerFilterTest {
69 75
     }
70 76
 
71 77
 
78
+    @Test
72 79
     public void test5() {
73 80
         // given
74 81
         Integer[] array = new Integer[]{10, 15, 20, 25, 55, 100, 150, 300, 900, 1000};
@@ -84,6 +91,6 @@ public class IntegerFilterTest {
84 91
     }
85 92
 
86 93
     private void compare(Integer[] expected, Integer[] actual) {
87
-//        TestUtils.assertArrayEquals(expected, actual);
94
+        TestUtils.assertArrayEquals(expected, actual);
88 95
     }
89 96
 }

+ 10
- 5
src/test/java/rocks/zipcode/io/quiz3/generics/arrayutility/string/StringFilterTest.java View File

@@ -1,20 +1,23 @@
1 1
 package rocks.zipcode.io.quiz3.generics.arrayutility.string;
2 2
 
3 3
 import org.junit.Test;
4
-import rocks.zipcode.io.quiz3.TestUtils;
4
+import rocks.zipcode.io.quiz3.utils.TestUtils;
5 5
 import rocks.zipcode.io.quiz3.generics.ArrayUtility;
6 6
 
7 7
 /**
8 8
  * @author leon on 09/12/2018.
9 9
  */
10 10
 public class StringFilterTest {
11
-    
11
+
12
+    @Test
12 13
     public void test1() {
13 14
         // given
14 15
         String[] expected = {"quick", "brown", "jumps", "over", "lazy"};
15 16
         String[] input = "The quick brown fox jumps over the lazy dog".split(" ");
16 17
         ArrayUtility<String> utility = new ArrayUtility<>(input);
17 18
 
19
+
20
+
18 21
         // when
19 22
         String[] actual = utility.filter(string -> string.length() > 3);
20 23
 
@@ -22,7 +25,8 @@ public class StringFilterTest {
22 25
         TestUtils.assertArrayEquals(expected, actual);
23 26
     }
24 27
 
25
-    
28
+
29
+    @Test
26 30
     public void test2() {
27 31
         // given
28 32
         String[] expected = {"The", "fox", "the", "dog"};
@@ -30,13 +34,14 @@ public class StringFilterTest {
30 34
         ArrayUtility<String> utility = new ArrayUtility<>(input);
31 35
 
32 36
         // when
33
-        String[] actual = utility.filter(string -> string.length() < 3);
37
+        String[] actual = utility.filter(string -> string.length() <= 3);
34 38
 
35 39
         // then
36 40
         TestUtils.assertArrayEquals(expected, actual);
37 41
     }
38 42
 
39
-    
43
+
44
+    @Test
40 45
     public void test3() {
41 46
         // given
42 47
         String[] expected = {"The", "over", "the"};

+ 6
- 0
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/labstatus/TestEnumerations.java View File

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.io.quiz3.objectorientation.enums.labstatus;
2 2
 
3
+import org.junit.Assert;
3 4
 import org.junit.Test;
4 5
 import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
5 6
 
@@ -21,4 +22,9 @@ public class TestEnumerations {
21 22
     public void test3() {
22 23
         LabStatus.valueOf("PENDING");
23 24
     }
25
+
26
+    @Test
27
+    public void test4() {
28
+        Assert.assertEquals(3, LabStatus.values().length);
29
+    }
24 30
 }

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/PaperTest.java View File

@@ -25,7 +25,7 @@ public class PaperTest {
25 25
 
26 26
     @Test
27 27
     public void testGetWinner() {
28
-        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSORS");
28
+        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSOR");
29 29
         Assert.assertEquals(loser, sign.getWinner());
30 30
     }
31 31
 }

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/RockTest.java View File

@@ -20,7 +20,7 @@ public class RockTest {
20 20
 
21 21
     @Test
22 22
     public void testGetLoser() {
23
-        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSORS");
23
+        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSOR");
24 24
         Assert.assertEquals(loser, sign.getLoser());
25 25
     }
26 26
 

+ 2
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java View File

@@ -1,6 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.objectorientation.enums.rockpaperscissors;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
6 7
 
@@ -10,7 +11,7 @@ import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
10 11
 public class ScissorTest {
11 12
     private RockPaperScissorHandSign sign;
12 13
 
13
-    @Test
14
+    @Before
14 15
     public void setup() {
15 16
         // given
16 17
         this.sign = RockPaperScissorHandSign.valueOf("SCISSOR");

+ 53
- 0
src/test/java/rocks/zipcode/io/quiz3/utils/TestUtils.java View File

@@ -0,0 +1,53 @@
1
+package rocks.zipcode.io.quiz3.utils;
2
+
3
+import org.junit.Assert;
4
+
5
+import java.util.Arrays;
6
+import java.util.concurrent.TimeoutException;
7
+import java.util.function.BiFunction;
8
+import java.util.function.Function;
9
+
10
+/**
11
+ * @author leon on 09/12/2018.
12
+ */
13
+public class TestUtils {
14
+    public static <ObjectType> void assertArrayEquals(ObjectType[] array1, ObjectType[] array2) {
15
+        Arrays.sort(array1);
16
+        Arrays.sort(array2);
17
+        Assert.assertEquals(Arrays.toString(array1), Arrays.toString(array2));
18
+    }
19
+
20
+
21
+    public static <ArgType1, ReturnType> void constrainMethodPerformance(
22
+            Function<ArgType1, ReturnType> function,
23
+            ArgType1 arg1,
24
+            Long maxTimeInMilliseconds) {
25
+        constrainMethodPerformance((val1, val2) -> function.apply(val1), arg1, null, maxTimeInMilliseconds);
26
+    }
27
+
28
+    public static <ArgType1, ArgType2, ReturnType> void constrainMethodPerformance(
29
+            BiFunction<ArgType1, ArgType2, ReturnType> function,
30
+            ArgType1 arg1, ArgType2 arg2, Long maxTimeInMilliseconds) {
31
+        if (timeMethod(function, arg1, arg2) > maxTimeInMilliseconds) {
32
+            Throwable timeoutException = new TimeoutException("Method must perform in under " + maxTimeInMilliseconds + "millseconds");
33
+            ;
34
+            throw new Error(timeoutException);
35
+        }
36
+    }
37
+
38
+
39
+    public static <ArgType1, ReturnType> Long timeMethod(Function<ArgType1, ReturnType> function, ArgType1 arg1) {
40
+        return timeMethod((val1, val2) -> function.apply(val1), arg1, null);
41
+    }
42
+
43
+    public static <ArgType1, ArgType2, ReturnType> Long timeMethod(
44
+            BiFunction<ArgType1, ArgType2, ReturnType> function,
45
+            ArgType1 arg1, ArgType2 arg2) {
46
+        Long startTime = System.currentTimeMillis();
47
+        function.apply(arg1, arg2);
48
+        Long endTime = System.currentTimeMillis();
49
+        Long delta = endTime - startTime;
50
+        return delta;
51
+    }
52
+
53
+}