Преглед изворни кода

Merge branch 'master' of https://git.zipcode.rocks/Cohort4.2/Quiz5

Leon пре 5 година
родитељ
комит
6dd4865b3e

+ 7
- 0
src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java Прегледај датотеку

@@ -4,4 +4,11 @@ package rocks.zipcode.quiz3a.arrays;
4 4
  * @author leon on 01/01/2019.
5 5
  */
6 6
 public class ArrayUtils {
7
+    public static String getMiddleElement(String[] values) {
8
+        return null;
9
+    }
10
+
11
+    public static String[] removeMiddleElement(String[] values) {
12
+        return null;
13
+    }
7 14
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/collections/WordCounter.java Прегледај датотеку

@@ -6,7 +6,7 @@ public class WordCounter {
6 6
     public WordCounter(String... strings) {
7 7
     }
8 8
 
9
-    public static Map<String, Integer> getWordCountMap() {
9
+    public Map<String, Integer> getWordCountMap() {
10 10
         return null;
11 11
     }
12 12
 }

+ 47
- 0
src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/GetMiddleElementTest.java Прегледај датотеку

@@ -0,0 +1,47 @@
1
+package rocks.zipcode.quiz3a.arrays.arrayutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.arrays.ArrayUtils;
6
+
7
+public class GetMiddleElementTest {
8
+    @Test
9
+    public void test1() {
10
+        // given
11
+        String expected = "Quick";
12
+        String[] strings = {"The", expected, "Brown"};
13
+
14
+        // when
15
+        String actual = ArrayUtils.getMiddleElement(strings);
16
+
17
+        //then
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void test2() {
23
+        // given
24
+        String expected = "Brown";
25
+        String[] strings = {"The", "Quick", expected, "Fox", "Jumps"};
26
+
27
+        // when
28
+        String actual = ArrayUtils.getMiddleElement(strings);
29
+
30
+        //then
31
+        Assert.assertEquals(expected, actual);
32
+    }
33
+
34
+
35
+    @Test
36
+    public void test3() {
37
+        // given
38
+        String expected = "Fox";
39
+        String[] strings = {"The", "Quick", "Brown", expected, "Jumps", "Over", "The"};
40
+
41
+        // when
42
+        String actual = ArrayUtils.getMiddleElement(strings);
43
+
44
+        //then
45
+        Assert.assertEquals(expected, actual);
46
+    }
47
+}

+ 47
- 0
src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/RemoveMiddleCharacterTest.java Прегледај датотеку

@@ -0,0 +1,47 @@
1
+package rocks.zipcode.quiz3a.arrays.arrayutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.arrays.ArrayUtils;
6
+
7
+public class RemoveMiddleCharacterTest {
8
+    @Test
9
+    public void test1() {
10
+        // given
11
+        String[] strings = {"The", "Quick", "Brown"};
12
+        String[] expected = {"The", "Brown"};
13
+
14
+        // when
15
+        String[] actual = ArrayUtils.removeMiddleElement(strings);
16
+
17
+        //then
18
+        Assert.assertArrayEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void test2() {
23
+        // given
24
+        String[] expected = {"The", "Quick", "Fox", "Jumps"};
25
+        String[] strings = {"The", "Quick", "Brown", "Fox", "Jumps"};
26
+
27
+        // when
28
+        String[] actual = ArrayUtils.removeMiddleElement(strings);
29
+
30
+        //then
31
+        Assert.assertArrayEquals(expected, actual);
32
+    }
33
+
34
+
35
+    @Test
36
+    public void test3() {
37
+        // given
38
+        String[] strings = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The"};
39
+        String[] expected = {"The", "Quick", "Brown", "Jumps", "Over", "The"};
40
+
41
+        // when
42
+        String[] actual = ArrayUtils.removeMiddleElement(strings);
43
+
44
+        //then
45
+        Assert.assertArrayEquals(expected, actual);
46
+    }
47
+}

+ 68
- 0
src/test/java/rocks/zipcode/quiz3a/collections/wordcounter/GetWordCountMapTest.java Прегледај датотеку

@@ -1,4 +1,72 @@
1 1
 package rocks.zipcode.quiz3a.collections.wordcounter;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.collections.WordCounter;
6
+
7
+import java.util.Map;
8
+
3 9
 public class GetWordCountMapTest {
10
+    @Test
11
+    public void test1() {
12
+        // given
13
+        WordCounter wordCounter = new WordCounter("Hey");
14
+        Integer expected = 1;
15
+
16
+        // when
17
+        Map<String, Integer> map = wordCounter.getWordCountMap();
18
+        Integer actual = map.get("Hey");
19
+
20
+        // then
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        WordCounter wordCounter = new WordCounter("Hey", "Hey");
28
+        Integer expected = 2;
29
+
30
+        // when
31
+        Map<String, Integer> map = wordCounter.getWordCountMap();
32
+        Integer actual = map.get("Hey");
33
+
34
+        // then
35
+        Assert.assertEquals(expected, actual);
36
+    }
37
+
38
+    @Test
39
+    public void test3() {
40
+        // given
41
+        WordCounter wordCounter = new WordCounter("Hey", "Hey", "Hello");
42
+        Integer expectedHey = 2;
43
+        Integer expectedHello = 1;
44
+
45
+        // when
46
+        Map<String, Integer> map = wordCounter.getWordCountMap();
47
+        Integer actualHey = map.get("Hey");
48
+        Integer actualHello = map.get("Hello");
49
+
50
+        // then
51
+        Assert.assertEquals(expectedHey, actualHey);
52
+        Assert.assertEquals(expectedHello, actualHello);
53
+    }
54
+
55
+
56
+    @Test
57
+    public void test4() {
58
+        // given
59
+        WordCounter wordCounter = new WordCounter("Hey", "Hey", "Hello", "Hello", "Hello");
60
+        Integer expectedHey = 2;
61
+        Integer expectedHello = 3;
62
+
63
+        // when
64
+        Map<String, Integer> map = wordCounter.getWordCountMap();
65
+        Integer actualHey = map.get("Hey");
66
+        Integer actualHello = map.get("Hello");
67
+
68
+        // then
69
+        Assert.assertEquals(expectedHey, actualHey);
70
+        Assert.assertEquals(expectedHello, actualHello);
71
+    }
4 72
 }

+ 2
- 2
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/LowerCaseMiddleCharacterTest.java Прегледај датотеку

@@ -12,7 +12,7 @@ public class LowerCaseMiddleCharacterTest {
12 12
         String expected = "o";
13 13
 
14 14
         // when
15
-        String actual = StringUtils.capitalizeMiddleCharacter(input);
15
+        String actual = StringUtils.lowerCaseMiddleCharacter(input);
16 16
 
17 17
         // then
18 18
         Assert.assertEquals(expected, actual);
@@ -25,7 +25,7 @@ public class LowerCaseMiddleCharacterTest {
25 25
         String expected = "OoO";
26 26
 
27 27
         // when
28
-        String actual = StringUtils.capitalizeMiddleCharacter(input);
28
+        String actual = StringUtils.lowerCaseMiddleCharacter(input);
29 29
 
30 30
         // then
31 31
         Assert.assertEquals(expected, actual);

+ 3
- 3
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositTest.java Прегледај датотеку

@@ -28,14 +28,14 @@ public class DepositTest {
28 28
         test(10.0, 50.0);
29 29
     }
30 30
 
31
-    public void test(Double initialBalance, Double withdrawalAmount) {
31
+    public void test(Double initialBalance, Double witdrawalAmount) {
32 32
         // given
33
-        Double expected = initialBalance + withdrawalAmount;
33
+        Double expected = initialBalance + witdrawalAmount;
34 34
         BankAccount bankAccount = new BankAccount();
35 35
         bankAccount.setBalance(initialBalance);
36 36
 
37 37
         // when
38
-        bankAccount.withdrawal(withdrawalAmount);
38
+        bankAccount.deposit(witdrawalAmount);
39 39
         Double actual = bankAccount.getBalance();
40 40
 
41 41
         // then

+ 36
- 3
src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetSpiceCountTest.java Прегледај датотеку

@@ -3,20 +3,53 @@ package rocks.zipcode.quiz3a.objectorientation.food;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 import rocks.zipcode.quiz3a.collections.Food;
6
+import rocks.zipcode.quiz3a.objectorientation.Curry;
7
+import rocks.zipcode.quiz3a.objectorientation.Ginger;
6 8
 import rocks.zipcode.quiz3a.objectorientation.Pepper;
7 9
 import rocks.zipcode.quiz3a.objectorientation.Spice;
8 10
 
9 11
 import java.util.Map;
12
+import java.util.function.Supplier;
10 13
 
11 14
 public class GetSpiceCountTest {
12 15
     @Test
13 16
     public void test1() {
17
+        test(5, Pepper::new);
18
+    }
19
+
20
+    @Test
21
+    public void test2() {
22
+        test(10, Pepper::new);
23
+    }
24
+
25
+    @Test
26
+    public void test3() {
27
+        test(3, Curry::new);
28
+    }
29
+
30
+
31
+    @Test
32
+    public void test4() {
33
+        test(6, Curry::new);
34
+    }
35
+
36
+    @Test
37
+    public void test5() {
38
+        test(2, Ginger::new);
39
+    }
40
+
41
+    @Test
42
+    public void test6() {
43
+        test(4, Ginger::new);
44
+    }
45
+
46
+    public void test(Integer amountOfIngredients, Supplier<?> ingredientConstructor) {
14 47
         // given
48
+        Integer expected = amountOfIngredients;
15 49
         Food food = new Food();
16
-        Integer expected = 5;
17 50
         Spice pepper = null;
18
-        for (int i = 0; i < expected; i++) {
19
-            pepper = (Spice)new Pepper();
51
+        for (int i = 0; i < amountOfIngredients; i++) {
52
+            pepper = (Spice) ingredientConstructor.get();
20 53
             food.applySpice(pepper);
21 54
         }
22 55