class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_results_property_calculator(self): self.assertEquals(self.calculator.result, 0) def test_addition(self): test_data = CSVReader("Tests/Data/addition.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.add(row['Value1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) 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_multiplication(self): test_data = CSVReader("Tests/Data/multiplication.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value1'], row['Value2']), result) self.assertEqual(self.calculator.result, result) def test_division(self): test_data = CSVReader("Tests/Data/division.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.divide(row['Value1'], row['Value2']), result) self.assertEqual(self.calculator.divide.result, result) def test_square(self): test_data = CSVReader("Tests/Data/square.csv") for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square(row['Value1']), result) self.assertEqual(self.calculator.square.result, result) def test_squareroot(self): test_data = CSVReader("Tests/Data/squareroot.csv") for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.squareroot(row['Value1']), result) self.assertEqual(self.calculator.squareroot.result, result) def test_results_property(self): self.calculator.add(2, 1) self.assertEqual(self.calculator.result, 3)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_Add(self): test_data = CsvReader('./Tests/Data/UnitTestAddition.csv').data for row in test_data: a = int(row['Value 1']) b = int(row['Value 2']) result = int(row['Result']) self.assertEqual(self.calculator.add(a, b), result) self.assertNotEqual(self.calculator.add(a, b), result - 1) def test_Subtract(self): test_data = CsvReader('./Tests/Data/UnitTestSubtraction.csv').data for row in test_data: a = int(row['Value 1']) b = int(row['Value 2']) result = int(row['Result']) self.assertEqual(self.calculator.subtract(a, b), result) self.assertNotEqual(self.calculator.subtract(a, b), result - 1) def test_Multiply(self): test_data = CsvReader('./Tests/Data/UnitTestMultiplication.csv').data for row in test_data: a = int(row['Value 1']) b = int(row['Value 2']) result = int(row['Result']) self.assertEqual(self.calculator.multiply(a, b), result) self.assertNotEqual(self.calculator.multiply(a, b), result - 1) def test_Divide(self): test_data = CsvReader('./Tests/Data/UnitTestDivision.csv').data for row in test_data: a = int(row['Value 1']) b = int(row['Value 2']) result = float(row['Result']) self.assertAlmostEqual(self.calculator.divide(a, b), result) self.assertNotEqual(self.calculator.divide(a, b), result - 1) def test_Square(self): test_data = CsvReader('./Tests/Data/UnitTestSquare.csv').data for row in test_data: a = int(row['Value 1']) result = int(row['Result']) self.assertEqual(self.calculator.square(a), result) self.assertNotEqual(self.calculator.square(a), result - 1) def test_SquareRoot(self): test_data = CsvReader('./Tests/Data/UnitTestSquareRoot.csv').data for row in test_data: a = int(row['Value 1']) result = float(row['Result']) self.assertAlmostEqual(self.calculator.squareRoot(a), result) self.assertNotEqual(self.calculator.squareRoot(a), result - 1)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_addition(self): add = self.calculator.add(2, 2) self.assertEqual(add, 4) def test_subtraction(self): subtract = self.calculator.subtract(2, 2) self.assertEqual(subtract, 0) def test_multiplication(self): product = self.calculator.product(3, 2) self.assertEqual(product, 6) def test_division(self): divide = self.calculator.divide(2, 1) self.assertEqual(divide, 2) def test_power(self): power = self.calculator.power(3, 2) self.assertEqual(power, 9) def test_root(self): root = self.calculator.root(16, 2) self.assertEqual(root, 4)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_addition(self): add = self.calculator.add(4 ,6) self.assertEqual(add, 10) def test_subtraction(self): subtract = self.calculator.subtract(6 ,3) self.assertEqual(subtract, 3) def test_division(self): divide = self.calculator.divide(10, 2) self.assertEqual(divide, 5) def test_multiplication(self): product = self.calculator.multiply(3, 3) self.assertEqual(product, 9) def test_power(self): power = self.calculator.square(3, 2) self.assertEqual(power, 9) def test_root(self): root = self.calculator.root(9, 2) self.assertEqual(root, 3) def test_results_property(self): self.assertEqual(self.calculator.result, 0)
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_calculator_return_sum(self): result = self.calculator.add(1, 2) self.assertEqual(3, result) def test_calculator_return_square (self): result = self.calculator.square(2) self.assertEqual(4,result) def test_calculator_return_SquareRoot(self): result = self.calculator.SquareRoot(4) self.assertEqual(2, result) def test_calculator_return_product (self): result = self.calculator.Product(2,2) self.assertEqual(4,result) def test_calculator_return_division (self): result = self.calculator.Division(2,2) self.assertEqual(1,result) def test_calculator_return_difference(self): result = self.calculator.subtract(1, 2) self.assertEqual(-1, result)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_results_property_calculator(self): self.assertEqual(self.calculator.result, 0) def test_divide_zero(self): self.assertEqual(self.calculator.divide(0, 4), "Division by zero") def test_add_method_calculator(self): test_data = CsvReader('Tests/Data/Unit_Test_Addition.csv').data for row in test_data: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_subtract_method_calculator(self): test_data = CsvReader('Tests/Data/Unit_Test_Subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_multiply_method_calculator(self): test_data = CsvReader('Tests/Data/Unit_Test_Multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_divide_method_calculator(self): test_data = CsvReader('Tests/Data/Unit_Test_Division.csv').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'])) def test_squared_method_calculator(self): test_data = CsvReader('Tests/Data/Unit_Test_Square.csv').data for row in test_data: self.assertEqual(self.calculator.square(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_squareroot_method_calculator(self): test_data = CsvReader('Tests/Data/Unit_Test_Square_Root.csv').data for row in test_data: self.assertEqual(self.calculator.squareroot(row['Value 1']), round(float(row['Result']), 7)) self.assertEqual(self.calculator.result, round(float(row['Result']), 7))
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_results_property(self): self.assertEqual(self.calculator.result, 0) def test_add_method(self): add_data = CSVReader('csv/Unit Test Addition.csv') for row in add_data.data: self.assertEqual( self.calculator.add(int(row['Value 1']), int(row['Value 2'])), int(row['Result'])) def test_subtract_method(self): sub_data = CSVReader('csv/Unit Test Subtraction.csv') for row in sub_data.data: self.assertEqual( self.calculator.subtract(int(row['Value 2']), int(row['Value 1'])), int(row['Result'])) def test_multiply_method(self): sub_data = CSVReader('csv/Unit Test Multiplication.csv') for row in sub_data.data: self.assertEqual( self.calculator.multiply(int(row['Value 2']), int(row['Value 1'])), int(row['Result'])) def test_divide_method(self): sub_data = CSVReader('csv/Unit Test Division.csv') for row in sub_data.data: self.assertEqual( round( self.calculator.divide(float(row['Value 2']), float(row['Value 1'])), 9), float(row['Result'])) def test_divide_method_zero(self): with self.assertRaises(Exception): self.calculator.divide(1, 0) def test_square_method(self): sub_data = CSVReader('csv/Unit Test Square.csv') for row in sub_data.data: self.assertEqual(self.calculator.square(int(row['Value 1'])), int(row['Result'])) def test_sqrt_method(self): sub_data = CSVReader('csv/Unit Test Square Root.csv') for row in sub_data.data: self.assertEqual( round(self.calculator.square_root(float(row['Value 1'])), 8), round(float(row['Result']), 8))
class MyTestCase(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.CsvReader('Tests/Data/TestAddition.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, int(row['Result'])) def test_subtraction(self): test_data = CsvReader.CsvReader('Tests/Data/TestSubtraction.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, int(row['Result'])) def test_multiplication(self): test_data = CsvReader.CsvReader( 'Tests/Data/TestMultiplication.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, int(row['Result'])) def test_division(self): test_data = CsvReader.CsvReader('Tests/Data/TestDivision.csv').data for row in test_data: result = float(row['Result']) self.assertAlmostEqual( self.calculator.divide(row['Value 1'], row['Value 2']), result) self.assertAlmostEqual(self.calculator.result, float(row['Result'])) def test_square(self): test_data = CsvReader.CsvReader('Tests/Data/TestSquare.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square(row['Value 1']), result) self.assertEqual(self.calculator.result, int(row['Result'])) def test_square_root(self): test_data = CsvReader.CsvReader('Tests/Data/TestSquareRoot.csv').data for row in test_data: result = float(row['Result']) self.assertAlmostEqual(self.calculator.square_root(row['Value 1']), result) self.assertAlmostEqual(self.calculator.result, float(row['Result']))
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_results_property(self): self.assertEqual(self.calculator.result, 0) def test_subtraction(self): test_data = CsvReader('Tests/Data/subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_addition(self): test_data = CsvReader('Tests/Data/addition.csv').data for row in test_data: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_multiplication(self): test_data = CsvReader('Tests/Data/multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_division(self): test_data = CsvReader('Tests/Data/division.csv').data for row in test_data: self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), round(float(row['Result']), 9)) self.assertEqual(self.calculator.result, round(float(row['Result']), 9)) def test_square(self): test_data = CsvReader('Tests/Data/square.csv').data for row in test_data: self.assertEqual(self.calculator.square(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_squareroot(self): test_data = CsvReader('Tests/Data/squareroot.csv').data for row in test_data: self.assertEqual(self.calculator.squareroot(row['Value 1']), round(float(row['Result']), 8)) self.assertEqual(self.calculator.result, round(float(row['Result']), 8))
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("Group4Test/Group4Data/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_addition(self): test_data = CsvReader("Group4Test/Group4Data/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_multiplication(self): test_data = CsvReader("Group4Test/Group4Data/multiplication.csv").data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_division(self): test_data = CsvReader("Group4Test/Group4Data/division.csv").data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.divide(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) def test_square(self): test_data = CsvReader("Group4Test/Group4Data/square.csv").data for row in test_data: result = float(row['Result']) self.assertEqual(row['Value 1'], result) self.assertEqual(self.calculator.result, result) #Old values = def test_sqrt(self): def test_sqrt(self): test_data = CsvReader("Group4Test/Group4Data/squareroot.csv").data for row in test_data: result = float(row['Result']) self.assertEqual((row['Value 1'], result)) self.assertEqual(self.calculator.result, result) def test_results_property(self): self.assertEqual(self.calculator.result, 0)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_square_root(self): test_data = CsvReader('/Tests/Data/Unit Test Square Root.csv').data for row in test_data: self.assertEqual( self.calculator.square_root(row['Value 1']), Decimal(row['Result']).quantize(Decimal('.000001'))) self.assertEqual( self.calculator.result, Decimal(row['Result']).quantize(Decimal('.000001'))) def test_square(self): test_data = CsvReader('/Tests/Data/Unit Test Square.csv').data for row in test_data: self.assertEqual(self.calculator.square(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_division(self): test_data = CsvReader('/Tests/Data/Unit Test Division.csv').data for row in test_data: self.assertEqual( self.calculator.division(row['Value 1'], row['Value 2']), Decimal(row['Result'])) self.assertEqual(self.calculator.result, Decimal(row['Result'])) def test_multiplication(self): test_data = CsvReader('/Tests/Data/Unit Test Multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiplication(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_subtract(self): test_data = CsvReader('/Tests/Data/Unit Test Subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_addition(self): test_data = CsvReader('/Tests/Data/Unit Test Addition.csv').data for row in test_data: self.assertEqual( self.calculator.add(row['Value 2'], row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
class MyTestCase(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_Calculator.csv").data for row in test_data: result = float(row['Add Result']) self.assertEqual(self.calculator.add(row['Add 1'], row['Add 2']), float(row['Add Result'])) self.assertEqual(self.calculator.result, result) def test_subtraction(self): test_data = CsvReader("Tests/Data/Unit_Test_Calculator.csv").data for row in test_data: result = float(row['Sub Result']) self.assertEqual(self.calculator.subtract(row['Sub 1'], row['Sub 2']), float(row['Sub Result'])) self.assertEqual(self.calculator.result, result) def test_multiplication(self): test_data = CsvReader("Tests/Data/Unit_Test_Calculator.csv").data for row in test_data: result = float(row['Multiply Result']) self.assertEqual(self.calculator.multiply(row['Multiply 1'], row['Multiply 2']), float(row['Multiply Result'])) self.assertEqual(self.calculator.result, result) def test_division(self): test_data = CsvReader("Tests/Data/Unit_Test_Calculator.csv").data for row in test_data: result = float(row['Divide Result']) self.assertEqual(self.calculator.division(row['Divide 1'], row['Divide 2']), float(row['Divide Result'])) self.assertEqual(self.calculator.result, result) def test_squared(self): test_data = CsvReader("Tests/Data/Unit_Test_Calculator.csv").data for row in test_data: result = float(row['Squared Result']) self.assertEqual(self.calculator.squared(row['Squared 1']), float(row['Squared Result'])) self.assertEqual(self.calculator.result, result) def test_sqrt(self): test_data = CsvReader("Tests/Data/Unit_Test_Calculator.csv").data for row in test_data: result = float(row['Sqrt Result']) self.assertEqual(self.calculator.sqrt(row['Sqrt 1']), float(row['Sqrt Result'])) self.assertEqual(self.calculator.result, result) 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 for row in test_data: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) def test_subtract_method_calculator(self): test_data = CsvReader('Tests/Data/Subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) def test_divide_method_calculator(self): test_data = CsvReader('Tests/Data/Division.csv').data for row in test_data: x = float(row['Value 1']) y = float(row['Value 2']) z = float(row['Result']) self.assertEqual(self.calculator.divide(y, x), round(z, 7)) def test_multiply_method_calculator(self): test_data = CsvReader('Tests/Data/Multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(int(row['Value 1']), int(row['Value 2'])), int(row['Result'])) def test_square_method_calculator(self): test_data = CsvReader('Tests/Data/Square.csv').data for row in test_data: self.assertEqual(self.calculator.square(row['Value 1']), int(row['Result'])) def test_sqrt_method_calculator(self): test_data = CsvReader('Tests/Data/Square Root.csv').data for row in test_data: x = float(row['Value 1']) y = float(row['Result']) self.assertEqual(self.calculator.sqrt(x), round(y, 8)) if __name__ == '__main__': unittest.main()
class MyTestCase(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('CalcData/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('CalcData/Unit_Test_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_multiplication(self): test_data = CSVReader('CalcData/Unit_Test_Multiplication.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_division(self): test_data = CSVReader('CalcData/Unit_Test_Division.csv').data for row in test_data: result = float(row['Result']) self.assertAlmostEqual(self.calculator.divide(row['Value 2'], row['Value 1']), result) self.assertAlmostEqual(self.calculator.result, result) def test_square(self): test_data = CSVReader('CalcData/Unit_Test_Square.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square(float(row['Value 1'])), result) self.assertEqual(self.calculator.result, result) def test_square_root(self): test_data = CSVReader('CalcData/Unit_Test_Square_Root.csv').data for row in test_data: result = float(row['Result']) self.assertAlmostEqual(self.calculator.square_root(float(row['Value 1'])), result) self.assertAlmostEqual(self.calculator.result, result) def test_results_property(self): self.assertEqual(self.calculator.result, 0)
class MyTestCase(unittest.TestCase): def setUp(self): self.Calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.Calculator, Calculator) def test_subtraction(self): pprint("________Subtraction________") test_data = CsvReader('Tests/csv/Subtraction.csv').data for row in test_data: self.assertEqual(self.Calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.Calculator.result, int(row['Result'])) def test_addition(self): pprint("________Addition________") test_data = CsvReader('Tests/csv/Addition.csv').data for row in test_data: self.assertEqual(self.Calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.Calculator.result, int(row['Result'])) def test_multiplication(self): pprint("________Multiplication________") test_data = CsvReader('Tests/csv/Multiplication.csv').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'])) def test_division(self): pprint("________Division________") test_data = CsvReader('Tests/csv/Division.csv').data for row in test_data: self.assertAlmostEqual(self.Calculator.divide(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertAlmostEqual(self.Calculator.result, float(row['Result'])) def test_square(self): pprint("________Square________") test_data = CsvReader('Tests/csv/Square.csv').data for row in test_data: self.Calculator.square(row['Value 1']) self.assertEqual(self.Calculator.result, int(row['Result'])) def test_squareroot(self): pprint("________Square Root________") test_data = CsvReader('Tests/csv/Square_Root.csv').data for row in test_data: self.Calculator.sqroot(int(row['Value 1'])) self.assertAlmostEqual(self.Calculator.result, float(row['Result']))
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_result(self): self.assertEqual(self.calculator.result, 0) def test_add(self): result = 8 self.assertEqual(self.calculator.add(3, 5), result) self.assertEqual(self.calculator.result, result) def test_subtract(self): result = -2 self.assertEqual(self.calculator.subtract(3, 5), result) self.assertEqual(self.calculator.result, result) def test_multiply(self): result = 15 self.assertEqual(self.calculator.multiply(3, 5), result) self.assertEqual(self.calculator.result, result) def test_divide(self): result = 3 self.assertEqual(self.calculator.divide(15, 5), result) self.assertEqual(self.calculator.result, result) try: self.calculator.divide(3, 0) except ZeroDivisionError: pass else: self.fail("Did not catch ZeroDivisionError") def test_square(self): result = 9 self.assertEqual(self.calculator.square(3), result) self.assertEqual(self.calculator.result, result) def test_squareroot(self): result = 3 self.assertEqual(self.calculator.squareroot(9), result) self.assertEqual(self.calculator.result, result)
def automateAdd(self): print(" Test Case for Addition ") print(self.random1, "- This is first Random number ") print(self.random2, "- This is second Random number ") num1 = self.random1 num2 = self.random2 print("Addition by Automated funnction =", num1 + num2) # By using the function c = Calculator() sum2 = c.add(num1, num2) print("Addition Output by Calling function =", sum2) if num1 + num2 == sum2: print("Test case of calculator is passed\n\n") else: print(" Test Automation of of Calculator Addition is failed ") print('*' * 70)
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/Unit Test Addition.csv").data for row in test_data: self.assertEqual(self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_sub_method_calculator(self): test_data = CsvReader("Tests/Data/Unit Test Subtraction.csv").data for row in test_data: self.assertEqual(self.calculator.sub(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_multiply_method_calculator(self): test_data = CsvReader("Tests/Data/Unit Test Multiplication.csv").data for row in test_data: self.assertEqual(self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_divide_method_calculator(self): test_data = CsvReader("Tests/Data/Unit Test Division.csv").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'])) def test_square_method_calculator(self): test_data = CsvReader("Tests/Data/Unit Test Square.csv").data for row in test_data: self.assertEqual(self.calculator.squares(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_sqrt_method_calculator(self): test_data = CsvReader("Tests/Data/Unit Test Square Root.csv").data for row in test_data: self.assertEqual(self.calculator.square_root(row['Value 1']), round(float(row['Result']), 7)) self.assertEqual(self.calculator.result, round(float(row['Result']), 7))
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_results_properties(self): self.assertEqual(self.calculator.result, 0) def test_addition_calculator(self): test_Data = CsvReader("/Tests/Data/UnitTestAddition.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"])) def test_subtraction_calculator(self): test_Data = CsvReader("/Tests/Data/UnitTestSubtraction.csv").data pprint(test_Data) for row in test_Data: self.assertEqual( self.calculator.subtract(row["Value 1"], row["Value 2"]), float(row["Result"])) self.assertEqual(self.calculator.result, float(row["Result"])) def test_multiplication_calculator(self): test_Data = CsvReader("/Tests/Data/UnitTestMultiplication.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"])) def test_division_calculator(self): test_Data = CsvReader("/Tests/Data/UnitTestDivision.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"])) def test_square_calculator(self): test_Data = CsvReader("/Tests/Data/UnitTestSquare.csv").data pprint(test_Data) for row in test_Data: self.assertEqual(self.calculator.squared(row["Value 1"]), float(row["Result"])) self.assertEqual(self.calculator.result, float(row["Result"])) def test_squareroot_calculator(self): test_Data = CsvReader("/Tests/Data/UnitTestSquareRoot.csv").data pprint(test_Data) for row in test_Data: self.assertEqual(self.calculator.sqrt(row["Value 1"]), float(row["Result"])) self.assertEqual(self.calculator.result, float(row["Result"]))
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() # To test instantiation of calculator class def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) # Testing addition def test_addition(self): test_data = CSVReader( '/Tests/Data_Calculator/Unit Test Addition.csv').data for row in test_data: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) test_data.clear() # Testing subtraction def test_subtraction(self): test_data = CSVReader( '/Tests/Data_Calculator/Unit Test Subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) test_data.clear() # Testing multiplication def test_multiplication(self): test_data = CSVReader( '/Tests/Data_Calculator/Unit Test Multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) test_data.clear() # Testing division def test_division(self): test_data = CSVReader( '/Tests/Data_Calculator/Unit Test Division.csv').data for row in test_data: self.assertAlmostEqual( float(row['Result']), self.calculator.divide(row['Value 1'], row['Value 2'])) self.assertAlmostEqual(float(row['Result']), round(self.calculator.result, 9)) test_data.clear() # Testing squared def test_squared(self): test_data = CSVReader( '/Tests/Data_Calculator/Unit Test Square.csv').data for row in test_data: self.assertEqual(self.calculator.squared(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) test_data.clear() # Testing squared root def test_squared_root(self): test_data = CSVReader( '/Tests/Data_Calculator/Unit Test Square Root.csv').data for row in test_data: self.assertAlmostEqual( self.calculator.squared_root(row['Value 1']), round(float(row['Result']), 9)) self.assertAlmostEqual(round(float(row['Result']), 9), round(self.calculator.result, 9)) test_data.clear() def test_results(self): self.assertEqual(self.calculator.result, 0)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calobject = Calculator() # Object of the class Calculator def test_instantiate_calculator(self): # Instantiate the Calculator class self.assertIsInstance(self.calobject, Calculator) def test_addition_method_calculator(self): # Testing of the add function print("Testing Addition") try: test_data = CsvReader('./Data/Unit Test Addition.csv' ).data # Loading the .csv data file except: print('File not found, Please input valid file.') for row in test_data: x = row['Value 1'] y = row['Value 2'] expect_result = int(row['Result']) self.assertEqual(self.calobject.add(x, y), expect_result) self.assertEqual(self.calobject.result, expect_result) print('Successful Testing!') def test_subtraction_method_calculator( self): # Testing of the subtract function print(' ') print('Testing Subtraction') try: test_data = CsvReader('./Data/Unit Test Subtraction.csv' ).data # Loading the .csv data file except: print('File not found, Please input valid file.') for row in test_data: x = row['Value 1'] y = row['Value 2'] expect_result = int(row['Result']) self.assertEqual(self.calobject.subtract(x, y), expect_result) self.assertEqual(self.calobject.result, expect_result) print('Successful Testing!') def test_multiply_method_calculator( self): # Testing of the multiply function print(' ') print('Testing Multiplication') try: test_data = CsvReader('./Data/Unit Test Multiplication.csv' ).data # Loading the .csv data file except: print('File not found, Please input valid file.') for row in test_data: x = int(row['Value 1']) y = int(row['Value 2']) expect_result = int(row['Result']) self.assertEqual(self.calobject.multiply(x, y), expect_result) self.assertEqual(self.calobject.result, expect_result) print('Successful Testing!') def test_divide_method_calculator(self): # Testing of the divide function print(' ') print('Testing Division') try: test_data = CsvReader('./Data/Unit Test Division.csv' ).data # Loading the .csv data file except: print('File not found, Please input valid file.') for row in test_data: x = float(row['Value 1']) y = float(row['Value 2']) expect_result = float(row['Result']) self.assertEqual(self.calobject.divide(x, y), round(expect_result, 7)) self.assertEqual(self.calobject.result, round(expect_result, 7)) print('Successful Testing!') def test_square_method_calculator(self): # Testing of the square function print(' ') print('Testing Squares') try: test_data = CsvReader('./Data/Unit Test Square.csv' ).data # Loading the .csv data file except: print('File not found, Please input valid file.') for row in test_data: x = int(row['Value 1']) expect_result = int(row['Result']) self.assertEqual(self.calobject.square(x), expect_result) self.assertEqual(self.calobject.result, expect_result) print('Successful Testing!') def test_sqrt_method_calculator( self): # Testing of the square_root function print(' ') print('Testing Square Roots') try: test_data = CsvReader('./Data/Unit Test Square Root.csv' ).data # Loading the .csv data file except: print('File not found, Please input valid file.') for row in test_data: x = float(row['Value 1']) expect_result = float(row['Result']) self.assertEqual(self.calobject.square_root(x), round(expect_result, 8)) self.assertEqual(self.calobject.result, round(expect_result, 8)) print('Successful Testing!')
class CsvReaderTests(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_csvreader(self): self.csv_reader = CsvReader('data/Unit Test CsvReader.txt') self.assertIsInstance(self.csv_reader, CsvReader) self.assertEqual(self.csv_reader.data.__len__(), 2) def test_zerolength(self): try: test_data = CsvReader( 'data/Unit Test Zero Length Datafile.csv').data except ZeroDataException: pass else: self.fail("Did not catch ZeroDataException.") def test_add(self): test_data = CsvReader('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) def test_subtract(self): test_data = CsvReader('data/Unit Test Subtraction.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.subtract(row['Value 2'], row['Value 1']), result) def test_multiply(self): test_data = CsvReader('data/Unit Test Multiplication.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), result) def test_division(self): test_data = CsvReader('data/Unit Test Division.csv').data for row in test_data: result = float(row['Result']) self.assertEqual( round(self.calculator.divide(row['Value 2'], row['Value 1']), 9), result) def test_square(self): test_data = CsvReader('data/Unit Test Square.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square(row['Value 1']), result) def test_squareroot(self): test_data = CsvReader('data/Unit Test Square Root.csv').data for row in test_data: data = row['Result'] result = float(data) if "." in data: sigfigs = len(data.split('.')[1]) self.assertEqual( round(self.calculator.squareroot(row['Value 1']), sigfigs), result) else: self.assertEqual(self.calculator.squareroot(row['Value 1']), result)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_results_property(self): self.assertEqual(self.calculator.result, 0) ## Part 1 - Subtraction def test_subtraction_calulator(self): print("Start Subtraction test") self.assertEqual(self.calculator.subtract(2, 4), 2) self.assertEqual(self.calculator.result, 2) test_data = getFileData('/Tests/Data/UnitTestSubtraction.csv').data for row in test_data: self.assertEqual(self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) ## Part 2 - Addition def test_addition_calulator(self): print("Start addition test") test_data = getFileData('/Tests/Data/UnitTestAddition.csv').data for row in test_data: self.assertEqual(self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) ## Part 3 - Multiplcation def test_multiplication_calulator(self): print("Start Multiplication test") self.assertEqual(self.calculator.multiply(4, 4), 16) self.assertEqual(self.calculator.result, 16) test_data = getFileData('/Tests/Data/UnitTestMultiplication.csv').data for row in test_data: self.assertEqual(self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) ## Part 4 - Divide def test_division_calulator(self): print("Start Divide test") self.assertEqual(self.calculator.divide(4, 4), 1) self.assertEqual(self.calculator.result, 1) test_data = getFileData('/Tests/Data/UnitTestDivision.csv').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'])) ## Part 5 - Square def test_square_calulator(self): print("Start Square test") self.assertEqual(self.calculator.square(4), 16) self.assertEqual(self.calculator.result, 16) test_data = getFileData('/Tests/Data/UnitTestSquare.csv').data for row in test_data: self.assertEqual(self.calculator.square(row['Value 1']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result'])) ## Part 6 - Square Root def test_sqrt_calulator(self): print("Start Square Root test") self.assertEqual(self.calculator.sqrt(16), 4) self.assertEqual(self.calculator.result, 4) test_data = getFileData('/Tests/Data/UnitTestSquareRoot.csv').data for row in test_data: self.assertAlmostEqual(self.calculator.sqrt(row['Value 1']), float(row['Result'])) self.assertAlmostEqual(self.calculator.result, float(row['Result']))
def addition_test(self): calculator = Calculator() result = calculator.add(2, 2) self.assertEqual(4, result)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_results_property_calculator(self): self.assertEqual(self.calculator.result, 0) def test_add_method_calculator(self): self.assertEqual(self.calculator.add(2, 2), 4) self.assertEqual(self.calculator.result, 4) def test_subtract_method_calculator(self): self.assertEqual(self.calculator.subtract(2, 2), 0) self.assertEqual(self.calculator.result, 0) def test_multiply_method_calculator(self): self.assertEqual(self.calculator.multiply(2, 2), 4) self.assertEqual(self.calculator.result, 4) def test_divide_method_calculator(self): self.assertEqual(self.calculator.divide(5, 10), 2) self.assertEqual(self.calculator.result, 2) def test_square_method_calculator(self): self.assertEqual(self.calculator.square(5), 25) self.assertEqual(self.calculator.result, 25) def test_square_root_method_calculator(self): self.assertEqual(self.calculator.square_root(49), 7) self.assertEqual(self.calculator.result, 7) # Unit tests testing individual csv files def test_subtraction(self): test_data_subtract = CsvReader( './Tests/Data/Unit Test Subtraction.csv').data for row in test_data_subtract: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_addition(self): test_data_add = CsvReader('./Tests/Data/Unit Test Addition.csv').data for row in test_data_add: self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_multiplication(self): test_data_multiply = CsvReader( './Tests/Data/Unit Test Multiplication.csv').data for row in test_data_multiply: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_division(self): test_data_divide = CsvReader( './Tests/Data/Unit Test Division.csv').data for row in test_data_divide: self.assertEqual( round(self.calculator.divide(row['Value 1'], row['Value 2']), 9), round(float(row['Result']), 9)) self.assertEqual(round(self.calculator.result, 9), round(float(row['Result']), 9)) def test_square(self): test_data_square = CsvReader('./Tests/Data/Unit Test Square.csv').data for row in test_data_square: self.assertEqual(self.calculator.square(row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_square_root(self): test_data_square_root = CsvReader( './Tests/Data/Unit Test Square Root.csv').data for row in test_data_square_root: self.assertEqual( round(self.calculator.square_root(row['Value 1']), 8), round(float(row['Result']), 8)) self.assertEqual(round(self.calculator.result, 8), round(float(row['Result']), 8))
from Calculator.Calculator import Calculator from Translator.Translator import Translator from UserInterface.UserInterface import UserInterface if __name__ == "__main__": userInterface = UserInterface() traductor = Translator() calculator = Calculator() userInterface.showTitle() number1 = userInterface.getWordNumber("primer") number2 = userInterface.getWordNumber("segundo") number1 = traductor.wordToNumberTranslate(number1) number2 = traductor.wordToNumberTranslate(number2) result = calculator.add(number1, number2) userInterface.showResult(result)
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): result = roundOff(4) self.assertEqual(self.calculator.add(2, 2), result) self.assertEqual(self.calculator.result, result) def test_add_method_calculatorCSV(self): test_data = CsvReader('Data/Addition.csv').data for row in test_data: result = roundOff(float(row['Result'])) self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_subtract_method_calculator(self): result = roundOff(0) self.assertEqual(self.calculator.subtract(2, 2), result) self.assertEqual(self.calculator.result, result) def test_subtract_method_calculatorCSV(self): test_data = CsvReader('Data/Subtraction.csv').data for row in test_data: result = roundOff(float(row['Result'])) self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_multiply_method_calculator(self): result = 4 self.assertEqual(self.calculator.multiply(2, 2), result) self.assertEqual(self.calculator.result, result) def test_multiply_method_calculatorCSV(self): test_data = CsvReader('Data/Multiplication.csv').data for row in test_data: result = roundOff(float(row['Result'])) self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_divide_method_calculator(self): result = roundOff(2) self.assertEqual(self.calculator.divide(4, 8), result) self.assertEqual(self.calculator.result, result) def test_divide_method_calculatorCSV(self): test_data = CsvReader('Data/Division.csv').data for row in test_data: result = roundOff((row['Result'])) self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_square_method_calculator(self): result = roundOff(16) self.assertEqual(self.calculator.square(4), result) self.assertEqual(self.calculator.result, result) def test_square_method_calculatorCSV(self): test_data = CsvReader('Data/Square.csv').data for row in test_data: result = roundOff(float(row['Result'])) self.assertEqual(self.calculator.square(row['Value 1']), result) self.assertEqual(self.calculator.result, result) def test_sqrt_method_calculator(self): result = roundOff(2) self.assertEqual(self.calculator.squareroot(4), result) self.assertEqual(self.calculator.result, result) def test_sqrt_method_calculatorCSV(self): test_data = CsvReader('Data/Square Root.csv').data for row in test_data: result = roundOff(float(row['Result'])) self.assertAlmostEqual(self.calculator.squareroot(row['Value 1']), result) self.assertAlmostEqual(self.calculator.result, result)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_results_property_calculator(self): self.assertEqual(self.calculator.result, 0) def test_add_method_calculator(self): self.assertEqual(self.calculator.add(2, 2), 4) self.assertEqual(self.calculator.result, 4) test_data = CsvReader('Tests/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.result, result) def test_subtract_method_calculator(self): self.assertEqual(self.calculator.subtract(2, 2), 0) self.assertEqual(self.calculator.result, 0) test_data = CsvReader('Tests/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.result, result) def test_multiply_method_calculator(self): self.assertEqual(self.calculator.multiply(2, 2), 4) self.assertEqual(self.calculator.result, 4) test_data = CsvReader('Tests/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.result, result) def test_divide_method_calculator(self): self.assertEqual(self.calculator.divide(2, 2), 1) self.assertEqual(self.calculator.result, 1) test_data = CsvReader('Tests/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.result, result) def test_square_method_calculator(self): self.assertEqual(self.calculator.square(2), 4) self.assertEqual(self.calculator.result, 4) test_data = CsvReader('Tests/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.result, result) def test_square_root_method_calculator(self): self.assertEqual(self.calculator.squareroot(4), 2) self.assertEqual(self.calculator.result, 2) test_data = CsvReader('Tests/Data/UnitTestSquareRoot.csv').data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.squareroot(row['Value 1']), result) self.assertEqual(self.calculator.result, result) def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): calculator = Calculator() self.assertIsInstance(calculator, Calculator) def test_results_property_calculator(self): self.assertEqual(self.calculator.result, 0) def test_add(self): test_data = CsvReader("/Tests/Data/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_subtract_method_calculator(self): # self.assertEqual(self.calculator.subtract(2, 2), 0) # self.assertEqual(self.calculator.result, 0) def test_subtract(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_multiply(self): test_data = CsvReader("/Tests/Data/Multiplication.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_divide(self): test_data = CsvReader("/Tests/Data/Division.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result) def test_square_root(self): test_data = CsvReader("/Tests/Data/SquareRoot.csv").data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square_root(row['Value 1']), round(result, 8)) # self.assertEqual(self.calculator.square_root(row['Value 1']), result) # self.assertEqual("nan", self.calculator.square_root(-4)) # def test_square_root_method_calculator(self): # self.assertEqual(2, self.calculator.square_root(4)) # self.assertEqual(0, self.calculator.square_root(0)) # self.assertEqual("nan", self.calculator.square_root(-4)) def test_square(self): test_data = CsvReader("/Tests/Data/Square.csv").data for row in test_data: result = float(row['Result']) self.assertEqual(self.calculator.square(row['Value 1']), result) self.assertEqual(self.calculator.result, result)