33from wordy import calculate
44
55
6+ # Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
7+
68class WordyTest (unittest .TestCase ):
7- def test_simple_add_1 (self ):
8- self .assertEqual (calculate ("What is 5 plus 13 ?" ), 18 )
9+ def test_addition (self ):
10+ self .assertEqual (calculate ("What is 1 plus 1 ?" ), 2 )
911
10- def test_simple_add_2 (self ):
11- self .assertEqual (calculate ("What is 5 plus -13 ?" ), - 8 )
12+ def test_more_addition (self ):
13+ self .assertEqual (calculate ("What is 53 plus 2 ?" ), 55 )
1214
13- def test_simple_sub_1 (self ):
14- self .assertEqual (calculate ("What is 103 minus 97 ?" ), 6 )
15+ def test_addition_with_negative_numbers (self ):
16+ self .assertEqual (calculate ("What is -1 plus -10 ?" ), - 11 )
1517
16- def test_simple_sub_2 (self ):
17- self .assertEqual (calculate ("What is 97 minus 103 ?" ), - 6 )
18+ def test_large_addition (self ):
19+ self .assertEqual (calculate ("What is 123 plus 45678 ?" ), 45801 )
1820
19- def test_simple_mult (self ):
20- self .assertEqual (calculate ("What is 7 multiplied by 3 ?" ), 21 )
21+ def test_subtraction (self ):
22+ self .assertEqual (calculate ("What is 4 minus -12 ?" ), 16 )
2123
22- def test_simple_div (self ):
23- self .assertEqual (calculate ("What is 45 divided by 5 ?" ), 9 )
24+ def test_multiplication (self ):
25+ self .assertEqual (calculate ("What is -3 multiplied by 25 ?" ), - 75 )
2426
25- def test_add_negative_numbers (self ):
26- self .assertEqual (calculate ("What is -1 plus -10 ?" ), - 11 )
27+ def test_division (self ):
28+ self .assertEqual (calculate ("What is 33 divided by -3 ?" ), - 11 )
2729
28- def test_add_more_digits (self ):
29- self .assertEqual (calculate ("What is 123 plus 45678 ?" ), 45801 )
30+ def test_multiple_addition (self ):
31+ self .assertEqual (calculate ("What is 1 plus 1 plus 1 ?" ), 3 )
3032
31- def test_add_twice (self ):
32- self .assertEqual (calculate ("What is 1 plus 2 plus 1 ?" ), 4 )
33+ def test_addition_then_subtraction (self ):
34+ self .assertEqual (calculate ("What is 1 plus 5 minus -2 ?" ), 8 )
3335
34- def test_add_then_subtract (self ):
35- self .assertEqual (calculate ("What is 1 plus 5 minus -8 ?" ), 14 )
36+ def test_multiple_subtraction (self ):
37+ self .assertEqual (calculate ("What is 20 minus 4 minus 13 ?" ), 3 )
3638
37- def test_subtract_twice (self ):
38- self .assertEqual (calculate ("What is 20 minus 14 minus 13 ?" ), - 7 )
39+ def test_subtraction_then_addition (self ):
40+ self .assertEqual (calculate ("What is 17 minus 6 plus 3 ?" ), 14 )
3941
40- def test_multiply_twice (self ):
42+ def test_multiple_multiplication (self ):
4143 self .assertEqual (
4244 calculate ("What is 2 multiplied by -2 multiplied by 3?" ), - 12 )
4345
44- def test_add_then_multiply (self ):
46+ def test_addition_then_multiplication (self ):
4547 self .assertEqual (calculate ("What is -3 plus 7 multiplied by -2?" ), - 8 )
4648
47- def test_divide_twice (self ):
49+ def test_multiple_division (self ):
4850 self .assertEqual (
49- calculate ("What is -12000 divided by 25 divided by -30 ?" ), 16 )
51+ calculate ("What is -12 divided by 2 divided by -3 ?" ), 2 )
5052
51- def test_invalid_operation (self ):
53+ def test_unknown_operation (self ):
5254 with self .assertRaises (ValueError ):
53- calculate ("What is 4 xor 7?" )
55+ calculate ("What is 52 cubed?" )
56+
57+ def test_non_math_question (self ):
58+ with self .assertRaises (ValueError ):
59+ calculate ("Who is the President of the United States?" )
60+
61+ # Additional tests for this track
5462
5563 def test_missing_operation (self ):
5664 with self .assertRaises (ValueError ):
@@ -60,10 +68,6 @@ def test_missing_number(self):
6068 with self .assertRaises (ValueError ):
6169 calculate ("What is 7 plus multiplied by -2?" )
6270
63- def test_irrelevant_question (self ):
64- with self .assertRaises (ValueError ):
65- calculate ("Which is greater, 3 or 2?" )
66-
6771
6872if __name__ == '__main__' :
6973 unittest .main ()
0 commit comments