Ejemplo n.º 1
0
class SampleSize(DataLoader):
    def __init__(self):
        self.calc = Calculator()
        pass

    def cochran_small(self, n_0, N):
        return cochran_small(n_0, N)

    def cochran_large(self, proportion, marginerror, confidence):
        return cochran_large(proportion, marginerror, confidence)

    def cochran(self, N, proportion, marginerror, confidence):
        n_0 = cochran_large(proportion, marginerror, confidence)
        if N >= 500:
            return n_0
        else:
            return cochran_small(n_0, N)

    def find_n_size_unknown_sigma(self, confidence_p, interval_width,
                                  n_pct_of_N):
        z = Statistics.z_given_confidence(confidence_p)
        E = self.calc.divide(interval_width, 2)
        p_hat = n_pct_of_N
        q_hat = 1 - p_hat
        pq = self.calc.multiply(p_hat, q_hat)
        result = self.calc.multiply(self.calc.square(self.calc.divide(z, E)),
                                    pq)
        return round(result, 0)

    def find_n_size_given_sigma(self, confidence_p, sigma, me):
        z = Statistics.z_given_confidence(confidence_p)
        zsig = self.calc.multiply(z, sigma)
        result = self.calc.square(self.calc.divide(zsig, me))
        return round(result, 0)
Ejemplo n.º 2
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_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))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
def cochran_large(proportion, me, confidence):
    calc = Calculator()
    z = Statistics.z_given_confidence(confidence)
    z_2 = calc.square(z)
    e_2 = calc.square(me)
    n_0 = calc.divide(
        calc.multiply(calc.multiply(z_2, proportion), 1 - proportion), e_2)
    return round(n_0, 0)
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']))
Ejemplo n.º 11
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)
Ejemplo n.º 13
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()
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.calculator = Calculator()

    def test_setUp(self):
        self.assertIsInstance(self.calculator, Calculator)

    def test_calc_return_add(self):
        result = self.calculator.addition(1, 2)
        self.assertEqual(3, result)

    def test_calc_return_sub(self):
        result = self.calculator.subtraction(1, 2)
        self.assertEqual(-1, result)

    def test_calc_access_sum_result(self):
        self.calculator.addition(1, 2)
        self.assertEqual(3, self.calculator.result)

    def test_calc_access_sub_result(self):
        self.calculator.subtraction(1, 2)
        self.assertEqual(-1, self.calculator.result)

    def test_calc_return_times(self):
        result = self.calculator.multiplication(3, 2)
        self.assertEquals(6, result)

    def test_calc_return_divide(self):
        result = self.calculator.divide(4, 2)
        self.assertEquals(2, result)

    def test_calc_return_exp(self):
        result = self.calculator.exponentiate(3, 4)
        self.assertEquals(81, result)

    def test_calc_return_logged(self):
        result = self.calculator.logger(10, 10)
        self.assertEquals(1.0, result)

    def test_calc_return_nthRoot(self):
        result = self.calculator.nthRoot(4, 81)
        self.assertEquals(3.0, result)

    def test_multiple_calculators(self):
        calculator1 = Calculator()
        calculator2 = Calculator()

        self.calculator.addition(calculator1.addition(1, 2),
                                 calculator2.subtraction(3, 4))

        self.assertEqual(2, self.calculator.result)
Ejemplo n.º 16
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']))
Ejemplo n.º 17
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/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))
    def automateDivision(self):
        print(" Test Case for Division ")
        print(self.random1, "- This is first Random number ")
        print(self.random2, "- This is second Random number ")
        num1 = self.random1
        num2 = self.random2
        try:
            print("Division by Automated function =", num1 / num2)

        except ZeroDivisionError:
            print(num1, "/", num2, " = Infinity")

        # By using the function
        c = Calculator()
        division = c.divide(num1, num2)
        print("Division Output by Calling function =", division)

        if num1 / num2 == division:
            print("Test case of calculator Division is passed\n\n")

        else:
            print(" Test Automation of of Calculator Division is failed ")
        print('*' * 70)
Ejemplo n.º 19
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)
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"]))
Ejemplo n.º 21
0
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!')
Ejemplo n.º 23
0
def cochran_small(n_0, N):
    calc = Calculator()
    return round(calc.divide(n_0, 1 + calc.divide(n_0 - 1, N)), 0)
Ejemplo n.º 24
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)

## 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 test_divide(self):
     calculator = Calculator()
     result = calculator.divide(1, 2)
     self.assertEqual(0.5, result)
Ejemplo n.º 26
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_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))
Ejemplo n.º 27
0
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)
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
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):
        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)