11import org .junit .jupiter .api .Disabled ;
2+ import org .junit .jupiter .api .DisplayName ;
23import org .junit .jupiter .api .Test ;
34
45import static org .assertj .core .api .Assertions .assertThat ;
@@ -9,129 +10,175 @@ public class WordProblemSolverTest {
910 WordProblemSolver solver = new WordProblemSolver ();
1011
1112 @ Test
13+ @ DisplayName ("just a number" )
1214 public void testJustANumber () {
1315 assertThat (solver .solve ("What is 5?" )).isEqualTo (5 );
1416 }
1517
18+ @ Test
19+ @ DisplayName ("just a zero" )
20+ public void testJustAZero () {
21+ assertThat (solver .solve ("What is 0?" )).isEqualTo (0 );
22+ }
23+
24+ @ Test
25+ @ DisplayName ("just a negative number" )
26+ public void testJustANegativeNumber () {
27+ assertThat (solver .solve ("What is -123?" )).isEqualTo (-123 );
28+ }
29+
1630 @ Disabled ("Remove to run test" )
1731 @ Test
32+ @ DisplayName ("addition" )
1833 public void testSingleAddition1 () {
1934 assertThat (solver .solve ("What is 1 plus 1?" )).isEqualTo (2 );
2035 }
2136
2237 @ Disabled ("Remove to run test" )
2338 @ Test
39+ @ DisplayName ("addition with a left hand zero" )
40+ public void testAdditionWithALeftHandZero () {
41+ assertThat (solver .solve ("What is 0 plus 2?" )).isEqualTo (2 );
42+ }
43+
44+ @ Disabled ("Remove to run test" )
45+ @ Test
46+ @ DisplayName ("addition with a right hand zero" )
47+ public void testAdditionWithARightHandZero () {
48+ assertThat (solver .solve ("What is 3 plus 0?" )).isEqualTo (3 );
49+ }
50+
51+ @ Disabled ("Remove to run test" )
52+ @ Test
53+ @ DisplayName ("more addition" )
2454 public void testSingleAddition2 () {
2555 assertThat (solver .solve ("What is 53 plus 2?" )).isEqualTo (55 );
2656 }
2757
2858 @ Disabled ("Remove to run test" )
2959 @ Test
60+ @ DisplayName ("addition with negative numbers" )
3061 public void testSingleAdditionWithNegativeNumbers () {
3162 assertThat (solver .solve ("What is -1 plus -10?" )).isEqualTo (-11 );
3263 }
3364
3465 @ Disabled ("Remove to run test" )
3566 @ Test
67+ @ DisplayName ("large addition" )
3668 public void testSingleAdditionOfLargeNumbers () {
3769 assertThat (solver .solve ("What is 123 plus 45678?" )).isEqualTo (45801 );
3870 }
3971
4072 @ Disabled ("Remove to run test" )
4173 @ Test
74+ @ DisplayName ("subtraction" )
4275 public void testSingleSubtraction () {
4376 assertThat (solver .solve ("What is 4 minus -12?" )).isEqualTo (16 );
4477 }
4578
4679 @ Disabled ("Remove to run test" )
4780 @ Test
81+ @ DisplayName ("multiplication" )
4882 public void testSingleMultiplication () {
4983 assertThat (solver .solve ("What is -3 multiplied by 25?" )).isEqualTo (-75 );
5084 }
5185
5286 @ Disabled ("Remove to run test" )
5387 @ Test
88+ @ DisplayName ("division" )
5489 public void testSingleDivision () {
5590 assertThat (solver .solve ("What is 33 divided by -3?" )).isEqualTo (-11 );
5691 }
5792
5893 @ Disabled ("Remove to run test" )
5994 @ Test
95+ @ DisplayName ("multiple additions" )
6096 public void testMultipleAdditions () {
6197 assertThat (solver .solve ("What is 1 plus 1 plus 1?" )).isEqualTo (3 );
6298 }
6399
64100 @ Disabled ("Remove to run test" )
65101 @ Test
102+ @ DisplayName ("addition and subtraction" )
66103 public void testAdditionThenSubtraction () {
67104 assertThat (solver .solve ("What is 1 plus 5 minus -2?" )).isEqualTo (8 );
68105 }
69106
70107 @ Disabled ("Remove to run test" )
71108 @ Test
109+ @ DisplayName ("multiple subtraction" )
72110 public void testMultipleSubtractions () {
73111 assertThat (solver .solve ("What is 20 minus 4 minus 13?" )).isEqualTo (3 );
74112 }
75113
76114 @ Disabled ("Remove to run test" )
77115 @ Test
116+ @ DisplayName ("subtraction then addition" )
78117 public void testSubtractionThenAddition () {
79118 assertThat (solver .solve ("What is 17 minus 6 plus 3?" )).isEqualTo (14 );
80119 }
81120
82121 @ Disabled ("Remove to run test" )
83122 @ Test
123+ @ DisplayName ("multiple multiplication" )
84124 public void testMultipleMultiplications () {
85125 assertThat (solver .solve ("What is 2 multiplied by -2 multiplied by 3?" )).isEqualTo (-12 );
86126 }
87127
88128 @ Disabled ("Remove to run test" )
89129 @ Test
130+ @ DisplayName ("addition and multiplication" )
90131 public void testAdditionThenMultiplication () {
91132 assertThat (solver .solve ("What is -3 plus 7 multiplied by -2?" )).isEqualTo (-8 );
92133 }
93134
94135 @ Disabled ("Remove to run test" )
95136 @ Test
137+ @ DisplayName ("multiple division" )
96138 public void testMultipleDivisions () {
97139 assertThat (solver .solve ("What is -12 divided by 2 divided by -3?" )).isEqualTo (2 );
98140 }
99141
100142 @ Disabled ("Remove to run test" )
101143 @ Test
144+ @ DisplayName ("unknown operation" )
102145 public void testUnknownOperation () {
103146 assertThatExceptionOfType (IllegalArgumentException .class )
104- .isThrownBy (() -> solver .solve ("What is 52 cubed?" ))
105- .withMessage ("I'm sorry, I don't understand the question!" );
147+ .isThrownBy (() -> solver .solve ("What is 52 cubed?" ))
148+ .withMessage ("I'm sorry, I don't understand the question!" );
106149 }
107150
108151 @ Disabled ("Remove to run test" )
109152 @ Test
153+ @ DisplayName ("Non math question" )
110154 public void testNonMathQuestion () {
111155 // See https://en.wikipedia.org/wiki/President_of_the_United_States if you really need to know!
112156 assertThatExceptionOfType (IllegalArgumentException .class )
113- .isThrownBy (() -> solver .solve ("Who is the President of the United States?" ))
114- .withMessage ("I'm sorry, I don't understand the question!" );
157+ .isThrownBy (() -> solver .solve ("Who is the President of the United States?" ))
158+ .withMessage ("I'm sorry, I don't understand the question!" );
115159 }
116160
117161 @ Disabled ("Remove to run test" )
118162 @ Test
163+ @ DisplayName ("reject problem missing an operand" )
119164 public void testMissingAnOperand () {
120165 assertThatExceptionOfType (IllegalArgumentException .class )
121- .isThrownBy (() -> solver .solve ("What is 1 plus?" ))
122- .withMessage ("I'm sorry, I don't understand the question!" );
166+ .isThrownBy (() -> solver .solve ("What is 1 plus?" ))
167+ .withMessage ("I'm sorry, I don't understand the question!" );
123168 }
124169
125170 @ Disabled ("Remove to run test" )
126171 @ Test
172+ @ DisplayName ("reject problem with no operands or operator" )
127173 public void testNoOperandsOrOperators () {
128174 assertThatExceptionOfType (IllegalArgumentException .class )
129- .isThrownBy (() -> solver .solve ("What is?" ))
130- .withMessage ("I'm sorry, I don't understand the question!" );
175+ .isThrownBy (() -> solver .solve ("What is?" ))
176+ .withMessage ("I'm sorry, I don't understand the question!" );
131177 }
132178
133179 @ Disabled ("Remove to run test" )
134180 @ Test
181+ @ DisplayName ("reject two operations in a row" )
135182 public void testTwoOperationsInARow () {
136183 assertThatExceptionOfType (IllegalArgumentException .class )
137184 .isThrownBy (() -> solver .solve ("What is 1 plus plus 2?" ))
@@ -140,6 +187,7 @@ public void testTwoOperationsInARow() {
140187
141188 @ Disabled ("Remove to run test" )
142189 @ Test
190+ @ DisplayName ("reject two numbers in a row" )
143191 public void testTwoNumbersAfterOperation () {
144192 assertThatExceptionOfType (IllegalArgumentException .class )
145193 .isThrownBy (() -> solver .solve ("What is 1 plus 2 1?" ))
@@ -148,6 +196,7 @@ public void testTwoNumbersAfterOperation() {
148196
149197 @ Disabled ("Remove to run test" )
150198 @ Test
199+ @ DisplayName ("reject postfix notation" )
151200 public void testPostfixNotation () {
152201 assertThatExceptionOfType (IllegalArgumentException .class )
153202 .isThrownBy (() -> solver .solve ("What is 1 2 plus?" ))
@@ -156,6 +205,7 @@ public void testPostfixNotation() {
156205
157206 @ Disabled ("Remove to run test" )
158207 @ Test
208+ @ DisplayName ("reject prefix notation" )
159209 public void testPrefixNotation () {
160210 assertThatExceptionOfType (IllegalArgumentException .class )
161211 .isThrownBy (() -> solver .solve ("What is plus 1 2?" ))
0 commit comments