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