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


Python calculator.Calculator類代碼示例

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


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

示例1: TddInPythonExample

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,代碼行數:34,代碼來源:test_calculator.py

示例2: CalculatorTest

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,代碼行數:14,代碼來源:test_calculator.py

示例3: get

 def get(self, request):
     participant = Participant.objects.get(
         Q(email=request.user.username) | Q(email=request.user.email)
     )
     event = participant.event.select_related()[0]
     calculator = Calculator(event)
     return Response(
         status.HTTP_200_OK,
         {
             "event"            : event,
             "participant"      : participant,
             "amount"           : calculator.amount(),
             "participantAmount": calculator.participantAmount(participant)
         }
     )
開發者ID:nvahlas,項目名稱:short-debts-make-long-friends,代碼行數:15,代碼來源:views.py

示例4: CalculatorTest

class CalculatorTest(unittest.TestCase):
    def setUp(self):
        self.event = Event(pk=1)
        self.calculator = Calculator(self.event)
    
    def testAmount(self):
        self.assertEqual(self.calculator.amount(), 100)
開發者ID:nvahlas,項目名稱:short-debts-make-long-friends,代碼行數:7,代碼來源:tests.py

示例5: sut

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,代碼行數:10,代碼來源:test_calculator.py

示例6: TestCalculator

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,代碼行數:14,代碼來源:test_calculator.py

示例7: TddInPythonExample

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,代碼行數:24,代碼來源:test_calculator.py

示例8: TddInPythonExample

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,代碼行數:16,代碼來源:test_calculator_refactor_1.py

示例9: TddInPythonExample

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,代碼行數:17,代碼來源:test_calculator.py

示例10: TestCalculator

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,代碼行數:20,代碼來源:test_calculator.py

示例11: TddInPythonExample

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,代碼行數:24,代碼來源:test_calculator.py

示例12: Calculator

#!/usr/bin/env python
import sys
from app.calculator import Calculator

calc = Calculator()
lista = sys.argv
result = "'" + str(sys.argv[2]) + "' no such method supported. \n" + str(calc.legal())
if sys.argv[2] in calc.legal():
	modifier = sys.argv[2]
	if len( sys.argv[2] ) == 1:
		modifier = calc.character(sys.argv[2])		
	result = getattr(calc,modifier)(int(sys.argv[1]), int(sys.argv[3]) )
print result
開發者ID:phsh,項目名稱:potential-computing-machine,代碼行數:13,代碼來源:calculate.py

示例13: setUp

 def setUp(self):
     self.event = Event(pk=1)
     self.calculator = Calculator(self.event)
開發者ID:nvahlas,項目名稱:short-debts-make-long-friends,代碼行數:3,代碼來源:tests.py

示例14: setUp

	def setUp(self):	# Package initiation
		self.calc = Calculator()
開發者ID:NurFaizin,項目名稱:SDP,代碼行數:2,代碼來源:test_calculator.py

示例15: test_calculator_division_method_returns_correct_result

 def test_calculator_division_method_returns_correct_result(self):
     calc = Calculator()
     result = calc.division(5,2)
     self.assertEqual(2.5, result)
開發者ID:kamaxeon,項目名稱:fap,代碼行數:4,代碼來源:test_calculator.py


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