class SubTestCases(unittest.TestCase): def setUp(self): """ Создать опрос и проверить его методы """ self.calc = Calculator(0, 0) def test_sub_positive(self): self.assertEqual(self.calc.sub(20, 2), 18) def test_sub_negative_one(self): self.assertEqual(self.calc.sub(0, -29999), 29999) def test_sub_negative_both(self): self.assertEqual(self.calc.sub(-150000, -29999), -120001) def test_sub_empty_string(self): self.assertRaises(TypeError, self.calc.sub, -150000, '') def test_sub_one_string_param(self): self.assertRaises(TypeError, self.calc.sub, 1500, 'fd') def test_sum_both_strings(self): self.assertRaises(TypeError, self.calc.sub, 'ab', 'fd') def test_sum_large_numbers(self): self.assertEqual( self.calc.sub( 99999999999999900009999999999999999999990000999999, 9999999999999990000999999999999999999999000099999999999999999999900009999999999999999999990000999999 ), -9999999999999990000999999999999999999999000099999900000000000000000000000000000000000000000000000000 )
def test_Calculator(self): # Arrange calculator = Calculator() output = {'sum': 7} input = {'num1': 2, 'num2': 5} # Act result = calculator.post(input) # Assert self.assertEqual(output, result)
class CalcTesting(unittest.TestCase): """ Tests for Calculator """ def setUp(self): x = str(1) y = str(2) self.my_calculation = Calculator(x, y) def test_number_input_testing(self): self.assertEqual(self.my_calculation.addition(), 3) def test_text_input_testing(self): self.assertFalse(self.my_calculation.verif_numb("sfsd")) def test_epmty_input_testing(self): self.assertTrue(self.my_calculation.verif_numb("2"))
class TestCalculator(unittest.TestCase): def setUp(self): print("SETUP") self.calculator = Calculator() def test_add(self): print("test_add") result = self.calculator.add(4, 5) self.assertEqual(9, result) def test_subtract(self): print("test_subtract") result = self.calculator.subtract(9, 3) self.assertEqual(6, result) def tearDown(self): print("TEAR DOWN")
class SumTestCases(unittest.TestCase): def setUp(self): """ Создание экземпляра класса Calculator """ self.calc = Calculator(0, 0) def test_get_param(self): '''Валидация int input происходит в методе get_param тест проверяет мок на валидных данных, но не может проверить мок на ошибочных - будет зацикливание, таков мой код ''' with unittest.mock.patch('builtins.input', return_value=2): self.assertEqual(self.calc.get_params("first"), 2) def test_sum_positive(self): self.assertEqual(self.calc.sum(1, 2), 3) def test_sum_negative_one(self): self.assertEqual(self.calc.sum(0, -29999), -29999) def test_sum_negative_both(self): self.assertEqual(self.calc.sum(-150000, -29999), -179999) def test_sum_empty_string(self): self.assertRaises(TypeError, sum, -150000, '') def test_sum_one_string_param(self): self.assertRaises(TypeError, self.calc.sum, 1500, 'fd') def test_sum_both_strings(self): self.assertRaises(TypeError, sum, 'ab', 'fd') def test_sum_large_numbers(self): self.assertEqual( self.calc.sum( 99999999999999900009999999999999999999990000999999, 9999999999999990000999999999999999999999000099999999999999999999900009999999999999999999990000999999 ), 9999999999999990000999999999999999999999000100000099999999999999800019999999999999999999980001999998 )
class UnitTest(unittest.TestCase): calc = Calculator() def test_one(self): result = UnitTest.calc.add(1, 3) self.assertEqual(result, 4, "Summation Is Failed") def test_two(self): result = UnitTest.calc.subtract(1, 3) self.assertEqual(result, -2, "Subtraction Is Failed") def test_three(self): result = UnitTest.calc.mul(1, 3) self.assertEqual(result, 3, "Multiplication Is Failed")
class TestCalculator(unittest.TestCase): @classmethod def setUpClass(self): print('Set up class') # Create an instance of the calculator that can be used in all tests @classmethod def tearDownClass(self): print('Tear down class') global C C = Calculator() def test_add(self): self.assertEqual(C.add(2, 7), 9) self.assertEqual(C.add(2, 7.5), 9.5) self.assertEqual(C.add(-2, 7), 5) def test_subtract(self): self.assertEqual(C.subtract(7, 2), 5) self.assertEqual(C.subtract(7.5, 2), 5.5) self.assertEqual(C.subtract(-7, 2), -9) # Write test methods for subtract, multiply, and divide def test_multiply(self): self.assertEqual(C.multiply(2, 2), 4) self.assertEqual(C.multiply(2, 2.5), 5) self.assertEqual(C.multiply(-2, 2.5), -5) def test_divide(self): self.assertEqual(C.divide(4, 2), 2) self.assertEqual(C.divide(4.5, 2), 2.25) self.assertEqual(C.divide(-4.5, 2), -2.25)
class DivTestCases(unittest.TestCase): def setUp(self): """ Создать опрос и проверить его методы """ self.calc = Calculator(0, 0) def test_div_positive(self): self.assertEqual(self.calc.div(20, 2), 10) def test_div_negative_one(self): self.assertEqual(self.calc.div(15, -5), -3) def test_div_negative_both(self): self.assertEqual(self.calc.div(-15, -5), 3) def test_div_first_zero_param(self): self.assertEqual(self.calc.div(0, -3), 0) def test_div_empty_string(self): self.assertRaises(TypeError, self.calc.div, -150000, '') def test_div_one_string_param(self): self.assertRaises(TypeError, self.calc.div, 1500, 'fd') def test_div_both_strings(self): self.assertRaises(TypeError, self.calc.div, 'ab', 'fd') def test_div_one_zero_param(self): self.assertEqual(self.calc.div(10, 0), 'На ноль делить нельзя ') def test_mul_large_numbers(self): self.assertEqual( self.calc.div( 99999999999999900009999999999999999999990000999999, 9999999999999990000999999999999999999999000099999999999999999999900009999999999999999999990000999999 ), 1e-50)
class MulTestCases(unittest.TestCase): def setUp(self): """ Создать опрос и проверить его методы """ self.calc = Calculator(0, 0) def test_mul_positive(self): self.assertEqual(self.calc.mul(20, 2), 40) def test_mul_negative_one(self): self.assertEqual(self.calc.mul(1, -29999), -29999) def test_mul_negative_both(self): self.assertEqual(self.calc.mul(-150, -299), 44850) def test_mul_zero_param(self): self.assertEqual(self.calc.mul(-150, 0), 0) def test_mul_both_zero_param(self): self.assertEqual(self.calc.mul(0, 0), 0) def test_mul_empty_string(self): self.assertRaises(ValueError, self.calc.mul, -150000, '') def test_mul_one_string_param(self): self.assertRaises(ValueError, self.calc.mul, 1500, 'fd') def test_mul_both_strings(self): self.assertRaises(ValueError, self.calc.mul, 'ab', 'fd') def test_mul_large_numbers(self): self.assertEqual( self.calc.sub( 99999999999999900009999999999999999999990000999999, 99999999999999900009999999999000099999999990000999999), -99899999999999900109989999999000100000000000000000000)
def test_Calculator_with_none(self): calculator = Calculator() input = {'num1': None, 'num2': None} with self.assertRaises(TypeError): calculator.post(input)
def test_Calculator_with_float(self): calculator = Calculator() output = {'sum': 7} input = {'num1': 3.5, 'num2': 3.5} result = calculator.post(input) self.assertEqual(output, result)
def test_Calculator_with_strings(self): calculator = Calculator() output = {'sum': '52'} input = {'num1': "5", 'num2': "2"} result = calculator.post(input) self.assertEqual(output, result)
param_b = 0 answer = 0 while answer not in range(1, 5): print( """ Выберите математическую операцию для выполнения: 1 - сложение 2 - вычитание 3 - умножение 4 - деление """ ) try: answer = int(input("Ваш выбор: ")) except ValueError: print("Выберите операцию из значений ниже") Calc = Calculator(param_a, param_b) param_a = Calc.get_params('first') param_b = Calc.get_params('second') if answer == 1: print(Calc.sum(param_a, param_b)) elif answer == 2: print(Calc.sub(param_a, param_b)) elif answer == 3: print(Calc.mul(param_a, param_b)) else: print(Calc.div(param_a, param_b))
def setUp(self): """ Создание экземпляра класса Calculator """ self.calc = Calculator(0, 0)
def setUp(self): """ Создать опрос и проверить его методы """ self.calc = Calculator(0, 0)
def setUp(self): print("SETUP") self.calculator = Calculator()
def setUp(self): x = str(1) y = str(2) self.my_calculation = Calculator(x, y)