Просмотр исходного кода

created an additional oop class & tests

Leon 6 лет назад
Родитель
Сommit
7048c18285

+ 21
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java Просмотреть файл

@@ -0,0 +1,21 @@
1
+package rocks.zipcode.io.quiz4.objectorientation;
2
+
3
+/**
4
+ * @author leon on 19/12/2018.
5
+ */
6
+public class StringEvaluatorObject {
7
+    public StringEvaluatorObject(String str) {
8
+    }
9
+
10
+    public String[] getAllPrefixes() {
11
+        return null;
12
+    }
13
+
14
+    public String[] getCommonPrefixes(String secondInput) {
15
+        return null;
16
+    }
17
+
18
+    public String getLargestCommonPrefix(String secondInput) {
19
+        return null;
20
+    }
21
+}

+ 84
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringevaluatorobject/GetAllPrefixes.java Просмотреть файл

@@ -0,0 +1,84 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.stringevaluatorobject;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
5
+import rocks.zipcode.io.quiz4.objectorientation.StringEvaluatorObject;
6
+import rocks.zipcode.io.quiz4.utils.TestUtils;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class GetAllPrefixes {
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        String input = "A";
16
+        String[] expected = {input};
17
+        test(input, expected);
18
+    }
19
+
20
+    @Test
21
+    public void test2() {
22
+        // given
23
+        String input = "B";
24
+        String[] expected = {input};
25
+        test(input, expected);
26
+    }
27
+
28
+
29
+    @Test
30
+    public void test3() {
31
+        // given
32
+        String input = "AB";
33
+        String[] expected = {"A", "B", "AB"};
34
+        test(input, expected);
35
+    }
36
+
37
+
38
+    @Test
39
+    public void test4() {
40
+        // given
41
+        String input = "ABB";
42
+        String[] expected = {"A", "AB", "ABB", "B", "BB"};
43
+        test(input, expected);
44
+    }
45
+
46
+
47
+    @Test
48
+    public void test5() {
49
+        // given
50
+        String input = "AABB";
51
+        String[] expected = {"A", "AA", "AAB", "AABB", "AB", "ABB", "B", "BB"};
52
+        test(input, expected);
53
+    }
54
+
55
+
56
+    @Test
57
+    public void test6() {
58
+        // given
59
+        String input = "AnotherMethodToTest";
60
+        String[] expected = {
61
+                "A", "An", "Ano", "Anot", "Anoth", "Anothe", "Another", "AnotherM", "AnotherMe", "AnotherMet", "AnotherMeth", "AnotherMetho", "AnotherMethod", "AnotherMethodT", "AnotherMethodTo", "AnotherMethodToT", "AnotherMethodToTe", "AnotherMethodToTes", "AnotherMethodToTest",
62
+                "n", "no", "not", "noth", "nothe", "nother", "notherM", "notherMe", "notherMet", "notherMeth", "notherMetho", "notherMethod", "notherMethodT", "notherMethodTo", "notherMethodToT", "notherMethodToTe", "notherMethodToTes", "notherMethodToTest",
63
+                "o", "oT", "oTe", "oTes", "oTest", "od", "odT", "odTo", "odToT", "odToTe", "odToTes", "odToTest", "ot", "oth", "othe", "other", "otherM", "otherMe", "otherMet", "otherMeth", "otherMetho", "otherMethod", "otherMethodT", "otherMethodTo", "otherMethodToT", "otherMethodToTe", "otherMethodToTes", "otherMethodToTest",
64
+                "t", "th", "the", "ther", "therM", "therMe", "therMet", "therMeth", "therMetho", "therMethod", "therMethodT", "therMethodTo", "therMethodToT", "therMethodToTe", "therMethodToTes", "therMethodToTest", "tho", "thod", "thodT", "thodTo", "thodToT", "thodToTe", "thodToTes", "thodToTest",
65
+                "h", "he", "her", "herM", "herMe", "herMet", "herMeth", "herMetho", "herMethod", "herMethodT", "herMethodTo", "herMethodToT", "herMethodToTe", "herMethodToTes", "herMethodToTest", "ho", "hod", "hodT", "hodTo", "hodToT", "hodToTe", "hodToTes", "hodToTest",
66
+                "e", "er", "erM", "erMe", "erMet", "erMeth", "erMetho", "erMethod", "erMethodT", "erMethodTo", "erMethodToT", "erMethodToTe", "erMethodToTes", "erMethodToTest", "es", "est", "et", "eth", "etho", "ethod", "ethodT", "ethodTo", "ethodToT", "ethodToTe", "ethodToTes", "ethodToTest",
67
+                "r", "rM", "rMe", "rMet", "rMeth", "rMetho", "rMethod", "rMethodT", "rMethodTo", "rMethodToT", "rMethodToTe", "rMethodToTes", "rMethodToTest",
68
+                "M", "Me", "Met", "Meth", "Metho", "Method", "MethodT", "MethodTo", "MethodToT", "MethodToTe", "MethodToTes", "MethodToTest",
69
+                "T", "Te", "Tes", "Test", "To", "ToT", "ToTe", "ToTes", "ToTest",
70
+                "d", "dT", "dTo", "dToT", "dToTe", "dToTes", "dToTest",
71
+                "s", "st"};
72
+
73
+        test(input, expected);
74
+    }
75
+
76
+    private void test(String input, String[] expected) {
77
+        // when
78
+        String[] actual = new StringEvaluatorObject(input).getAllPrefixes();
79
+
80
+        // then
81
+        TestUtils.assertArrayEquals(expected, actual);
82
+
83
+    }
84
+}

+ 67
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringevaluatorobject/GetCommonPrefixesTest.java Просмотреть файл

@@ -0,0 +1,67 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.stringevaluatorobject;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
5
+import rocks.zipcode.io.quiz4.objectorientation.StringEvaluatorObject;
6
+import rocks.zipcode.io.quiz4.utils.TestUtils;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class GetCommonPrefixesTest {
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        String firstInput = "AAB";
16
+        String secondInput = "AAAB";
17
+        String[] expected = {"A", "AA", "AAB", "AB", "B"};
18
+        test(firstInput, secondInput, expected);
19
+    }
20
+
21
+    @Test
22
+    public void test2() {
23
+        // given
24
+        String firstInput = "AAZB";
25
+        String secondInput = "AAAB";
26
+        String[] expected = {"A", "AA", "B"};
27
+        test(firstInput, secondInput, expected);
28
+    }
29
+
30
+
31
+    @Test
32
+    public void test3() {
33
+        // given
34
+        String firstInput = "Zapple";
35
+        String secondInput = "Candy apples!";
36
+        String[] expected = {"a", "ap", "app", "appl", "apple", "e", "l", "le", "p", "pl", "ple", "pp", "ppl", "pple"};
37
+        test(firstInput, secondInput, expected);
38
+    }
39
+
40
+
41
+    @Test
42
+    public void tes4() {
43
+        // given
44
+        String firstInput = "Irreducible complexity";
45
+        String secondInput = "Deductive operations";
46
+        String[] expected = {" ", "c", "d", "du", "duc", "e", "e ", "ed", "edu", "educ", "i", "o", "p", "r", "t", "u", "uc"};
47
+        test(firstInput, secondInput, expected);
48
+    }
49
+
50
+    @Test
51
+    public void test5() {
52
+        // given
53
+        String firstInput = "Peter piper picked a pepper";
54
+        String secondInput = "Jimmy neutron was a fancy scientist";
55
+        String[] expected = {" ", " a", " a ", "a", "a ", "c", "e", "i", "r", "t"};
56
+        test(firstInput, secondInput, expected);
57
+    }
58
+
59
+    private void test(String firstInput, String secondInput, String[] expected) {
60
+        // when
61
+        String[] actual = new StringEvaluatorObject(firstInput).getCommonPrefixes(secondInput);
62
+
63
+        // then
64
+        TestUtils.assertArrayEquals(expected, actual);
65
+    }
66
+
67
+}

+ 61
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringevaluatorobject/GetLargestCommonPrefixTest.java Просмотреть файл

@@ -0,0 +1,61 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.stringevaluatorobject;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
6
+import rocks.zipcode.io.quiz4.objectorientation.StringEvaluatorObject;
7
+import rocks.zipcode.io.quiz4.utils.TestUtils;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class GetLargestCommonPrefixTest {
13
+    @Test
14
+    public void test1() {
15
+        // given
16
+        String firstInput = "AAB";
17
+        String secondInput = "AAAB";
18
+        String expected = "AAB";
19
+        test(firstInput, secondInput, expected);
20
+    }
21
+
22
+    @Test
23
+    public void test2() {
24
+        // given
25
+        String firstInput = "AAZB";
26
+        String secondInput = "AAAB";
27
+        String expected = "AA";
28
+        test(firstInput, secondInput, expected);
29
+    }
30
+
31
+
32
+
33
+    @Test
34
+    public void test3() {
35
+        // given
36
+        String firstInput = "Zapple";
37
+        String secondInput = "Candy apples!";
38
+        String expected = "apple";
39
+        test(firstInput, secondInput, expected);
40
+    }
41
+
42
+
43
+
44
+    @Test
45
+    public void test4() {
46
+        // given
47
+        String firstInput = "Irreducible complexity";
48
+        String secondInput = "Deductive operations";
49
+        String expected = "educ";
50
+        test(firstInput, secondInput, expected);
51
+    }
52
+
53
+
54
+    private void test(String firstInput, String secondInput, String expected) {
55
+        // when
56
+        String actual = new StringEvaluatorObject(firstInput).getLargestCommonPrefix(secondInput);
57
+
58
+        // then
59
+        Assert.assertEquals(expected, actual);
60
+    }
61
+}