本文整理汇总了Python中wordy.calculate函数的典型用法代码示例。如果您正苦于以下问题:Python calculate函数的具体用法?Python calculate怎么用?Python calculate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了calculate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subtract_twice
def test_subtract_twice(self):
self.assertEqual(-7, calculate("What is 20 minus 14 minus 13?"))
示例2: test_multiply_twice
def test_multiply_twice(self):
self.assertEqual(-12, calculate("What is 2 multiplied by -2 multiplied by 3?"))
示例3: test_add_twice
def test_add_twice(self):
self.assertEqual(4, calculate("What is 1 plus 2 plus 1?"))
示例4: test_add_then_subtract
def test_add_then_subtract(self):
self.assertEqual(14, calculate("What is 1 plus 5 minus -8?"))
示例5: test_invalid_operation
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')
示例6: test_add_more_digits
def test_add_more_digits(self):
self.assertEqual(45801, calculate("What is 123 plus 45678?"))
示例7: test_simple_mult
def test_simple_mult(self):
self.assertEqual(21, calculate("What is 7 multiplied by 3?"))
示例8: test_simple_add_1
def test_simple_add_1(self):
self.assertEqual(18, calculate("What is 5 plus 13?"))
示例9: test_simple_sub_1
def test_simple_sub_1(self):
self.assertEqual(6, calculate("What is 103 minus 97?"))
示例10: test_simple_sub_2
def test_simple_sub_2(self):
self.assertEqual(-6, calculate("What is 97 minus 103?"))
示例11: test_irrelevant_question
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')
示例12: test_missing_number
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')
示例13: test_missing_operation
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')
示例14: test_add_then_multiply
def test_add_then_multiply(self):
self.assertEqual(-8, calculate("What is -3 plus 7 multiplied by -2?"))
示例15: test_simple_div
def test_simple_div(self):
self.assertEqual(9, calculate("What is 45 divided by 5?"))