class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_subtraction(self): test_data = CsvReader("Tests/Data/subtraction.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_add_method_calculator(self): test_data_add = CsvReader('Tests/Data/Addition.csv').data for row in test_data_add: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) def test_multiply_method_calculator(self): test_data_multiply = CsvReader('Tests/Data/Multiplication.csv').data for row in test_data_multiply: self.assertEqual( self.calculator.mul(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) def test_divide_method_calculator(self): test_data_divide = CsvReader('Tests/Data/Division.csv').data for row in test_data_divide: self.assertEqual( round(self.calculator.division(row['Value 1'], row['Value 2']), 2), round(float(row['Result']), 2)) self.assertEqual(round(self.calculator.result, 2), round(float(row['Result']), 2)) def test_square_method_calculator(self): test_data_square = CsvReader('Tests/Data/Square.csv').data for row in test_data_square: self.assertEqual(self.calculator.sq(row['Value 1']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) def test_square_root_method_calculator(self): test_data_square_root = CsvReader('Tests/Data/Square Root.csv').data for row in test_data_square_root: self.assertEqual(round(self.calculator.sqr(row['Value 1']), 2), round(float(row['Result']), 2)) self.assertEqual(round(self.calculator.result, 2), round(float(row['Result']), 2)) def test_results_property(self): self.assertEqual(self.calculator.result, 0)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_add_method_calculator(self): test_data = CsvReader("Tests/Data/addition.csv").data pprint(test_data) for row in test_data: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) test_data.clear() def test_subtract_method_calculator(self): test_data = CsvReader("Tests/Data/subtraction.csv").data pprint(test_data) for row in test_data: self.assertEqual( self.calculator.subtract(int(row['Value 2']), int(row['Value 1'])), int(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) test_data.clear() def test_multiply_method_calculator(self): test_data = CsvReader("Tests/Data/multiplication.csv").data pprint(test_data) for row in test_data: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) test_data.clear() def test_divide_method_calculator(self): test_data = CsvReader("Tests/Data/division.csv").data pprint(test_data) for row in test_data: self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) test_data.clear() def test_square_method_calculator(self): test_data = CsvReader("Tests/Data/square.csv").data pprint(test_data) for row in test_data: self.assertEqual(self.calculator.sqr(int(row['Value 1'])), int(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) test_data.clear() def test_sqrt_method_calculator(self): test_data = CsvReader("Tests/Data/sq_rt.csv").data pprint(test_data) for row in test_data: self.assertEqual(self.calculator.sq_rt(int(row['Value 1'])), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) test_data.clear() def test_results_property_calculator(self): self.assertEqual(self.calculator.result, 0)