|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Rule;
|
|
|
3
|
+import org.junit.Test;
|
|
|
4
|
+import org.junit.rules.ExpectedException;
|
|
|
5
|
+
|
|
|
6
|
+import static org.junit.Assert.assertEquals;
|
|
|
7
|
+
|
|
|
8
|
+public final class WordProblemSolverTest {
|
|
|
9
|
+
|
|
|
10
|
+ /*
|
|
|
11
|
+ * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
|
|
|
12
|
+ * ExpectedExceptions in particular.
|
|
|
13
|
+ */
|
|
|
14
|
+ @Rule
|
|
|
15
|
+ public ExpectedException expectedException = ExpectedException.none();
|
|
|
16
|
+
|
|
|
17
|
+ @Test
|
|
|
18
|
+ public void testSingleAddition1() {
|
|
|
19
|
+ assertEquals(2, new WordProblemSolver().solve("What is 1 plus 1?"));
|
|
|
20
|
+ }
|
|
|
21
|
+
|
|
|
22
|
+ @Ignore
|
|
|
23
|
+ @Test
|
|
|
24
|
+ public void testSingleAddition2() {
|
|
|
25
|
+ assertEquals(55, new WordProblemSolver().solve("What is 53 plus 2?"));
|
|
|
26
|
+ }
|
|
|
27
|
+
|
|
|
28
|
+ @Ignore
|
|
|
29
|
+ @Test
|
|
|
30
|
+ public void testSingleAdditionWithNegativeNumbers() {
|
|
|
31
|
+ assertEquals(-11, new WordProblemSolver().solve("What is -1 plus -10?"));
|
|
|
32
|
+ }
|
|
|
33
|
+
|
|
|
34
|
+ @Ignore
|
|
|
35
|
+ @Test
|
|
|
36
|
+ public void testSingleAdditionOfLargeNumbers() {
|
|
|
37
|
+ assertEquals(45801, new WordProblemSolver().solve("What is 123 plus 45678?"));
|
|
|
38
|
+ }
|
|
|
39
|
+
|
|
|
40
|
+ @Ignore
|
|
|
41
|
+ @Test
|
|
|
42
|
+ public void testSingleSubtraction() {
|
|
|
43
|
+ assertEquals(16, new WordProblemSolver().solve("What is 4 minus -12?"));
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
|
46
|
+ @Ignore
|
|
|
47
|
+ @Test
|
|
|
48
|
+ public void testSingleMultiplication() {
|
|
|
49
|
+ assertEquals(-75, new WordProblemSolver().solve("What is -3 multiplied by 25?"));
|
|
|
50
|
+ }
|
|
|
51
|
+
|
|
|
52
|
+ @Ignore
|
|
|
53
|
+ @Test
|
|
|
54
|
+ public void testSingleDivision() {
|
|
|
55
|
+ assertEquals(-11, new WordProblemSolver().solve("What is 33 divided by -3?"));
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ @Ignore
|
|
|
59
|
+ @Test
|
|
|
60
|
+ public void testMultipleAdditions() {
|
|
|
61
|
+ assertEquals(3, new WordProblemSolver().solve("What is 1 plus 1 plus 1?"));
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
|
64
|
+ @Ignore
|
|
|
65
|
+ @Test
|
|
|
66
|
+ public void testAdditionThenSubtraction() {
|
|
|
67
|
+ assertEquals(8, new WordProblemSolver().solve("What is 1 plus 5 minus -2?"));
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ @Ignore
|
|
|
71
|
+ @Test
|
|
|
72
|
+ public void testMultipleSubtractions() {
|
|
|
73
|
+ assertEquals(3, new WordProblemSolver().solve("What is 20 minus 4 minus 13?"));
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ @Ignore
|
|
|
77
|
+ @Test
|
|
|
78
|
+ public void testSubtractionThenAddition() {
|
|
|
79
|
+ assertEquals(14, new WordProblemSolver().solve("What is 17 minus 6 plus 3?"));
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ @Ignore
|
|
|
83
|
+ @Test
|
|
|
84
|
+ public void testMultipleMultiplications() {
|
|
|
85
|
+ assertEquals(-12, new WordProblemSolver().solve("What is 2 multiplied by -2 multiplied by 3?"));
|
|
|
86
|
+ }
|
|
|
87
|
+
|
|
|
88
|
+ @Ignore
|
|
|
89
|
+ @Test
|
|
|
90
|
+ public void testAdditionThenMultiplication() {
|
|
|
91
|
+ assertEquals(-8, new WordProblemSolver().solve("What is -3 plus 7 multiplied by -2?"));
|
|
|
92
|
+ }
|
|
|
93
|
+
|
|
|
94
|
+ @Ignore
|
|
|
95
|
+ @Test
|
|
|
96
|
+ public void testMultipleDivisions() {
|
|
|
97
|
+ assertEquals(2, new WordProblemSolver().solve("What is -12 divided by 2 divided by -3?"));
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ @Ignore
|
|
|
101
|
+ @Test
|
|
|
102
|
+ public void testUnknownOperation() {
|
|
|
103
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
104
|
+ expectedException.expectMessage("I'm sorry, I don't understand the question!");
|
|
|
105
|
+
|
|
|
106
|
+ new WordProblemSolver().solve("What is 52 cubed?");
|
|
|
107
|
+ }
|
|
|
108
|
+
|
|
|
109
|
+ @Ignore
|
|
|
110
|
+ @Test
|
|
|
111
|
+ public void testInvalidQuestionFormat() {
|
|
|
112
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
113
|
+ expectedException.expectMessage("I'm sorry, I don't understand the question!");
|
|
|
114
|
+
|
|
|
115
|
+ // 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?");
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+}
|