class CalculatorTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_result_is_zero_calculator(self): self.assertEqual(self.calculator.result, 0) def test_addition(self): file = Reader("testCases/Addition.csv").content print("TEST ADDITION\n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.add(row[0], row[1]), float(row[2])) self.assertEqual(self.calculator.result, result) def test_subtraction(self): file = Reader("testCases/Subtraction.csv").content print("TESTING SUBTRACTION\n") for row in file: self.assertEqual(self.calculator.subtract(row[0], row[1]), float(row[2])) def test_multiplication(self): file = Reader("testCases/Multiplication.csv").content print("TESTING MULTIPLICATION\n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.multiply(row[0], row[1]), float(row[2])) def test_division(self): file = Reader("testCases/Division.csv").content print("TEST DIVISION\n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.divide(row[0], row[1]), float(row[2])) def test_square(self): file = Reader("testCases/Square.csv").content print("TEST SQUARE\n") for row in file: result = float(row[1]) self.assertEqual(self.calculator.square(row[0]), float(row[1])) self.assertEqual(self.calculator.result, result) def test_square_root(self): file = Reader("testCases/SquareRoot.csv").content print("TEST SQUARE ROOT\n") for row in file: result = float(row[1]) self.assertAlmostEqual(self.calculator.square_root(row[0]), float(row[1])) self.assertAlmostEqual(self.calculator.result, result)
class CalculatorTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_addition(self): test_data = CsvReader("../tests/Data/Unit Test Addition.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_subtraction(self): test_data = CsvReader("../tests/Data/Unit Test Subtraction.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.sub(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_multiplication(self): test_data = CsvReader( "../tests/Data/Unit Test Multiplication.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.mult(row['Value 1'], row['Value 2']), result) def test_division(self): test_data = CsvReader("../tests/Data/Unit Test Division.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.divi(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_square(self): test_data = CsvReader("../tests/Data/Unit Test Square.csv").data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.squ(row['Value 1']), result) def test_square_root(self): test_data = CsvReader("../tests/Data/Unit Test Square Root.csv").data for row in test_data: result = round(float(row['Result']), 8) self.assertEqual(self.calculator.root(row['Value 1']), result) self.assertEqual(self.calculator.result, result) def test_divide_zero(self): self.assertRaises(ZeroDivisionError, self.calculator.divi(0, 0)) def test_result_is_zero_calculator(self): self.assertEqual(self.calculator.result, 0)
def test_add_method_calculator(self): calculator = Calculator() test_data = CsvReader('/data/addition.csv').data for row in test_data: self.assertEqual( calculator.add(float(row['Value 1']), float(row['Value 2'])), float(row['Result'])) self.assertEqual(calculator.result, float(row['Result'])) test_data.clear()
class CalculatorTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_result_is_zero_calculator(self): self.assertEqual(self.calculator.result, 0) def test_Addition(self): file = Reader("testCases/Unit_Test_Addition.csv").content print("test addition \n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.add(row[0], row[1]), float(row[2])) self.assertEqual(self.calculator.result, result) def test_Subtraction(self): file = Reader("testCases/Unit_Test_Subtraction.csv").content print("test subtraction \n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.subtract(row[0], row[1]), float(row[2])) self.assertEqual(self.calculator.result, result) def test_Division(self): file = Reader("testCases/Unit_Test_Division.csv").content print("test division \n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.division(row[0], row[1]), float(row[2])) self.assertEqual(self.calculator.result, result) def test_Multiplication(self): file = Reader("testCases/Unit_Test_Multiplication.csv").content print("test multiplication \n") for row in file: result = float(row[2]) self.assertEqual(self.calculator.multiply(row[0], row[1]), float(row[2])) self.assertEqual(self.calculator.result, result) def test_Square(self): file = Reader("testCases/Unit_Test_Square.csv").content print("test square \n") for row in file: result = float(row[1]) self.assertEqual(self.calculator.square(row[0]), float(row[1])) self.assertEqual(self.calculator.result, result) def test_Square_Root(self): file = Reader("testCases/Unit_Test_Square_Root.csv").content print("test square root \n") for row in file: result = float(row[1]) self.assertAlmostEqual(self.calculator.squareRoot(row[0]), float(row[1])) self.assertAlmostEqual(self.calculator.result, result)
def test_add_method_calculator(self): calculator = Calculator() self.assertEqual(calculator.add(2, 2), 4) self.assertEqual(calculator.result, 4)
class CalculatorTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_result_is_zero_calculator(self): self.assertEqual(self.calculator.result, 0) def test_addition(self): file = Reader("tests/data/Unit_Test_Addition.csv").content print("TESTING ADDITION\n") for row in file: result = float(row[2]) # print('---->: {0:4} + {1:4} = {2:4}'.format(row[0], row[1], row[2])) self.assertEqual(self.calculator.add(row[0], row[1]), float(row[2])) self.assertEqual(self.calculator.result, result) # self.assertEqual(self.calculator.add(5, 6), 11) def test_subtraction(self): file = Reader("tests/data/Unit_Test_Subtraction.csv").content print("TESTING SUBTRACTION\n") for row in file: # print('---->: {0:4} - {1:4} = {2:4}'.format(row[1], row[0], row[2])) self.assertEqual(self.calculator.subtract(row[0], row[1]), float(row[2])) # self.assertEqual(self.calculator.subtract(5, 6), 1) def test_multiplication(self): file = Reader("tests/data/Unit_Test_Multiplication.csv").content print("TESTING MULTIPLICATION\n") for row in file: result = float(row[2]) # print('---->: {0:4} x {1:4} = {2:4}'.format(row[0], row[1], row[2])) self.assertEqual(self.calculator.multiply(row[0], row[1]), float(row[2])) # self.assertEqual(self.calculator.multiply(5, 6), 30) def test_division(self): file = Reader("tests/data/Unit_Test_Division.csv").content print("TESTING DIVISION\n") for row in file: result = float(row[2]) # print('---->: {0:4} / {1:4} = {2:4}'.format(row[1], row[0], row[2])) self.assertEqual(self.calculator.divide(row[0], row[1]), float(row[2])) # self.assertEqual(self.calculator.divide(6, 30), 5) def test_square(self): file = Reader("tests/data/Unit_Test_Square.csv").content print("TESTING SQUARE\n") for row in file: result = float(row[1]) # print('---->: {0:4} ^ {1:2} = {2:4}'.format(row[0], 2, row[1])) self.assertEqual(self.calculator.square(row[0]), float(row[1])) self.assertEqual(self.calculator.result, result) # self.assertEqual(self.calculator.square(5), 25) def test_square_root(self): file = Reader("tests/data/Unit_Test_Square_Root.csv").content print("TESTING SQUARE ROOT\n") for row in file: result = float(row[1]) # print('---->: Square Root of {0:4} = {1:4}'.format(row[0], row[1])) self.assertAlmostEqual(self.calculator.square_root(row[0]), float(row[1])) self.assertAlmostEqual(self.calculator.result, result)
class CalculatorTestCase(unittest2.TestCase): """unit tests for calculator functions.""" def setUp(self) -> None: self.calculator = Calculator() def test_results_property_calculator(self): self.assertEqual(self.calculator.get_result, 0) def test_add_method_calculator(self): self.assertEqual(self.calculator.add(2, 2), 4) self.assertEqual(self.calculator.get_result, 4) test_data = CsvReader('data/UnitTestAddition.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.add(row['Value 2'], row['Value 1']), result) self.assertEqual(self.calculator.get_result, result) def test_subtract_method_calculator(self): self.assertEqual(self.calculator.subtract(2, 2), 0) self.assertEqual(self.calculator.get_result, 0) test_data = CsvReader('data/UnitTestSubtraction.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.subtract(row['Value 2'], row['Value 1']), result) self.assertEqual(self.calculator.get_result, result) def test_multiply_method_calculator(self): self.assertEqual(self.calculator.multiply(2, 2), 4) self.assertEqual(self.calculator.get_result, 4) test_data = CsvReader('data/UnitTestMultiplication.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value 2'], row['Value 1']), result) self.assertEqual(self.calculator.get_result, result) def test_divide_method_calculator(self): self.assertEqual(self.calculator.divide(2, 2), 1) self.assertEqual(self.calculator.get_result, 1) test_data = CsvReader('data/UnitTestDivision.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.divide(row['Value 2'], row['Value 1']), result) self.assertEqual(self.calculator.get_result, result) def test_square_method_calculator(self): self.assertEqual(self.calculator.square(2), 4) self.assertEqual(self.calculator.get_result, 4) test_data = CsvReader('data/UnitTestSquare.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square(row['Value 1']), result) self.assertEqual(self.calculator.get_result, result) def test_square_root_method_calculator(self): self.assertEqual(self.calculator.square_root(4), 2) self.assertEqual(self.calculator.get_result, 2) test_data = CsvReader('data/UnitTestSquareRoot.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square_root(row['Value 1']), result) self.assertEqual(self.calculator.get_result, result) def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator)
def test_addition(self): add = Calculator.add(1, 2) self.assertIsInstance(add, Calculator)