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)
示例#2
0
 def test_square_method_calculator(self):
     calculator = Calculator()
     test_data = CsvReader('/data/square.csv').data
     for row in test_data:
         self.assertEqual(calculator.square(float(row['Value 1'])),
                          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)
示例#4
0
 def test_square_method_calculator(self):
     calculator = Calculator()
     self.assertEqual(calculator.square(2), 4)
     self.assertEqual(calculator.result, 4)
示例#5
0
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)