當前位置: 首頁>>代碼示例>>Python>>正文


Python Calculator.sub方法代碼示例

本文整理匯總了Python中app.calculator.Calculator.sub方法的典型用法代碼示例。如果您正苦於以下問題:Python Calculator.sub方法的具體用法?Python Calculator.sub怎麽用?Python Calculator.sub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app.calculator.Calculator的用法示例。


在下文中一共展示了Calculator.sub方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TddInPythonExample

# 需要導入模塊: from app.calculator import Calculator [as 別名]
# 或者: from app.calculator.Calculator import sub [as 別名]
class TddInPythonExample(unittest.TestCase):

	def setUp(self):
		self.calc = Calculator()

	def test_calculator_add_method_returns_correct_result(self):
		result = self.calc.add(2,2)
		self.assertEqual(4, result)

	def test_calculator_returns_error_message_if_both_entries_are_not_numbers(self):
		self.assertRaises(ValueError, self.calc.add, 'two', 'three')
		self.assertRaises(TypeError, self.calc.sub, 'two', 'three')

	def test_calculator_returns_error_message_if_first_entry_is_not_number(self):
		self.assertRaises(ValueError, self.calc.add, 'two', 3)

	def test_calculator_returns_error_message_if_second_entry_is_not_number(self):
		self.assertRaises(ValueError, self.calc.add, 2, 'three')

	def test_calculator_subtract_method_returns_correct_result(self):
		result = self.calc.sub(4,7)
		self.assertEqual(-3,result)

	def test_calculator_multipy_method_returns_correct_result(self):
		result = self.calc.mult(2,3)
		self.assertEqual(6,result)

	def test_calculator_divide_method_returns_correct_result(self):
		result = self.calc.div(8,2)
		self.assertEqual(4,result)

	def test_calculator_factorial_method_returns_correct_result(self):
		result = self.calc.fact(5)
		self.assertEqual(120, result)
開發者ID:herlitzj,項目名稱:recommender,代碼行數:36,代碼來源:test_calculator.py

示例2: CalculatorTest

# 需要導入模塊: from app.calculator import Calculator [as 別名]
# 或者: from app.calculator.Calculator import sub [as 別名]
class CalculatorTest(unittest.TestCase):
    def setUp(self):
        self.calc = Calculator()

    def test_should_return_3_when_add_1_and_2(self):
        ret = self.calc.add(1, 2)
        self.assertEqual(3, ret)

    def test_should_throw_exception_when_no_numbers_passes(self):
        self.assertRaises(ValueError, self.calc.add, "1", 2)

    def test_should_return_1_when_sub_3_and_2(self):
        ret = self.calc.sub(3, 2)
        self.assertEqual(1, ret)
開發者ID:abruzzi,項目名稱:python-tdd-demo,代碼行數:16,代碼來源:test_calculator.py

示例3: TddInPyhton

# 需要導入模塊: from app.calculator import Calculator [as 別名]
# 或者: from app.calculator.Calculator import sub [as 別名]
class TddInPyhton(unittest.TestCase):
    def setUp(self):
        self.calc = Calculator()
        self.values = range(10)

    def test_add_method_return_correct_result(self):
        result = self.calc.add(2, 2)
        self.assertEqual(4, result)

    def test_sub_method_return_correct_result(self):
        result = self.calc.sub(4, 2)
        self.assertEqual(2, result)

    def test_multy_return_correct_result(self):
        result = self.calc.multy(2, 3)
        self.assertEqual(6, result)

    def test_divi_return_correct_result(self):
        result = self.calc.divi(6, 3)
        self.assertEqual(2, result)

    def test_isLegal_add_random(self):
        result = self.calc.isLegal("add")
        self.assertTrue(result)

    def test_isLegal_addSign_random(self):
        result = self.calc.isLegal("+")
        self.assertTrue(result)

    def test_isLegal_subSign_random(self):
        result = self.calc.isLegal("-")
        self.assertTrue(result)

    def test_isLegal_sub_true(self):
        result = self.calc.isLegal("sub")
        self.assertTrue(result)

    def test_isLegal_divi_true(self):
        result = self.calc.isLegal("divi")
        self.assertTrue(result)

    def test_isLegal_subSign_random(self):
        result = self.calc.isLegal("/")
        self.assertTrue(result)

    def test_isLegal_multy_true(self):
        result = self.calc.isLegal("multy")
        self.assertTrue(result)

    def test_isLegal_random_false(self):
        result = self.calc.isLegal("false")
        self.assertFalse(result)

    def test_divi_return_error_result(self):
        self.assertRaises(ValueError, self.calc.cantBeZero, 0)
        self.assertRaises(ValueError, self.calc.divi, 5, 0)

    def test_error_message(self):
        self.assertRaises(ValueError, self.calc.validateNumber, "two", "three")
        self.assertRaises(ValueError, self.calc.validateNumber, 1, "three")
        self.assertRaises(ValueError, self.calc.validateNumber, "1", "three")
        self.assertRaises(ValueError, self.calc.validateNumber, "1", "6")

    def test_none_error_message(self):
        try:
            self.calc.validateNumber(2, 3)
            self.calc.validateNumber(0, 3)
            self.calc.validateNumber(0, 0)
        except ValueError:
            self.fail("validateNumber() raised ValueError unexpectedly!")
開發者ID:phsh,項目名稱:potential-computing-machine,代碼行數:72,代碼來源:test_calculator.py


注:本文中的app.calculator.Calculator.sub方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。