예제 #1
0
 def test_simple_sub_1(self):
     self.assertEqual(6, calculate("What is 103 minus 97?"))
예제 #2
0
 def test_simple_mult(self):
     self.assertEqual(21, calculate("What is 7 multiplied by 3?"))
예제 #3
0
 def test_invalid_operation(self):
     with self.assertRaises(ValueError) as context:
         calculate("What is 4 xor 7?")
     self.assertEqual(context.exception.message, 'Ill-formed question')
예제 #4
0
 def test_missing_number(self):
     with self.assertRaises(ValueError) as context:
         calculate("What is 7 plus times -2?")
     self.assertEqual(context.exception.message, 'Ill-formed question')
예제 #5
0
 def test_simple_add_1(self):
     self.assertEqual(18, calculate("What is 5 plus 13?"))
예제 #6
0
 def test_reject_prefix_notation(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate('What is plus 1 2?')
예제 #7
0
 def test_division(self):
     self.assertEqual(calculate("What is 33 divided by -3?"), -11)
예제 #8
0
 def test_subtract_twice(self):
     self.assertEqual(-7, calculate("What is 20 minus 14 minus 13?"))
예제 #9
0
 def test_subtraction(self):
     self.assertEqual(calculate("What is 4 minus -12?"), 16)
예제 #10
0
 def test_multiplication(self):
     self.assertEqual(calculate("What is -3 multiplied by 25?"), -75)
예제 #11
0
 def test_large_addition(self):
     self.assertEqual(calculate("What is 123 plus 45678?"), 45801)
예제 #12
0
 def test_addition_with_negative_numbers(self):
     self.assertEqual(calculate("What is -1 plus -10?"), -11)
예제 #13
0
 def test_more_addition(self):
     self.assertEqual(calculate("What is 53 plus 2?"), 55)
예제 #14
0
 def test_add_negative_numbers(self):
     self.assertEqual(-11, calculate("What is -1 plus -10?"))
예제 #15
0
 def test_multiple_addition(self):
     self.assertEqual(calculate("What is 1 plus 1 plus 1?"), 3)
예제 #16
0
 def test_add_twice(self):
     self.assertEqual(4, calculate("What is 1 plus 2 plus 1?"))
예제 #17
0
 def test_addition_then_subtraction(self):
     self.assertEqual(calculate("What is 1 plus 5 minus -2?"), 8)
예제 #18
0
 def test_add_then_multiply(self):
     self.assertEqual(-8, calculate("What is -3 plus 7 multiplied by -2?"))
예제 #19
0
 def test_multiple_subtraction(self):
     self.assertEqual(calculate("What is 20 minus 4 minus 13?"), 3)
예제 #20
0
 def test_missing_number(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate("What is 7 plus multiplied by -2?")
예제 #21
0
 def test_subtraction_then_addition(self):
     self.assertEqual(calculate("What is 17 minus 6 plus 3?"), 14)
예제 #22
0
 def test_simple_mult(self):
     self.assertEqual(21, calculate("What is 7 times 3?"))
예제 #23
0
 def test_multiple_multiplication(self):
     self.assertEqual(
         calculate("What is 2 multiplied by -2 multiplied by 3?"), -12)
예제 #24
0
 def test_missing_operation(self):
     with self.assertRaises(ValueError) as context:
         calculate("What is 2 2 minus 3?")
     self.assertEqual(context.exception.message, 'Ill-formed question')
예제 #25
0
 def test_addition_then_multiplication(self):
     self.assertEqual(calculate("What is -3 plus 7 multiplied by -2?"), -8)
예제 #26
0
 def test_irrelevant_question(self):
     with self.assertRaises(ValueError) as context:
         calculate("Which is greater, 3 or 2?")
     self.assertEqual(context.exception.message, 'Ill-formed question')
예제 #27
0
 def test_multiple_division(self):
     self.assertEqual(calculate("What is -12 divided by 2 divided by -3?"),
                      2)
예제 #28
0
 def test_simple_sub_2(self):
     self.assertEqual(-6, calculate("What is 97 minus 103?"))
예제 #29
0
 def test_unknown_operation(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate("What is 52 cubed?")
예제 #30
0
 def test_simple_div(self):
     self.assertEqual(9, calculate("What is 45 divided by 5?"))
예제 #31
0
 def test_non_math_question(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate("Who is the President of the United States?")
예제 #32
0
 def test_add_more_digits(self):
     self.assertEqual(45801, calculate("What is 123 plus 45678?"))
예제 #33
0
 def test_reject_problem_missing_an_operand(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate('What is 1 plus?')
예제 #34
0
 def test_add_then_subtract(self):
     self.assertEqual(14, calculate("What is 1 plus 5 minus -8?"))
예제 #35
0
 def test_reject_problem_with_no_operands_or_operators(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate('What is?')
예제 #36
0
 def test_multiply_twice(self):
     self.assertEqual(-12, calculate("What is 2 multiplied by -2 multiplied by 3?"))
예제 #37
0
 def test_reject_two_numbers_in_a_row(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate('What is 1 plus 2 1?')
예제 #38
0
 def test_divide_twice(self):
     self.assertEqual(16, calculate("What is -12000 divided by 25 divided by -30?"))
예제 #39
0
 def test_just_a_number(self):
     self.assertEqual(calculate('What is 5?'), 5)
예제 #40
0
 def test_simple_add_2(self):
     self.assertEqual(-8, calculate("What is 5 plus -13?"))
예제 #41
0
 def test_missing_operation(self):
     with self.assertRaisesWithMessage(ValueError):
         calculate("What is 2 2 minus 3?")