Leon 5 years ago
parent
commit
bc1fe915e7
24 changed files with 448 additions and 140 deletions
  1. 1
    1
      src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java
  2. 1
    1
      src/main/java/rocks/zipcode/quiz3a/fundamentals/StringUtils.java
  3. 0
    12
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java
  4. 0
    4
      src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Employee.java
  5. 18
    15
      src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/GetMiddleElementTest.java
  6. 18
    16
      src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/RemoveMiddleCharacterTest.java
  7. 4
    4
      src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/AddTest.java
  8. 4
    6
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/CapitalizeMiddleCharacterTest.java
  9. 22
    6
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/GetMiddleCharacterTest.java
  10. 5
    5
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/HasDuplicateConsecutiveCharactersTest.java
  11. 53
    0
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramNegativeTest.java
  12. 16
    5
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramPositiveTest.java
  13. 21
    6
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/LowerCaseMiddleCharacterTest.java
  14. 0
    33
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateCharactersTest.java
  15. 54
    0
      src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateConsecutiveCharactersTest.java
  16. 39
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositNegativeTest.java
  17. 47
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositPositiveTest.java
  18. 4
    2
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositTest.java
  19. 53
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalNegativeTest.java
  20. 17
    8
      src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalPositiveTest.java
  21. 16
    12
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java
  22. 1
    1
      src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeDepositTest.java
  23. 48
    3
      src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetAllSpicesTest.java
  24. 6
    0
      src/test/java/rocks/zipcode/quiz3a/objectorientation/spice/SpicePolymorphismTest.java

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/arrays/ArrayUtils.java View File

@@ -11,4 +11,4 @@ public class ArrayUtils {
11 11
     public static String[] removeMiddleElement(String[] values) {
12 12
         return null;
13 13
     }
14
-}
14
+}

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/fundamentals/StringUtils.java View File

@@ -20,7 +20,7 @@ public class StringUtils {
20 20
         return null;
21 21
     }
22 22
 
23
-    public static Boolean hasDuplicateCharacters(String str) {
23
+    public static Boolean hasDuplicateConsecutiveCharacters(String str) {
24 24
         return null;
25 25
     }
26 26
 

+ 0
- 12
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/BankAccount.java View File

@@ -4,18 +4,6 @@ package rocks.zipcode.quiz3a.objectorientation.account;
4 4
  * @author leon on 27/12/2018.
5 5
  */
6 6
 public class BankAccount {
7
-    public void deposit(Double amountToIncreaseBy) {
8
-
9
-    }
10
-
11
-    public void withdrawal(Double amountToDecreaseBy) {
12
-
13
-    }
14
-
15
-    public Double getBalance() {
16
-        return null;
17
-    }
18
-
19 7
     public void setBalance(Double val) {
20 8
     }
21 9
 }

+ 0
- 4
src/main/java/rocks/zipcode/quiz3a/objectorientation/account/Employee.java View File

@@ -17,8 +17,4 @@ public class Employee {
17 17
     public void setBankAccount(BankAccount bankAccount) {
18 18
 
19 19
     }
20
-
21
-    public String getName() {
22
-        return null;
23
-    }
24 20
 }

+ 18
- 15
src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/GetMiddleElementTest.java View File

@@ -9,37 +9,40 @@ public class GetMiddleElementTest {
9 9
     public void test1() {
10 10
         // given
11 11
         String expected = "Quick";
12
-        String[] strings = {"The", expected, "Brown"};
12
+        String[] input = {"The", expected, "Brown"};
13
+        test(expected, input);
13 14
 
14
-        // when
15
-        String actual = ArrayUtils.getMiddleElement(strings);
16
-
17
-        //then
18
-        Assert.assertEquals(expected, actual);
19 15
     }
20 16
 
21 17
     @Test
22 18
     public void test2() {
23 19
         // given
24 20
         String expected = "Brown";
25
-        String[] strings = {"The", "Quick", expected, "Fox", "Jumps"};
21
+        String[] input = {"The", "Quick", expected, "Fox", "Jumps"};
22
+        test(expected, input);
26 23
 
27
-        // when
28
-        String actual = ArrayUtils.getMiddleElement(strings);
29
-
30
-        //then
31
-        Assert.assertEquals(expected, actual);
32 24
     }
33 25
 
34
-
35 26
     @Test
36 27
     public void test3() {
37 28
         // given
38 29
         String expected = "Fox";
39
-        String[] strings = {"The", "Quick", "Brown", expected, "Jumps", "Over", "The"};
30
+        String[] input = {"The", "Quick", "Brown", expected, "Jumps", "Over", "The"};
31
+        test(expected, input);
32
+    }
33
+
34
+
35
+    @Test
36
+    public void test4() {
37
+        // given
38
+        String expected = "Jumps";
39
+        String[] input = {"The", "Quick", "Brown", "Fox", expected, "Over", "The", "Lazy", "Dog"};
40
+        test(expected, input);
41
+    }
40 42
 
43
+    private void test(String expected, String[] input) {
41 44
         // when
42
-        String actual = ArrayUtils.getMiddleElement(strings);
45
+        String actual = ArrayUtils.getMiddleElement(input);
43 46
 
44 47
         //then
45 48
         Assert.assertEquals(expected, actual);

+ 18
- 16
src/test/java/rocks/zipcode/quiz3a/arrays/arrayutils/RemoveMiddleCharacterTest.java View File

@@ -8,38 +8,40 @@ public class RemoveMiddleCharacterTest {
8 8
     @Test
9 9
     public void test1() {
10 10
         // given
11
-        String[] strings = {"The", "Quick", "Brown"};
12 11
         String[] expected = {"The", "Brown"};
12
+        String[] input = {"The", "Quick", "Brown"};
13
+        test(expected, input);
13 14
 
14
-        // when
15
-        String[] actual = ArrayUtils.removeMiddleElement(strings);
16
-
17
-        //then
18
-        Assert.assertArrayEquals(expected, actual);
19 15
     }
20 16
 
21 17
     @Test
22 18
     public void test2() {
23 19
         // given
24 20
         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);
21
+        String[] input = {"The", "Quick", "Brown", "Fox", "Jumps"};
22
+        test(expected, input);
32 23
     }
33 24
 
34
-
35 25
     @Test
36 26
     public void test3() {
37 27
         // given
38
-        String[] strings = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The"};
39 28
         String[] expected = {"The", "Quick", "Brown", "Jumps", "Over", "The"};
29
+        String[] input = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The"};
30
+        test(expected, input);
31
+    }
32
+
33
+
34
+    @Test
35
+    public void test4() {
36
+        // given
37
+        String[] expected = {"The", "Quick", "Brown", "Fox", "Over", "The", "Lazy", "Dog"};
38
+        String[] input = {"The", "Quick", "Brown", "Fox", "Jumps", "Over", "The", "Lazy", "Dog"};
39
+        test(expected, input);
40
+    }
40 41
 
42
+    private void test(String[] expected, String[] input) {
41 43
         // when
42
-        String[] actual = ArrayUtils.removeMiddleElement(strings);
44
+        String[] actual = ArrayUtils.removeMiddleElement(input);
43 45
 
44 46
         //then
45 47
         Assert.assertArrayEquals(expected, actual);

+ 4
- 4
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/AddTest.java View File

@@ -11,25 +11,25 @@ public class AddTest {
11 11
     @Test
12 12
     public void test1() {
13 13
         // given
14
-        test(81.74, 32.70, 49.04);
14
+        test(98.5, 10.5, 88.5);
15 15
     }
16 16
 
17 17
     @Test
18 18
     public void test2() {
19 19
         // given
20
-        test(1435.93, 689.93, 746.00);
20
+        test(40.12, 19.93, 20.19);
21 21
     }
22 22
 
23 23
     @Test
24 24
     public void test3() {
25 25
         // given
26
-        test(109896.0, 35354.0, 74542.0);
26
+        test(39.94, 19.94, 20.00);
27 27
     }
28 28
 
29 29
     @Test
30 30
     public void test4() {
31 31
         // given
32
-        test(12.0, 4.0, 8.0);
32
+        test(100.00, 50.0, 50.0);
33 33
     }
34 34
 
35 35
     @Test

+ 4
- 6
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/CapitalizeMiddleCharacterTest.java View File

@@ -10,12 +10,7 @@ public class CapitalizeMiddleCharacterTest {
10 10
         // given
11 11
         String input = "o";
12 12
         String expected = "O";
13
-
14
-        // when
15
-        String actual = StringUtils.capitalizeMiddleCharacter(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
13
+        test(expected, input);
19 14
     }
20 15
 
21 16
     @Test
@@ -23,7 +18,10 @@ public class CapitalizeMiddleCharacterTest {
23 18
         // given
24 19
         String input = "ooo";
25 20
         String expected = "oOo";
21
+        test(expected, input);
22
+    }
26 23
 
24
+    private void test(String expected, String input) {
27 25
         // when
28 26
         String actual = StringUtils.capitalizeMiddleCharacter(input);
29 27
 

+ 22
- 6
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/GetMiddleCharacterTest.java View File

@@ -10,12 +10,7 @@ public class GetMiddleCharacterTest {
10 10
         // given
11 11
         String input = "joint";
12 12
         Character expected = 'i';
13
-
14
-        // when
15
-        Character actual = StringUtils.getMiddleCharacter(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
13
+        test(expected, input);
19 14
     }
20 15
 
21 16
 
@@ -24,11 +19,32 @@ public class GetMiddleCharacterTest {
24 19
         // given
25 20
         String input = "burnt";
26 21
         Character expected = 'r';
22
+        test(expected, input);
23
+    }
27 24
 
25
+
26
+    @Test
27
+    public void test3() {
28
+        // given
29
+        String input = "bang!";
30
+        Character expected = 'n';
31
+        test(expected, input);
32
+    }
33
+
34
+    @Test
35
+    public void test4() {
36
+        // given
37
+        String input = "bang!";
38
+        Character expected = 'n';
39
+        test(expected, input);
40
+    }
41
+
42
+    private void test(Character expected, String input) {
28 43
         // when
29 44
         Character actual = StringUtils.getMiddleCharacter(input);
30 45
 
31 46
         // then
32 47
         Assert.assertEquals(expected, actual);
33 48
     }
49
+
34 50
 }

src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/HasDuplicateCharacterTest.java → src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/HasDuplicateConsecutiveCharactersTest.java View File

@@ -4,28 +4,28 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6 6
 
7
-public class HasDuplicateCharacterTest {
7
+public class HasDuplicateConsecutiveCharactersTest {
8 8
     @Test
9 9
     public void test1() {
10 10
         String input = "Happy";
11
-        Assert.assertFalse(StringUtils.hasDuplicateCharacters(input));
11
+        Assert.assertFalse(StringUtils.hasDuplicateConsecutiveCharacters(input));
12 12
     }
13 13
 
14 14
     @Test
15 15
     public void test2() {
16 16
         String input = "Fool";
17
-        Assert.assertTrue(StringUtils.hasDuplicateCharacters(input));
17
+        Assert.assertTrue(StringUtils.hasDuplicateConsecutiveCharacters(input));
18 18
     }
19 19
 
20 20
     @Test
21 21
     public void test3() {
22 22
         String input = "George";
23
-        Assert.assertFalse(StringUtils.hasDuplicateCharacters(input));
23
+        Assert.assertFalse(StringUtils.hasDuplicateConsecutiveCharacters(input));
24 24
     }
25 25
 
26 26
     @Test
27 27
     public void test4() {
28 28
         String input = "False";
29
-        Assert.assertFalse(StringUtils.hasDuplicateCharacters(input));
29
+        Assert.assertFalse(StringUtils.hasDuplicateConsecutiveCharacters(input));
30 30
     }
31 31
 }

+ 53
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramNegativeTest.java View File

@@ -0,0 +1,53 @@
1
+package rocks.zipcode.quiz3a.fundamentals.stringutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
+
7
+/**
8
+ * @author leon on 02/01/2019.
9
+ */
10
+public class IsogramNegativeTest {
11
+    @Test
12
+    public void test1() {
13
+        String input = "XX";
14
+        Assert.assertFalse(StringUtils.isIsogram(input));
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        String input = "XXX";
20
+        Assert.assertFalse(StringUtils.isIsogram(input));
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        String input = "AA";
26
+        Assert.assertFalse(StringUtils.isIsogram(input));
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        String input = "AAA";
32
+        Assert.assertFalse(StringUtils.isIsogram(input));
33
+    }
34
+
35
+
36
+    @Test
37
+    public void test5() {
38
+        String input = "Here";
39
+        Assert.assertFalse(StringUtils.isIsogram(input));
40
+    }
41
+
42
+    @Test
43
+    public void test6() {
44
+        String input = "Teared";
45
+        Assert.assertFalse(StringUtils.isIsogram(input));
46
+    }
47
+
48
+    @Test
49
+    public void test7() {
50
+        String input = "Brown Fox";
51
+        Assert.assertFalse(StringUtils.isIsogram(input));
52
+    }
53
+}

src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsIsoGramTest.java → src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/IsogramPositiveTest.java View File

@@ -4,7 +4,7 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6 6
 
7
-public class IsIsoGramTest {
7
+public class IsogramPositiveTest {
8 8
     @Test
9 9
     public void test1() {
10 10
         String input = "Jump";
@@ -19,13 +19,24 @@ public class IsIsoGramTest {
19 19
 
20 20
     @Test
21 21
     public void test3() {
22
-        String input = "Here";
23
-        Assert.assertFalse(StringUtils.isIsogram(input));
22
+        String input = "Jj0Oo";
23
+        Assert.assertTrue(StringUtils.isIsogram(input));
24 24
     }
25 25
 
26
+
26 27
     @Test
27 28
     public void test4() {
28
-        String input = "Teared";
29
-        Assert.assertFalse(StringUtils.isIsogram(input));
29
+        String input = "The Quick";
30
+        Assert.assertTrue(StringUtils.isIsogram(input));
30 31
     }
32
+
33
+    @Test
34
+    public void test5() {
35
+        String input = "Brown";
36
+        Assert.assertTrue(StringUtils.isIsogram(input));
37
+    }
38
+
39
+
40
+
41
+
31 42
 }

+ 21
- 6
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/LowerCaseMiddleCharacterTest.java View File

@@ -10,12 +10,7 @@ public class LowerCaseMiddleCharacterTest {
10 10
         // given
11 11
         String input = "O";
12 12
         String expected = "o";
13
-
14
-        // when
15
-        String actual = StringUtils.lowerCaseMiddleCharacter(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
13
+        test(expected, input);
19 14
     }
20 15
 
21 16
     @Test
@@ -23,11 +18,31 @@ public class LowerCaseMiddleCharacterTest {
23 18
         // given
24 19
         String input = "OOO";
25 20
         String expected = "OoO";
21
+        test(expected, input);
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        // given
27
+        String input = "APPLE";
28
+        String expected = "APpLE";
29
+        test(expected, input);
30
+    }
31
+
32
+    @Test
33
+    public void test4() {
34
+        // given
35
+        String input = "Waffle Sauces";
36
+        String expected = "Waffle Sauces";
37
+        test(expected, input);
38
+    }
26 39
 
40
+    public void test(String expected, String input) {
27 41
         // when
28 42
         String actual = StringUtils.lowerCaseMiddleCharacter(input);
29 43
 
30 44
         // then
31 45
         Assert.assertEquals(expected, actual);
32 46
     }
47
+
33 48
 }

+ 0
- 33
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateCharactersTest.java View File

@@ -1,33 +0,0 @@
1
-package rocks.zipcode.quiz3a.fundamentals.stringutils;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
-
7
-public class RemoveDuplicateCharactersTest {
8
-    @Test
9
-    public void test1() {
10
-        // given
11
-        String input = "Fool";
12
-        String expected = "Fl";
13
-
14
-        // when
15
-        String actual = StringUtils.removeConsecutiveDuplicateCharacters(input);
16
-
17
-        // then
18
-        Assert.assertEquals(expected, actual);
19
-    }
20
-
21
-    @Test
22
-    public void test2() {
23
-        // given
24
-        String input = "Mississippi";
25
-        String expected = "Miiii";
26
-
27
-        // when
28
-        String actual = StringUtils.removeConsecutiveDuplicateCharacters(input);
29
-
30
-        // then
31
-        Assert.assertEquals(expected, actual);
32
-    }
33
-}

+ 54
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/stringutils/RemoveDuplicateConsecutiveCharactersTest.java View File

@@ -0,0 +1,54 @@
1
+package rocks.zipcode.quiz3a.fundamentals.stringutils;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.StringUtils;
6
+
7
+public class RemoveDuplicateConsecutiveCharactersTest {
8
+    @Test
9
+    public void test1() {
10
+        // given
11
+        String input = "Fool";
12
+        String expected = "Fl";
13
+        test(expected, input);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        // given
19
+        String input = "Mississippi";
20
+        String expected = "Miiii";
21
+        test(expected, input);
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        // given
27
+        String input = "Fleet";
28
+        String expected = "Flt";
29
+        test(expected, input);
30
+    }
31
+
32
+    @Test
33
+    public void test4() {
34
+        // given
35
+        String input = "Independence";
36
+        String expected = input;
37
+        test(expected, input);
38
+    }
39
+    @Test
40
+    public void test5() {
41
+        // given
42
+        String input = "Integer";
43
+        String expected = input;
44
+        test(expected, input);
45
+    }
46
+
47
+    public void test(String expected, String input) {
48
+        // when
49
+        String actual = StringUtils.removeConsecutiveDuplicateCharacters(input);
50
+
51
+        // then
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+}

+ 39
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositNegativeTest.java View File

@@ -0,0 +1,39 @@
1
+package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
7
+
8
+/**
9
+ * @author leon on 02/01/2019.
10
+ */
11
+@SuppressWarnings("all")
12
+public class DepositNegativeTest {
13
+
14
+
15
+    @Test(expected = IllegalArgumentException.class)
16
+    public void test1() {
17
+        test(100.0, -1.0);
18
+    }
19
+
20
+    @Test(expected = IllegalArgumentException.class)
21
+    public void test2() {
22
+        test(10.0, 50.0);
23
+    }
24
+
25
+    public void test(Double initialBalance, Double witdrawalAmount) {
26
+        // given
27
+        Double expected = initialBalance + witdrawalAmount;
28
+        BankAccount bankAccount = new BankAccount();
29
+        Transactable transactable = (Transactable)bankAccount;
30
+        bankAccount.setBalance(initialBalance);
31
+
32
+        // when
33
+        transactable.deposit(witdrawalAmount);
34
+        Double actual = transactable.getBalance();
35
+
36
+        // then
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+}

+ 47
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositPositiveTest.java View File

@@ -0,0 +1,47 @@
1
+package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
7
+
8
+/**
9
+ * @author leon on 02/01/2019.
10
+ */
11
+@SuppressWarnings("all")
12
+public class DepositPositiveTest {
13
+    @Test(expected = IllegalArgumentException.class)
14
+    public void test1() {
15
+        test(100.0, -1.0);
16
+    }
17
+
18
+    @Test(expected = IllegalArgumentException.class)
19
+    public void test2() {
20
+        test(10.0, 50.0);
21
+    }
22
+
23
+    @Test(expected = IllegalArgumentException.class)
24
+    public void test3() {
25
+        test(55.0, 500.0);
26
+    }
27
+
28
+    @Test(expected = IllegalArgumentException.class)
29
+    public void test4() {
30
+        test(78.0, 90.0);
31
+    }
32
+
33
+    public void test(Double initialBalance, Double witdrawalAmount) {
34
+        // given
35
+        Double expected = initialBalance + witdrawalAmount;
36
+        BankAccount bankAccount = new BankAccount();
37
+        Transactable transactable = (Transactable)bankAccount;
38
+        bankAccount.setBalance(initialBalance);
39
+
40
+        // when
41
+        transactable.deposit(witdrawalAmount);
42
+        Double actual = transactable.getBalance();
43
+
44
+        // then
45
+        Assert.assertEquals(expected, actual);
46
+    }
47
+}

+ 4
- 2
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/DepositTest.java View File

@@ -3,6 +3,7 @@ package rocks.zipcode.quiz3a.objectorientation.bankaccount;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
6 7
 
7 8
 /**
8 9
  * @author leon on 30/12/2018.
@@ -32,11 +33,12 @@ public class DepositTest {
32 33
         // given
33 34
         Double expected = initialBalance + witdrawalAmount;
34 35
         BankAccount bankAccount = new BankAccount();
36
+        Transactable transactable = (Transactable)bankAccount;
35 37
         bankAccount.setBalance(initialBalance);
36 38
 
37 39
         // when
38
-        bankAccount.deposit(witdrawalAmount);
39
-        Double actual = bankAccount.getBalance();
40
+        transactable.deposit(witdrawalAmount);
41
+        Double actual = transactable.getBalance();
40 42
 
41 43
         // then
42 44
         Assert.assertEquals(expected, actual);

+ 53
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalNegativeTest.java View File

@@ -0,0 +1,53 @@
1
+package rocks.zipcode.quiz3a.objectorientation.bankaccount;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
7
+
8
+/**
9
+ * @author leon on 30/12/2018.
10
+ */
11
+@SuppressWarnings("all")
12
+public class WithdrawalNegativeTest {
13
+
14
+    @Test(expected = IllegalArgumentException.class)
15
+    public void test1() {
16
+        test(0.0, 1.0);
17
+    }
18
+
19
+    @Test(expected = IllegalArgumentException.class)
20
+    public void test2() {
21
+        test(10.0, 50.0);
22
+    }
23
+
24
+    @Test(expected = IllegalArgumentException.class)
25
+    public void test3() {
26
+        test(10.0, -50.0);
27
+    }
28
+
29
+    @Test(expected = IllegalArgumentException.class)
30
+    public void test4() {
31
+        test(00.0, -50.0);
32
+    }
33
+
34
+    @Test(expected = IllegalArgumentException.class)
35
+    public void test5() {
36
+        test(00.0, 0.01);
37
+    }
38
+
39
+    private void test(Double initialBalance, Double withdrawalAmount) {
40
+        // given
41
+        Double expected = initialBalance - withdrawalAmount;
42
+        BankAccount bankAccount = new BankAccount();
43
+        Transactable transactable = (Transactable)bankAccount;
44
+        bankAccount.setBalance(initialBalance);
45
+
46
+        // when
47
+        transactable.withdrawal(withdrawalAmount);
48
+        Double actual = transactable.getBalance();
49
+
50
+        // then
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+}

src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalTest.java → src/test/java/rocks/zipcode/quiz3a/objectorientation/bankaccount/WithdrawalPositiveTest.java View File

@@ -3,11 +3,13 @@ package rocks.zipcode.quiz3a.objectorientation.bankaccount;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 import rocks.zipcode.quiz3a.objectorientation.account.BankAccount;
6
+import rocks.zipcode.quiz3a.objectorientation.account.Transactable;
6 7
 
7 8
 /**
8
- * @author leon on 30/12/2018.
9
+ * @author leon on 02/01/2019.
9 10
  */
10
-public class WithdrawalTest {
11
+@SuppressWarnings("all")
12
+public class WithdrawalPositiveTest {
11 13
     @Test
12 14
     public void test1() {
13 15
         test(100.0, 80.0);
@@ -18,25 +20,32 @@ public class WithdrawalTest {
18 20
         test(150.0, 70.0);
19 21
     }
20 22
 
21
-    @Test(expected = IllegalArgumentException.class)
23
+
24
+    @Test
22 25
     public void test3() {
23
-        test(100.0, 180.0);
26
+        test(150.0, 150.0);
24 27
     }
25 28
 
26
-    @Test(expected = IllegalArgumentException.class)
29
+    @Test
27 30
     public void test4() {
28
-        test(10.0, 50.0);
31
+        test(150.0, 100.0);
32
+    }
33
+
34
+    @Test
35
+    public void test5() {
36
+        test(150.0, 50.0);
29 37
     }
30 38
 
31 39
     public void test(Double initialBalance, Double withdrawalAmount) {
32 40
         // given
33 41
         Double expected = initialBalance - withdrawalAmount;
34 42
         BankAccount bankAccount = new BankAccount();
43
+        Transactable transactable = (Transactable)bankAccount;
35 44
         bankAccount.setBalance(initialBalance);
36 45
 
37 46
         // when
38
-        bankAccount.withdrawal(withdrawalAmount);
39
-        Double actual = bankAccount.getBalance();
47
+        transactable.withdrawal(withdrawalAmount);
48
+        Double actual = transactable.getBalance();
40 49
 
41 50
         // then
42 51
         Assert.assertEquals(expected, actual);

+ 16
- 12
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeConstructorTest.java View File

@@ -15,8 +15,11 @@ public class EmployeeConstructorTest {
15 15
     public void testNullaryConstructor() {
16 16
         // given
17 17
         Employee employee = new Employee();
18
-        Worker worker = (Worker) employee;
19
-        Transactable transactable = (Transactable) employee;
18
+        Worker workerEmployee = (Worker) employee;
19
+        Transactable transactableEmployee = (Transactable) employee;
20
+        Transactable bankAccount = (Transactable) employee.getBankAccount();
21
+
22
+
20 23
 
21 24
         Double expectedHourlyWage = 35.0;
22 25
         Double expectedHoursWorked = 0.0;
@@ -24,10 +27,10 @@ public class EmployeeConstructorTest {
24 27
         Double expectedBankAccountBalance = 0.0;
25 28
 
26 29
         Assert.assertNotNull(employee.getBankAccount());
27
-        Assert.assertEquals(expectedHourlyWage, worker.getHourlyWage());
28
-        Assert.assertEquals(expectedHoursWorked, worker.getHoursWorked());
29
-        Assert.assertEquals(expectedBalance, transactable.getBalance());
30
-        Assert.assertEquals(expectedBankAccountBalance, employee.getBankAccount().getBalance());
30
+        Assert.assertEquals(expectedHourlyWage, workerEmployee.getHourlyWage());
31
+        Assert.assertEquals(expectedHoursWorked, workerEmployee.getHoursWorked());
32
+        Assert.assertEquals(expectedBalance, transactableEmployee.getBalance());
33
+        Assert.assertEquals(expectedBankAccountBalance, bankAccount.getBalance());
31 34
     }
32 35
 
33 36
     @Test
@@ -40,19 +43,20 @@ public class EmployeeConstructorTest {
40 43
         Double expectedMoneyEarned = expectedHourlyWage * expectedHoursWorked;
41 44
         BankAccount bankAccount = new BankAccount();
42 45
         bankAccount.setBalance(expectedBankAccountBalance);
46
+        Transactable transactableBankAccount = (Transactable)bankAccount;
43 47
 
44 48
         // when
45 49
         Employee employee = new Employee(bankAccount);
46
-        Worker worker = (Worker) employee;
47
-        Transactable transactable = (Transactable) employee;
50
+        Worker workerEmployee = (Worker) employee;
51
+        Transactable transactableEmployee = (Transactable) employee;
48 52
 
49 53
 
50 54
         Assert.assertNotNull(employee.getBankAccount());
51
-        Assert.assertEquals(expectedHourlyWage, worker.getHourlyWage());
52
-        Assert.assertEquals(expectedHoursWorked, worker.getHoursWorked());
53
-        Assert.assertEquals(expectedBalance, transactable.getBalance());
55
+        Assert.assertEquals(expectedHourlyWage, workerEmployee.getHourlyWage());
56
+        Assert.assertEquals(expectedHoursWorked, workerEmployee.getHoursWorked());
57
+        Assert.assertEquals(expectedBalance, transactableEmployee.getBalance());
54 58
         Assert.assertEquals(expectedMoneyEarned, expectedMoneyEarned);
55
-        Assert.assertEquals(expectedBankAccountBalance, employee.getBankAccount().getBalance());
59
+        Assert.assertEquals(expectedBankAccountBalance, transactableBankAccount.getBalance());
56 60
     }
57 61
 
58 62
 }

+ 1
- 1
src/test/java/rocks/zipcode/quiz3a/objectorientation/employee/EmployeeDepositTest.java View File

@@ -49,7 +49,7 @@ public class EmployeeDepositTest {
49 49
         // when
50 50
         employeeAsTransactable.deposit(amountToDeposit);
51 51
         Double actualEmployeeBalance = employeeAsTransactable.getBalance();
52
-        Double actualBankAccountBalance = bankAccount.getBalance();
52
+        Double actualBankAccountBalance = ((Transactable)bankAccount).getBalance();
53 53
 
54 54
 
55 55
         // then

+ 48
- 3
src/test/java/rocks/zipcode/quiz3a/objectorientation/food/GetAllSpicesTest.java View File

@@ -10,17 +10,62 @@ import rocks.zipcode.quiz3a.objectorientation.Spice;
10 10
 
11 11
 import java.util.Arrays;
12 12
 import java.util.List;
13
+import java.util.function.Supplier;
13 14
 
14 15
 public class GetAllSpicesTest {
15 16
     @Test
16 17
     public void test1() {
17 18
         // given
18
-        Food food = new Food();
19
-        List<Spice> expected = Arrays.asList(
19
+        test(() -> Arrays.asList(
20
+                (Spice) new Pepper(),
21
+                (Spice) new Ginger(),
22
+                (Spice) new Curry()));
23
+    }
24
+
25
+    @Test
26
+    public void test2() {
27
+        // given
28
+        test(() -> Arrays.asList(
29
+                (Spice) new Pepper(),
30
+                (Spice) new Pepper(),
31
+                (Spice) new Ginger(),
32
+                (Spice) new Curry()));
33
+    }
34
+
35
+
36
+    @Test
37
+    public void test3() {
38
+        // given
39
+        test(() -> Arrays.asList(
40
+                (Spice) new Pepper(),
20 41
                 (Spice) new Pepper(),
21 42
                 (Spice) new Ginger(),
22
-                (Spice) new Curry());
43
+                (Spice) new Ginger(),
44
+                (Spice) new Curry()));
45
+    }
46
+
47
+
48
+    @Test
49
+    public void test4() {
50
+        // given
51
+        test(() -> Arrays.asList((Spice) new Curry()));
52
+    }
53
+
54
+    @Test
55
+    public void test5() {
56
+        // given
57
+        test(() -> Arrays.asList((Spice) new Ginger()));
58
+    }
59
+
60
+    @Test
61
+    public void test6() {
62
+        // given
63
+        test(() -> Arrays.asList((Spice) new Pepper()));
64
+    }
23 65
 
66
+    private void test(Supplier<List<Spice>> listSupplier) {
67
+        List<Spice> expected = listSupplier.get();
68
+        Food food = new Food();
24 69
         for (Spice spice : expected) {
25 70
             food.applySpice(spice);
26 71
         }

+ 6
- 0
src/test/java/rocks/zipcode/quiz3a/objectorientation/spice/SpicePolymorphismTest.java View File

@@ -2,6 +2,7 @@ package rocks.zipcode.quiz3a.objectorientation.spice;
2 2
 
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5
+import rocks.zipcode.quiz3a.objectorientation.Curry;
5 6
 import rocks.zipcode.quiz3a.objectorientation.Ginger;
6 7
 import rocks.zipcode.quiz3a.objectorientation.Pepper;
7 8
 import rocks.zipcode.quiz3a.objectorientation.Spice;
@@ -19,4 +20,9 @@ public class SpicePolymorphismTest {
19 20
     public void testGingerIsSpice() {
20 21
         Assert.assertTrue(new Ginger() instanceof Spice);
21 22
     }
23
+
24
+    @Test
25
+    public void testCurryIsSpice() {
26
+        Assert.assertTrue(new Curry() instanceof Spice);
27
+    }
22 28
 }