Kaynağa Gözat

Merge remote-tracking branch 'upstream/master'

Souvatzis Vasilios 9 yıl önce
ebeveyn
işleme
b644b8e76a

+ 11
- 1
exercises/acronym/src/example/java/Acronym.java Dosyayı Görüntüle

@@ -2,7 +2,17 @@ import java.util.regex.Matcher;
2 2
 import java.util.regex.Pattern;
3 3
 
4 4
 public class Acronym {
5
-    public static String generate(String phrase){
5
+    private final String acronym;
6
+
7
+    public Acronym(String phrase) {
8
+        acronym = generateAcronym(phrase);
9
+    }
10
+
11
+    public String get() {
12
+        return acronym;
13
+    }
14
+
15
+    private String generateAcronym(String phrase){
6 16
         final Pattern BREAK_WORDS = Pattern.compile("[A-Z]+[a-z]*|[a-z]+");
7 17
         final Matcher matcher = BREAK_WORDS.matcher(phrase);
8 18
         final StringBuilder b = new StringBuilder();

+ 8
- 9
exercises/acronym/src/test/java/AcronymTest.java Dosyayı Görüntüle

@@ -5,12 +5,11 @@ import static org.junit.Assert.assertEquals;
5 5
 
6 6
 public class AcronymTest {
7 7
 
8
-
9 8
     @Test
10 9
     public void fromTitleCasedPhrases() {
11 10
         final String phrase = "Portable Network Graphics";
12 11
         final String expected = "PNG";
13
-        assertEquals(expected, Acronym.generate(phrase));
12
+        assertEquals(expected, new Acronym(phrase).get());
14 13
     }
15 14
 
16 15
     @Ignore
@@ -18,7 +17,7 @@ public class AcronymTest {
18 17
     public void fromOtherTitleCasedPhrases() {
19 18
         final String phrase = "Ruby on Rails";
20 19
         final String expected = "ROR";
21
-        assertEquals(expected, Acronym.generate(phrase));
20
+        assertEquals(expected, new Acronym(phrase).get());
22 21
     }
23 22
 
24 23
     @Ignore
@@ -26,7 +25,7 @@ public class AcronymTest {
26 25
     public void fromInconsistentlyCasedPhrases() {
27 26
         final String phrase = "HyperText Markup Language";
28 27
         final String expected = "HTML";
29
-        assertEquals(expected, Acronym.generate(phrase));
28
+        assertEquals(expected, new Acronym(phrase).get());
30 29
     }
31 30
 
32 31
     @Ignore
@@ -34,7 +33,7 @@ public class AcronymTest {
34 33
     public void fromPhrasesWithPunctuation() {
35 34
         final String phrase = "First In, First Out";
36 35
         final String expected = "FIFO";
37
-        assertEquals(expected, Acronym.generate(phrase));
36
+        assertEquals(expected, new Acronym(phrase).get());
38 37
     }
39 38
 
40 39
     @Ignore
@@ -42,7 +41,7 @@ public class AcronymTest {
42 41
     public void fromOtherPhrasesWithPunctuation() {
43 42
         final String phrase = "PHP: Hypertext Preprocessor";
44 43
         final String expected = "PHP";
45
-        assertEquals(expected, Acronym.generate(phrase));
44
+        assertEquals(expected, new Acronym(phrase).get());
46 45
     }
47 46
 
48 47
     @Ignore
@@ -50,7 +49,7 @@ public class AcronymTest {
50 49
     public void fromPhrasesWithNonAcronymAllCapsWord() {
51 50
         final String phrase = "GNU Image Manipulation Program";
52 51
         final String expected = "GIMP";
53
-        assertEquals(expected, Acronym.generate(phrase));
52
+        assertEquals(expected, new Acronym(phrase).get());
54 53
     }
55 54
 
56 55
     @Ignore
@@ -58,7 +57,7 @@ public class AcronymTest {
58 57
     public void fromPhrasesWithPunctuationAndSentenceCasing() {
59 58
         final String phrase = "Complementary metal-oxide semiconductor";
60 59
         final String expected = "CMOS";
61
-        assertEquals(expected, Acronym.generate(phrase));
60
+        assertEquals(expected, new Acronym(phrase).get());
62 61
     }
63 62
 
64 63
     @Ignore
@@ -66,7 +65,7 @@ public class AcronymTest {
66 65
     public void fromPhraseWithSingleLetterWord() {
67 66
         final String phrase = "Cat in a Hat";
68 67
         final String expected = "CIAH";
69
-        assertEquals(expected, Acronym.generate(phrase));
68
+        assertEquals(expected, new Acronym(phrase).get());
70 69
     }
71 70
 
72 71
 }

+ 0
- 0
exercises/allergies/src/main/java/.keep Dosyayı Görüntüle


+ 0
- 0
exercises/binary-search-tree/src/test/java/.keep Dosyayı Görüntüle


+ 0
- 0
exercises/binary-search/src/main/java/.keep Dosyayı Görüntüle


+ 13
- 6
exercises/diamond/src/test/java/DiamondPrinterTest.java Dosyayı Görüntüle

@@ -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                       ",

+ 8
- 2
exercises/grade-school/src/test/java/SchoolTest.java Dosyayı Görüntüle

@@ -1,3 +1,4 @@
1
+import org.junit.Before;
1 2
 import org.junit.Ignore;
2 3
 import org.junit.Test;
3 4
 
@@ -15,7 +16,12 @@ import static org.junit.Assert.assertTrue;
15 16
 import static org.junit.Assert.assertEquals;
16 17
 
17 18
 public class SchoolTest {
18
-  private final School school = new School();
19
+  private School school;
20
+
21
+  @Before
22
+  public void setUp() {
23
+    school = new School();
24
+  }
19 25
 
20 26
   @Test
21 27
   public void startsWithNoStudents() {
@@ -120,7 +126,7 @@ public class SchoolTest {
120 126
       // Such as UnsupportedOperationException when an unmodifiableMap is used
121 127
     }
122 128
 
123
-    assertThat(school.studentsByGradeAlphabetical().get(grade), 
129
+    assertThat(school.studentsByGradeAlphabetical().get(grade),
124 130
       not(hasItem(studentWhichShouldNotBeAdded)));
125 131
   }
126 132
 }

+ 20
- 13
exercises/luhn/src/test/java/LuhnValidatorTest.java Dosyayı Görüntüle

@@ -1,86 +1,93 @@
1 1
 import org.junit.Ignore;
2
+import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
4 5
 import static org.junit.Assert.assertFalse;
5 6
 import static org.junit.Assert.assertTrue;
6 7
 
7 8
 public class LuhnValidatorTest {
9
+    private LuhnValidator luhnValidator;
10
+
11
+    @Before
12
+    public void setUp() {
13
+      luhnValidator = new LuhnValidator();
14
+    }
8 15
 
9 16
     @Test
10 17
     public void testThatSingleDigitStringIsNotValid() {
11
-        assertFalse(new LuhnValidator().isValid("1"));
18
+        assertFalse(luhnValidator.isValid("1"));
12 19
     }
13 20
 
14 21
     @Ignore
15 22
     @Test
16 23
     public void testThatTheStringConsistingOfASingleZeroIsInvalid() {
17
-        assertFalse(new LuhnValidator().isValid("0"));
24
+        assertFalse(luhnValidator.isValid("0"));
18 25
     }
19 26
 
20 27
     @Ignore
21 28
     @Test
22 29
     public void testThatASimpleValidNumberIsIdentifiedAsValid() {
23
-        assertTrue(new LuhnValidator().isValid(" 5 9 "));
30
+        assertTrue(luhnValidator.isValid(" 5 9 "));
24 31
     }
25 32
 
26 33
     @Ignore
27 34
     @Test
28 35
     public void testThatAValidCanadianSocialInsuranceNumberIsIdentifiedAsValidV1() {
29
-        assertTrue(new LuhnValidator().isValid("046 454 286"));
36
+        assertTrue(luhnValidator.isValid("046 454 286"));
30 37
     }
31 38
 
32 39
     @Ignore
33 40
     @Test
34 41
     public void testThatAValidCanadianSocialInsuranceNumberIsIdentifiedAsValidV2() {
35
-        assertTrue(new LuhnValidator().isValid("055 444 285"));
42
+        assertTrue(luhnValidator.isValid("055 444 285"));
36 43
     }
37 44
 
38 45
     @Ignore
39 46
     @Test
40 47
     public void testThatAnInvalidCanadianSocialInsuranceNumberIsIdentifiedAsInvalid() {
41
-        assertFalse(new LuhnValidator().isValid("046 454 287"));
48
+        assertFalse(luhnValidator.isValid("046 454 287"));
42 49
     }
43 50
 
44 51
     @Ignore
45 52
     @Test
46 53
     public void testThatAnInvalidCreditCardIsIdentifiedAsInvalid() {
47
-        assertFalse(new LuhnValidator().isValid("8273 1232 7352 0569"));
54
+        assertFalse(luhnValidator.isValid("8273 1232 7352 0569"));
48 55
     }
49 56
 
50 57
     @Ignore
51 58
     @Test
52 59
     public void testThatAddingANonDigitCharacterToAValidStringInvalidatesTheString() {
53
-        assertFalse(new LuhnValidator().isValid("046a 454 286"));
60
+        assertFalse(luhnValidator.isValid("046a 454 286"));
54 61
     }
55 62
 
56 63
     @Ignore
57 64
     @Test
58 65
     public void testThatStringContainingPunctuationIsInvalid() {
59
-        assertFalse(new LuhnValidator().isValid("055-444-285"));
66
+        assertFalse(luhnValidator.isValid("055-444-285"));
60 67
     }
61 68
 
62 69
     @Ignore
63 70
     @Test
64 71
     public void testThatStringContainingSymbolsIsInvalid() {
65
-        assertFalse(new LuhnValidator().isValid("055£ 444$ 285"));
72
+        assertFalse(luhnValidator.isValid("055£ 444$ 285"));
66 73
     }
67 74
 
68 75
     @Ignore
69 76
     @Test
70 77
     public void testThatTheStringConsistingOfASpaceAndASingleZeroIsInvalid() {
71
-        assertFalse(new LuhnValidator().isValid(" 0"));
78
+        assertFalse(luhnValidator.isValid(" 0"));
72 79
     }
73 80
 
74 81
     @Ignore
75 82
     @Test
76 83
     public void testThatStringContainingMultipleZerosIsValid() {
77
-        assertTrue(new LuhnValidator().isValid(" 00000"));
84
+        assertTrue(luhnValidator.isValid(" 00000"));
78 85
     }
79 86
 
80 87
     @Ignore
81 88
     @Test
82 89
     public void testThatDoublingNineIsHandledCorrectly() {
83
-        assertTrue(new LuhnValidator().isValid("091"));
90
+        assertTrue(luhnValidator.isValid("091"));
84 91
     }
85 92
 
86 93
 }

exercises/raindrops/src/example/java/Raindrops.java → exercises/raindrops/src/example/java/RaindropConverter.java Dosyayı Görüntüle

@@ -1,6 +1,6 @@
1
-public class Raindrops {
1
+public class RaindropConverter {
2 2
 
3
-    public static String convert(int number) {
3
+    public String convert(int number) {
4 4
         String result = "";
5 5
 
6 6
         if (number % 3 == 0) {

exercises/raindrops/src/test/java/RaindropsTest.java → exercises/raindrops/src/test/java/RaindropConverterTest.java Dosyayı Görüntüle

@@ -10,7 +10,7 @@ import java.util.Collection;
10 10
 import static org.junit.Assert.assertEquals;
11 11
 
12 12
 @RunWith(Parameterized.class)
13
-public class RaindropsTest {
13
+public class RaindropConverterTest {
14 14
 
15 15
     private int inputNumber;
16 16
     private String outputFromRaindropConversion;
@@ -46,7 +46,7 @@ public class RaindropsTest {
46 46
         });
47 47
     }
48 48
 
49
-    public RaindropsTest(int inputNumber, String outputFromRaindropConversion) {
49
+    public RaindropConverterTest(int inputNumber, String outputFromRaindropConversion) {
50 50
         this.inputNumber = inputNumber;
51 51
         this.outputFromRaindropConversion = outputFromRaindropConversion;
52 52
     }
@@ -54,6 +54,6 @@ public class RaindropsTest {
54 54
 
55 55
     @Test
56 56
     public void test() {
57
-        assertEquals(outputFromRaindropConversion, Raindrops.convert(inputNumber));
57
+        assertEquals(outputFromRaindropConversion, new RaindropConverter().convert(inputNumber));
58 58
     }
59 59
 }

+ 6
- 1
exercises/robot-name/src/test/java/RobotTest.java Dosyayı Görüntüle

@@ -1,5 +1,6 @@
1 1
 import org.junit.Test;
2 2
 import org.junit.Ignore;
3
+import org.junit.Before;
3 4
 
4 5
 import static org.hamcrest.CoreMatchers.equalTo;
5 6
 import static org.hamcrest.core.Is.is;
@@ -9,8 +10,12 @@ import static org.junit.Assert.assertThat;
9 10
 public class RobotTest {
10 11
 
11 12
     private static final String EXPECTED_ROBOT_NAME_PATTERN = "[A-Z]{2}\\d{3}";
12
-    private final Robot robot = new Robot();
13
+    private Robot robot;
13 14
 
15
+    @Before
16
+    public void setUp() {
17
+      robot = new Robot();
18
+    }
14 19
 
15 20
     @Test
16 21
     public void hasName() {

+ 21
- 13
exercises/secret-handshake/src/test/java/HandshakeCalculatorTest.java Dosyayı Görüntüle

@@ -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
 }

+ 24
- 16
exercises/wordy/src/test/java/WordProblemSolverTest.java Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 import org.junit.Ignore;
2 2
 import org.junit.Rule;
3 3
 import org.junit.Test;
4
+import org.junit.Before;
4 5
 import org.junit.rules.ExpectedException;
5 6
 
6 7
 import static org.junit.Assert.assertEquals;
@@ -14,87 +15,94 @@ public final class WordProblemSolverTest {
14 15
     @Rule
15 16
     public ExpectedException expectedException = ExpectedException.none();
16 17
 
18
+    WordProblemSolver solver;
19
+
20
+    @Before
21
+    public void setup() {
22
+        solver = new WordProblemSolver();
23
+    }
24
+
17 25
     @Test
18 26
     public void testSingleAddition1() {
19
-        assertEquals(2, new WordProblemSolver().solve("What is 1 plus 1?"));
27
+        assertEquals(2, solver.solve("What is 1 plus 1?"));
20 28
     }
21 29
 
22 30
     @Ignore
23 31
     @Test
24 32
     public void testSingleAddition2() {
25
-        assertEquals(55, new WordProblemSolver().solve("What is 53 plus 2?"));
33
+        assertEquals(55, solver.solve("What is 53 plus 2?"));
26 34
     }
27 35
 
28 36
     @Ignore
29 37
     @Test
30 38
     public void testSingleAdditionWithNegativeNumbers() {
31
-        assertEquals(-11, new WordProblemSolver().solve("What is -1 plus -10?"));
39
+        assertEquals(-11, solver.solve("What is -1 plus -10?"));
32 40
     }
33 41
 
34 42
     @Ignore
35 43
     @Test
36 44
     public void testSingleAdditionOfLargeNumbers() {
37
-        assertEquals(45801, new WordProblemSolver().solve("What is 123 plus 45678?"));
45
+        assertEquals(45801, solver.solve("What is 123 plus 45678?"));
38 46
     }
39 47
 
40 48
     @Ignore
41 49
     @Test
42 50
     public void testSingleSubtraction() {
43
-        assertEquals(16, new WordProblemSolver().solve("What is 4 minus -12?"));
51
+        assertEquals(16, solver.solve("What is 4 minus -12?"));
44 52
     }
45 53
 
46 54
     @Ignore
47 55
     @Test
48 56
     public void testSingleMultiplication() {
49
-        assertEquals(-75, new WordProblemSolver().solve("What is -3 multiplied by 25?"));
57
+        assertEquals(-75, solver.solve("What is -3 multiplied by 25?"));
50 58
     }
51 59
 
52 60
     @Ignore
53 61
     @Test
54 62
     public void testSingleDivision() {
55
-        assertEquals(-11, new WordProblemSolver().solve("What is 33 divided by -3?"));
63
+        assertEquals(-11, solver.solve("What is 33 divided by -3?"));
56 64
     }
57 65
 
58 66
     @Ignore
59 67
     @Test
60 68
     public void testMultipleAdditions() {
61
-        assertEquals(3, new WordProblemSolver().solve("What is 1 plus 1 plus 1?"));
69
+        assertEquals(3, solver.solve("What is 1 plus 1 plus 1?"));
62 70
     }
63 71
 
64 72
     @Ignore
65 73
     @Test
66 74
     public void testAdditionThenSubtraction() {
67
-        assertEquals(8, new WordProblemSolver().solve("What is 1 plus 5 minus -2?"));
75
+        assertEquals(8, solver.solve("What is 1 plus 5 minus -2?"));
68 76
     }
69 77
 
70 78
     @Ignore
71 79
     @Test
72 80
     public void testMultipleSubtractions() {
73
-        assertEquals(3, new WordProblemSolver().solve("What is 20 minus 4 minus 13?"));
81
+        assertEquals(3, solver.solve("What is 20 minus 4 minus 13?"));
74 82
     }
75 83
 
76 84
     @Ignore
77 85
     @Test
78 86
     public void testSubtractionThenAddition() {
79
-        assertEquals(14, new WordProblemSolver().solve("What is 17 minus 6 plus 3?"));
87
+        assertEquals(14, solver.solve("What is 17 minus 6 plus 3?"));
80 88
     }
81 89
 
82 90
     @Ignore
83 91
     @Test
84 92
     public void testMultipleMultiplications() {
85
-        assertEquals(-12, new WordProblemSolver().solve("What is 2 multiplied by -2 multiplied by 3?"));
93
+        assertEquals(-12, solver.solve("What is 2 multiplied by -2 multiplied by 3?"));
86 94
     }
87 95
 
88 96
     @Ignore
89 97
     @Test
90 98
     public void testAdditionThenMultiplication() {
91
-        assertEquals(-8, new WordProblemSolver().solve("What is -3 plus 7 multiplied by -2?"));
99
+        assertEquals(-8, solver.solve("What is -3 plus 7 multiplied by -2?"));
92 100
     }
93 101
 
94 102
     @Ignore
95 103
     @Test
96 104
     public void testMultipleDivisions() {
97
-        assertEquals(2, new WordProblemSolver().solve("What is -12 divided by 2 divided by -3?"));
105
+        assertEquals(2, solver.solve("What is -12 divided by 2 divided by -3?"));
98 106
     }
99 107
 
100 108
     @Ignore
@@ -103,7 +111,7 @@ public final class WordProblemSolverTest {
103 111
         expectedException.expect(IllegalArgumentException.class);
104 112
         expectedException.expectMessage("I'm sorry, I don't understand the question!");
105 113
 
106
-        new WordProblemSolver().solve("What is 52 cubed?");
114
+        solver.solve("What is 52 cubed?");
107 115
     }
108 116
 
109 117
     @Ignore
@@ -113,7 +121,7 @@ public final class WordProblemSolverTest {
113 121
         expectedException.expectMessage("I'm sorry, I don't understand the question!");
114 122
 
115 123
         // See https://en.wikipedia.org/wiki/President_of_the_United_States if you really need to know!
116
-        new WordProblemSolver().solve("Who is the President of the United States?");
124
+        solver.solve("Who is the President of the United States?");
117 125
     }
118 126
 
119 127
 }