Bladeren bron

Merge branch 'master' into DifferenceOfSquaresUseInstanceMethod

Frida Johanne Tveit 9 jaren geleden
bovenliggende
commit
25be440137

+ 13
- 6
exercises/diamond/src/test/java/DiamondPrinterTest.java Bestand weergeven

@@ -1,4 +1,5 @@
1 1
 import org.junit.Ignore;
2
+import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
4 5
 import java.util.List;
@@ -9,17 +10,23 @@ import static org.hamcrest.CoreMatchers.is;
9 10
 import static org.junit.Assert.assertThat;
10 11
 
11 12
 public final class DiamondPrinterTest {
12
-
13
+    private DiamondPrinter diamondPrinter;
14
+    
15
+    @Before
16
+    public void setUp() {
17
+        diamondPrinter = new DiamondPrinter();
18
+    }
19
+        
13 20
     @Test
14 21
     public void testOneByOneDiamond() {
15
-        List<String> output = new DiamondPrinter().printToList('A');
22
+        List<String> output = diamondPrinter.printToList('A');
16 23
         assertThat(output, is(singletonList("A")));
17 24
     }
18 25
 
19 26
     @Ignore
20 27
     @Test
21 28
     public void testTwoByTwoDiamond() {
22
-        List<String> output = new DiamondPrinter().printToList('B');
29
+        List<String> output = diamondPrinter.printToList('B');
23 30
         assertThat(output, is(asList(" A ",
24 31
                                      "B B",
25 32
                                      " A ")));
@@ -28,7 +35,7 @@ public final class DiamondPrinterTest {
28 35
     @Ignore
29 36
     @Test
30 37
     public void testThreeByThreeDiamond() {
31
-        List<String> output = new DiamondPrinter().printToList('C');
38
+        List<String> output = diamondPrinter.printToList('C');
32 39
         assertThat(output, is(asList("  A  ",
33 40
                                      " B B ",
34 41
                                      "C   C",
@@ -39,7 +46,7 @@ public final class DiamondPrinterTest {
39 46
     @Ignore
40 47
     @Test
41 48
     public void testFiveByFiveDiamond() {
42
-        List<String> output = new DiamondPrinter().printToList('E');
49
+        List<String> output = diamondPrinter.printToList('E');
43 50
         assertThat(output, is(asList("    A    ",
44 51
                                      "   B B   ",
45 52
                                      "  C   C  ",
@@ -54,7 +61,7 @@ public final class DiamondPrinterTest {
54 61
     @Ignore
55 62
     @Test
56 63
     public void testFullDiamond() {
57
-        List<String> output = new DiamondPrinter().printToList('Z');
64
+        List<String> output = diamondPrinter.printToList('Z');
58 65
         assertThat(output, is(asList("                         A                         ",
59 66
                                      "                        B B                        ",
60 67
                                      "                       C   C                       ",

+ 21
- 13
exercises/secret-handshake/src/test/java/HandshakeCalculatorTest.java Bestand weergeven

@@ -1,4 +1,5 @@
1 1
 import org.junit.Ignore;
2
+import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
4 5
 import static java.util.Arrays.asList;
@@ -7,12 +8,19 @@ import static java.util.Collections.singletonList;
7 8
 import static org.junit.Assert.assertEquals;
8 9
 
9 10
 public final class HandshakeCalculatorTest {
10
-
11
+    private HandshakeCalculator handshakeCalculator;
12
+    
13
+    
14
+    @Before
15
+    public void setUp() {
16
+        handshakeCalculator = new HandshakeCalculator();
17
+    }
18
+    
11 19
     @Test
12 20
     public void testThatInput1YieldsAWink() {
13 21
         assertEquals(
14 22
                 singletonList(Signal.WINK),
15
-                new HandshakeCalculator().calculateHandshake(1));
23
+                handshakeCalculator.calculateHandshake(1));
16 24
     }
17 25
 
18 26
     @Ignore
@@ -20,7 +28,7 @@ public final class HandshakeCalculatorTest {
20 28
     public void testThatInput2YieldsADoubleBlink() {
21 29
         assertEquals(
22 30
                 singletonList(Signal.DOUBLE_BLINK),
23
-                new HandshakeCalculator().calculateHandshake(2));
31
+                handshakeCalculator.calculateHandshake(2));
24 32
     }
25 33
 
26 34
     @Ignore
@@ -28,7 +36,7 @@ public final class HandshakeCalculatorTest {
28 36
     public void testThatInput4YieldsACloseYourEyes() {
29 37
         assertEquals(
30 38
                 singletonList(Signal.CLOSE_YOUR_EYES),
31
-                new HandshakeCalculator().calculateHandshake(4));
39
+                handshakeCalculator.calculateHandshake(4));
32 40
     }
33 41
 
34 42
     @Ignore
@@ -36,7 +44,7 @@ public final class HandshakeCalculatorTest {
36 44
     public void testThatInput8YieldsAJump() {
37 45
         assertEquals(
38 46
                 singletonList(Signal.JUMP),
39
-                new HandshakeCalculator().calculateHandshake(8));
47
+               handshakeCalculator.calculateHandshake(8));
40 48
     }
41 49
 
42 50
     @Ignore
@@ -44,7 +52,7 @@ public final class HandshakeCalculatorTest {
44 52
     public void testAnInputThatYieldsTwoActions() {
45 53
         assertEquals(
46 54
                 asList(Signal.WINK, Signal.DOUBLE_BLINK),
47
-                new HandshakeCalculator().calculateHandshake(3));
55
+                handshakeCalculator.calculateHandshake(3));
48 56
     }
49 57
 
50 58
     @Ignore
@@ -52,7 +60,7 @@ public final class HandshakeCalculatorTest {
52 60
     public void testAnInputThatYieldsTwoReversedActions() {
53 61
         assertEquals(
54 62
                 asList(Signal.DOUBLE_BLINK, Signal.WINK),
55
-                new HandshakeCalculator().calculateHandshake(19));
63
+               handshakeCalculator.calculateHandshake(19));
56 64
     }
57 65
 
58 66
     @Ignore
@@ -60,7 +68,7 @@ public final class HandshakeCalculatorTest {
60 68
     public void testReversingASingleActionYieldsTheSameAction() {
61 69
         assertEquals(
62 70
                 singletonList(Signal.JUMP),
63
-                new HandshakeCalculator().calculateHandshake(24));
71
+                handshakeCalculator.calculateHandshake(24));
64 72
     }
65 73
 
66 74
     @Ignore
@@ -68,7 +76,7 @@ public final class HandshakeCalculatorTest {
68 76
     public void testReversingNoActionsYieldsNoActions() {
69 77
         assertEquals(
70 78
                 emptyList(),
71
-                new HandshakeCalculator().calculateHandshake(16));
79
+                handshakeCalculator.calculateHandshake(16));
72 80
     }
73 81
 
74 82
     @Ignore
@@ -76,7 +84,7 @@ public final class HandshakeCalculatorTest {
76 84
     public void testInputThatYieldsAllActions() {
77 85
         assertEquals(
78 86
                 asList(Signal.WINK, Signal.DOUBLE_BLINK, Signal.CLOSE_YOUR_EYES, Signal.JUMP),
79
-                new HandshakeCalculator().calculateHandshake(15));
87
+                handshakeCalculator.calculateHandshake(15));
80 88
     }
81 89
 
82 90
     @Ignore
@@ -84,7 +92,7 @@ public final class HandshakeCalculatorTest {
84 92
     public void testInputThatYieldsAllActionsReversed() {
85 93
         assertEquals(
86 94
                 asList(Signal.JUMP, Signal.CLOSE_YOUR_EYES, Signal.DOUBLE_BLINK, Signal.WINK),
87
-                new HandshakeCalculator().calculateHandshake(31));
95
+                handshakeCalculator.calculateHandshake(31));
88 96
     }
89 97
 
90 98
     @Ignore
@@ -92,7 +100,7 @@ public final class HandshakeCalculatorTest {
92 100
     public void testThatInput0YieldsNoActions() {
93 101
         assertEquals(
94 102
                 emptyList(),
95
-                new HandshakeCalculator().calculateHandshake(0));
103
+                handshakeCalculator.calculateHandshake(0));
96 104
     }
97 105
 
98 106
     @Ignore
@@ -100,7 +108,7 @@ public final class HandshakeCalculatorTest {
100 108
     public void testThatInputWithLower5BitsNotSetYieldsNoActions() {
101 109
         assertEquals(
102 110
                 emptyList(),
103
-                new HandshakeCalculator().calculateHandshake(32));
111
+                handshakeCalculator.calculateHandshake(32));
104 112
     }
105 113
 
106 114
 }