浏览代码

Merge branch 'master' into DifferenceOfSquaresUseInstanceMethod

Frida Johanne Tveit 9 年前
父节点
当前提交
25be440137

+ 13
- 6
exercises/diamond/src/test/java/DiamondPrinterTest.java 查看文件

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

+ 21
- 13
exercises/secret-handshake/src/test/java/HandshakeCalculatorTest.java 查看文件

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