当前位置: 首页>>代码示例>>Python>>正文


Python Calculator.add方法代码示例

本文整理汇总了Python中app.calculator.Calculator.add方法的典型用法代码示例。如果您正苦于以下问题:Python Calculator.add方法的具体用法?Python Calculator.add怎么用?Python Calculator.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.calculator.Calculator的用法示例。


在下文中一共展示了Calculator.add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TddInPythonExample

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [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: sut

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
class sut(unittest.TestCase):
    def setUp(self):
        self.calc = Calculator()

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

    def test_add_returns_error_if_args_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, "two", "three")
开发者ID:walkerrandolphsmith,项目名称:pycalc,代码行数:12,代码来源:test_calculator.py

示例3: CalculatorTest

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [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

示例4: TestCalculator

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
class TestCalculator(unittest.TestCase):

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

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

    def test_calculator_add_method_returns_error_if_args_are_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, "two", "three")

    def test_calculator_add_method_returns_error_if_one_arg_is_not_number(self):
        self.assertRaises(ValueError, self.calc.add, 'a', 1.2)
开发者ID:MijkeXomnia,项目名称:python_tutorial,代码行数:16,代码来源:test_calculator.py

示例5: TddInPythonExample

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
class TddInPythonExample(unittest.TestCase):
    def setUp(self):
        self.calc = Calculator()

    def test_calculator_add_method_returns_correct_result(self):
        result = self.calc.add(a+a,b)
        self.assertEqual(somme+a, result)
        
    def test_calculator_add_method_returns_correct_result2(self):
        result = self.calc.add(a,b)
        self.assertEqual(somme, result,"{!r} + {!r} ne font pas {!r}".format(a,b,result))    
        
    def test_calculator_add_method_returns_false(self):
        result = self.calc.add(a,b)
        self.assertNotEquals(sommeKo, result,"ca ne doit pas etre pareil")
            
    def test_calculator_returns_error_message_if_both_args_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, e, f)
    
    def test_calculator_returns_error_message_if_first_args_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, e, a)
        
    def test_calculator_returns_error_message_if_second_args_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, b, f)       
开发者ID:fcarluer,项目名称:workspace,代码行数:26,代码来源:test_calculator.py

示例6: TddInPythonExample

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [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_args_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, 'two', 'three')

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

    def test_calculator_returns_error_message_if_y_arg_not_number(self):
        self.assertRaises(ValueError, self.calc.add, 2, 'three')
开发者ID:ralphreid,项目名称:SANDBOX,代码行数:18,代码来源:test_calculator_refactor_1.py

示例7: TddInPythonExample

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
class TddInPythonExample(unittest.TestCase):

    def setUp(self):        # setUp() and tearDown() defined in unittest
        self.calc = Calculator()

    def test_calculator_add_method_returns_correct_result(self):
        result = self.calc.add(2, 2) # must be self.x otherwise not found
        self.assertEqual(4, result)

    def test_calculator_returns_error_message_if_both_args_not_numbers(self):
        self.assertRaises(ValueError, self.calc.add, 'two', 'three')

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

    def test_error_if_y_not_number(self):
        self.assertRaises(ValueError, self.calc.add, 2, 'three')
开发者ID:drkvogel,项目名称:2degrees,代码行数:19,代码来源:test_calculator.py

示例8: TestCalculator

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
class TestCalculator(unittest.TestCase):

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

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

    def test_calculator_string_error(self):
        self.assertRaises(ValueError, self.calc.add, 'two', 'three')

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

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

    def tearDown(self):
        pass
开发者ID:brennv,项目名称:bb,代码行数:22,代码来源:test_calculator.py

示例9: TddInPythonExample

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
class TddInPythonExample(unittest.TestCase):
	"""docstring for TddInPythonExample"""

	def setUp(self):	# Package initiation
		self.calc = Calculator()

	# def tearDown(self):
	# 	pass

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

	def test_calculator_returns_error_message_if_both_args_not_numbers(self):
		self.assertRaises(ValueError, self.calc.add, 'two', 'three')


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


	def test_calculator_returns_error_message_if_y_arg_not_numbers(self):
		self.assertRaises(ValueError, self.calc.add, 2, 'three')
开发者ID:NurFaizin,项目名称:SDP,代码行数:26,代码来源:test_calculator.py

示例10: test_calculator_add_method_returns_correct_result

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
 def test_calculator_add_method_returns_correct_result(self):
     calc = Calculator()
     result = calc.add(2,2)
     self.assertEqual(4, result)
开发者ID:sundarrajanm,项目名称:learning,代码行数:6,代码来源:test_calculator.py

示例11: TddInPyhton

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [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

示例12: test_add

# 需要导入模块: from app.calculator import Calculator [as 别名]
# 或者: from app.calculator.Calculator import add [as 别名]
 def test_add(self):
     calc = Calculator()
     result = calc.add(2,2)
     self.assertEqual(4, result)
开发者ID:DevSKiller,项目名称:devskiller-sample-python-calculator,代码行数:6,代码来源:test_verify_calculator.py


注:本文中的app.calculator.Calculator.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。