def test_calculator_add_method_returns_correct_result(self): """ Method to test add function from calculator.py """ calc = Calculator() result = calc.add(2, 2) self.assertEqual(4, result)
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)
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)
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) } )
def min_max_for_all(): """Logic for sending min/max mail""" config = get_config() for recipient in config['recipients']: for transaction in recipient['transactions']: print('\n' + '-' * 50 + '\n') sv = StockValue(symbol=transaction['symbol'], config=config) bankier = sv.get_bankier() current_value, bankier_time = sv.get_values(bankier) hm = HistoryManager() global_min = hm.get_min(transaction['symbol'], recipient['address']) global_max = hm.get_max(transaction['symbol'], recipient['address']) calculator = Calculator(transaction['buy_quantity'], transaction['buy_price'], transaction['buy_quantity'], current_value) if transaction['min_max_mail'] == 'yes': prepare_min_max_email(recipient['address'], transaction['symbol'], current_value, global_min, global_max, config, calculator) hm.update_history(current_value, transaction['symbol'], recipient['address'], bankier_time, now())
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)
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")
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_error_message_if_both_args_not_numbers(self): self.assertRaises(ValueError, self.calc.add, 'two', 'three')
class Test_Calculator(unittest.TestCase): def setUp(self): self.calc = Calculator() def test_add_returns_correct_result(self): """Simple, make an instance of the app and test that 2+2=4""" 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')
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)
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)
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)
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')
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')
def test_calculator(quantity, price_per_item, state, discount, price_with_discount, tax, state_tax, final_price) -> None: price_per_item = Decimal(price_per_item) expected_calculation = Calculation( quantity=quantity, price_per_item=price_per_item, state=state, discount=discount, price_with_discount=price_with_discount, tax=tax, state_tax=state_tax, final_price=final_price, ) calculation = Calculator(quantity=quantity, price_per_item=price_per_item, state=state).execute() assert expected_calculation == calculation
def regular_for_all(): config = get_config() print("dupes") for recipient in config['recipients']: if recipient['daily_mail'].lower() == 'yes': stocks_to_send = {} calculators = [] for transaction in recipient['transactions']: sv = StockValue(symbol=transaction['symbol'], config=config) bankier = sv.get_bankier() current_value, bankier_time = sv.get_values(bankier) stocks_to_send[transaction['symbol']] = current_value calculators.append( Calculator(transaction['buy_quantity'], transaction['buy_price'], transaction['buy_quantity'], current_value)) prepare_daily_email(recipient['address'], stocks_to_send, calculators, config)
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
class CalculatorTest(unittest.TestCase): def setUp(self): """ Create a instance to class Calculator """ self.calc = Calculator() def test_calculate_iva(self): result = self.calc.get_iva(100) self.assertEqual(result, 16) result2 = self.calc.get_iva(200) #32 self.assertEqual(result2, 32) result3 = self.calc.get_iva(500) #32 self.assertEqual(result3, 80) result3 = self.calc.get_iva(1000) #32 self.assertEqual(result3, 160) def test_calculate_iva_with_different_rate(self): result = self.calc.get_iva(200, rate=.20) self.assertEqual(result, 40) def test_calculate_interest(self): """PRUEBA UNA FUCNION QUE CALCULA EL INTERÉS, RECIBIENDO MONTO INCIAL, TASA DE INTERÉS Y PERIODOS (INTERÉS SIMPLE) IS = (MI*IR)*N """ result = self.calc.get_interest(100, .10, 10) self.assertEqual(result, 100) def test_calculate_compound_interest(): result = self.calc.get_interest(1000, .10, 10, compound=True) self.asserAlmostEqual(result, 100) """ def test_calculate_invertion(): result = self.calc.get_invertion(1000,.10,500,2) self.asserAlmostEqual(result,)""" """
class TddPythonExample(unittest.TestCase): """The Test Class.""" def setUp(self): """The setUp Method put things in place before each test case.""" self.calc = Calculator() def test_calculator_add_method_returns_correct_result(self): """Test For Add Method.""" result = self.calc.add(2, 2) self.assertEqual(4, result) def test_calculator_returns_error_if_both_args_not_numbers(self): """Test that raises ValueError when Strings are passed in.""" self.assertRaises(ValueError, self.calc.add, 'two', 'three') def test_calculator_returns_error_message_if_x_arg_not_number(self): """Test that raises ValueError when x arg isn't a number.""" self.assertRaises(ValueError, self.calc.add, 'two', 3) def test_calculator_returns_error_message_if_y_arg_not_number(self): """Test that raises ValueError when y arg isn't a number.""" self.assertRaises(ValueError, self.calc.add, 2, 'three')
class TestCalc: def setup(self): self.calc = Calculator() def test_multiply_correct(self): assert self.calc.multiply(10, 2) == 20 def test_division_correct(self): assert self.calc.division(10, 2) == 5.0 with pytest.raises(ZeroDivisionError) as zero_division: self.calc.division(10, 0) def test_subtraction_correct(self): assert self.calc.subtraction(100, 18) == 82 def test_adding_correct(self): assert self.calc.adding(30, 11) == 41
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')
def setUp(self): # Package initiation self.calc = Calculator()
def test_calculator_division_method_returns_correct_result(self): calc = Calculator() result = calc.division(5,2) self.assertEqual(2.5, result)
def test_calculator_subtraction_method_returns_correct_result(self): calc = Calculator() result = calc.substraction(4,2) self.assertEqual(2, result)
def test_calculator_addition_method_returns_correct_result(self): calc = Calculator() result = calc.addition(2,2) self.assertEqual(4, result)
def setUp(self): self.calc = 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
def setUp(self): # setUp() and tearDown() defined in unittest self.calc = Calculator()
def setUp(self): self.event = Event(pk=1) self.calculator = Calculator(self.event)
def test_add(self): calc = Calculator() result = calc.add(2,2) self.assertEqual(4, result)
def test_divide(self): calc = Calculator() result = calc.divide(4,2) self.assertEqual(2, result)
def test_multiply_by_zero(self): calc = Calculator() result = calc.multiply(4,0) self.assertEqual(0, result)
def test_multiply(self): calc = Calculator() result = calc.multiply(4,2) self.assertEqual(8, result)
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!")
def setUp(self): self.calc = Calculator() self.values = range(10)
#!/usr/bin/env python import sys import fileinput from app.calculator import Calculator calcu = Calculator() firstNumber = 0 secondNumber = 2 command = 1 tripleCommand = [] for compleatLine in fileinput.input(): for commandParts in compleatLine.rstrip().split(): tripleCommand.append(commandParts) result = "'" + str(tripleCommand[command]) + "' no such method supported. \n" + str(calcu.legal()) if tripleCommand[command] in calcu.legal(): result = getattr( calcu,tripleCommand[command])(int(tripleCommand[firstNumber]), int(tripleCommand[secondNumber]) ) print result
def test_subtract(self): calc = Calculator() result = calc.subtract(4,2) self.assertEqual(2, result)