class MyTestCase(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.assertIsInstance(self.calculator.result, 0) def test_subtraction(self): test_data = CsvReader('/tests/CSV_files/subtraction.csv').data for row in test_data: self.assertEqual(self.calculator.subtract(row['Value 2'], row['Value 1']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_addition(self): test_data = CsvReader('/CSV_files/addition.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_results_property(self): self.assertEqual(self.calculator.result, 0)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.statistics = Statistics('Tests/Data/statistics.csv') self.calculator=Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.statistics, Statistics) def test_decorator_calculator(self): self.assertIsInstance(self.statistics, Statistics) def test_mean(self): self.assertEqual(self.statistics.mean(), 0.25) def test_median(self): self.assertEqual(self.statistics.median(), 4) def test_mode(self): self.assertEqual(self.statistics.mod(), 1) def test_popstand(self): self.assertEqual(round(self.statistics.popstand(), 4), 0.2233) def test_vpop(self): self.assertEqual(self.statistics.vpop(), 0.0498442) def test_confidence(self): self.assertEqual(self.statistics.confidence(), 0.2232581) def test_popuvar(self): self.assertEqual(self.statistics.confidence(), 0.2232581) def test_sample_mean(self): self.assertEqual(self.statistics.sample_mean(), 4) def test_zscore(self): self.assertEqual(self.statistics.confidence(), 0.2232581) def test_samplestand(self): self.assertEqual(self.statistics.confidence(), 0.2232581) def test_prop(self): self.assertEqual(self.statistics.prop(), 1.6) def test_variance_sample_proportion(self): my_pop = read_pop("Variance.csv") try: self.assertEqual(self.calculator.variance_sample_proportion(my_pop),0.0045) # positive test self.assertNotEqual(self.calculator.variance_sample_proportion(my_pop),0.0045+1) # negative test except AssertionError as e: print("Variance of Sample Proportion has Assertion Error:", e) def test_standardised_score(self): self.assertListEqual(self.statistics.zscore(), 0.2232581)
class Test_calculate_test(unittest.TestCase): def setUp(self): self.calc = Calculator() def test_add_method_returns_correct_result(self): self.assertEquals(23, self.calc.add(15,8)) def test_add_method_raises_typeerror_if_values_not_numeric(self): self.assertRaises(TypeError, self.calc.add, 'hello', 'moses')
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() self.statistics = Statistics() def test_calculator_return_sum(self): result = self.calculator.addition(1, 2) self.assertEqual(3, result) def test_statistics_calculator_return_mean(self): data = [1, 2, 3, 4, 5] result = self.statistics.mean(data) self.assertEqual(3, 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): test_data = CsvReader("Tests/Data/addition.csv").data for row in test_data: self.assertEqual( self.calculator.add(int(row['Value 1']), int(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/subtraction.csv").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, int(row['Result'])) 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'])) self.assertEqual(self.calculator.result, 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['Result']) self.assertEqual( self.calculator.divide(int(row['Value 2']), int(row['Value 1'])), round(x, 7)) self.assertEqual(self.calculator.result, round(x, 7)) def test_square_method_calculator(self): test_data = CsvReader("Tests/Data/square.csv").data for row in test_data: self.assertEqual(self.calculator.squaring(int(row['Value 1'])), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) def test_square_rt_method_calculator(self): test_data = CsvReader("Tests/Data/square_root.csv").data for row in test_data: y = float(row['Result']) self.assertEqual(self.calculator.square_rt(int(row['Value 1'])), round(y, 7)) self.assertEqual(self.calculator.result, round(y, 7)) if __name__ == '__main__': unittest.main()
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.Sum(1, 2) self.assertEqual(3, result) def test_calculator_return_sumList(self): numlist = [1, 3, 5, 2] result = self.calculator.Sum(numlist) self.assertEqual(11, result) def test_calculator_return_difference(self): result = self.calculator.Difference(4, 1) self.assertEqual(3, result) def test_MathOperation_Product(self): self.assertEqual(10, self.calculator.Product(2, 5)) def test_MathOperations_Product_list(self): numlist = [1, 3, 5] self.assertEqual(15, self.calculator.Product(numlist)) def test_MathOperations_Power(self): self.assertEqual(8, self.calculator.Power(2, 3)) def test_MathOperations_Power_list(self): numlist = [1, 2, 3] self.assertEqual(9, self.calculator.Power(numlist, 2)) def test_Root(self): self.assertEqual(3, self.calculator.Root(2,9))
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 Addition.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.addRes(row['Value 1'], row['Value 2']), res) self.assertEqual(self.calculator.res, res) def test_division(self): test_data = CsvReader("Tests/Data/Unit Test Division.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.divRes(row['Value 2'], row['Value 1']), res) self.assertEqual(self.calculator.res, res) def test_multiplication(self): test_data = CsvReader("Tests/Data/Unit Test Multiplication.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.multRes(row['Value 1'], row['Value 2']), res) self.assertEqual(self.calculator.res, res) def test_squared(self): test_data = CsvReader("Tests/Data/Unit Test Square.csv").data for row in test_data: res = float(row['Result']) self.assertEqual(self.calculator.squareRes(row['Value 1']), res) self.assertEqual(self.calculator.res, res) def test_squareRoot(self): test_data = CsvReader("Tests/Data/Unit Test Square Root.csv").data for row in test_data: res = float(row['Result']) self.assertEqual(self.calculator.squareRootRes(row['Value 1']), round(res, 8)) self.assertEqual(self.calculator.res, round(res, 8)) def test_subtraction(self): test_data = CsvReader("Tests/Data/Unit Test Subtraction.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.subRes(row['Value 2'], row['Value 1']), res) self.assertEqual(self.calculator.res, res) def test_addSub(self): test_data = CsvReader( "Tests/Data/Unit Test Addition plus Subtraction.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.addSub(row['Value 1'], row['Value 2'], row['Value 3'], row['Value 4']), res) self.assertEqual(self.calculator.res, res) def test_sqrtSquared(self): test_data = CsvReader( "Tests/Data/Unit Test Square Root plus Squared.csv").data for row in test_data: res = float(row['Result']) self.assertEqual(self.calculator.sqrtSquared(row['Value 1']), res) self.assertEqual(self.calculator.res, res) def test_multAdd(self): test_data = CsvReader( "Tests/Data/Unit Test Multiplication plus Addition.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.multAdd(row['Value 1'], row['Value 2'], row['Value 3'], row['Value 4']), res) self.assertEqual(self.calculator.res, res) def test_addSubDiv(self): test_data = CsvReader("Tests/Data/Unit Test Add Sub Div.csv").data for row in test_data: res = float(row['Result']) self.assertEqual( self.calculator.addSubDiv(row['Value 1'], row['Value 2'], row['Value 3'], row['Value 4'], row['Value 5']), res) self.assertEqual(self.calculator.res, res) def test_results_property(self): self.assertEqual(self.calculator.res, 0)
def test_value(): c = Calculator(value=6) ans = c.value assert ans == 6
def setUp(self) -> None: self.statistics = Statistics('Tests/Data/statistics.csv') self.calculator=Calculator()
def __init__(self): Calculator.__init__(self)
def test_set_value(): c = Calculator() c.value = 5 with pytest.raises(ValueError): c.value = 'test text' assert c.value == 5
def setUp(self): self.calculator = Calculator() self.statistics = Statistics()
def test_reset_value(): c = Calculator(value=50) c.reset_value() assert c.value == 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_access_sum_result(self): self.calculator.add(1, 2) self.assertEqual(3, self.calculator.result) def test_calculator_return_difference(self): result = self.calculator.subtract(2, 1) self.assertEqual(-1, result) def test_calculator_access_difference_result(self): self.calculator.subtract(2, 1) self.assertEqual(-1, self.calculator.result) def test_calculator_return_product(self): result = self.calculator.multiply(1, 2) self.assertEqual(2, result) def test_calculator_access_product_result(self): self.calculator.multiply(1, 2) self.assertEqual(2, self.calculator.result) def test_calculator_divide(self): result = self.calculator.divide(5, 10) self.assertEqual(2, result) def test_calculator_root(self): result = self.calculator.squareroot(9) self.assertEqual(3, result) def test_calculator_power(self): result = self.calculator.square(4) self.assertEqual(16, result)
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_cal_return_sum(self): result = self.calculator.add(1, 2) self.assertEqual(3, result) def test_cal_return_diff(self): result = self.calculator.subtract(1, 2) self.assertEqual(-1, result) def test_cal_return_mul(self): result = self.calculator.multiply(1, 2) self.assertEqual(2, result) def test_cal_return_div(self): result = self.calculator.divide(2, 1) self.assertEqual(2, result) def test_cal_return_expo(self): result = self.calculator.exponent(2, 3) self.assertEqual(8, result) def test_cal_return_nroot(self): result = self.calculator.nroot(3, 27) self.assertEqual(3, result) def test_cal_return_log(self): result = self.calculator.log(10, 10) self.assertEqual(1, result) def test_cal_access_sum_result(self): self.calculator.add(1, 2) self.assertEqual(3, self.calculator.result) def test_cal_access_diff_result(self): self.calculator.subtract(1, 2) self.assertEqual(-1, self.calculator.result) def test_cal_access_mul_result(self): self.calculator.multiply(1, 2) self.assertEqual(2, self.calculator.result) def test_cal_access_div_result(self): self.calculator.divide(2, 1) self.assertEqual(2, self.calculator.result) def test_cal_access_exp_result(self): self.calculator.exponent(2, 3) self.assertEqual(8, self.calculator.result) def test_cal_access_nroot_result(self): self.calculator.nroot(3, 27) self.assertEqual(3, self.calculator.result) def test_cal_access_log_result(self): self.calculator.log(10, 10) self.assertEqual(1, self.calculator.result) def test_multiple_cal(self): cal1 = Calculator() cal2 = Calculator() self.calculator.add(cal1.add(1, 2), cal2.subtract(3, 4)) self.assertEqual(2, self.calculator.result)
def test_multiply(): c = Calculator(1000) with pytest.raises(ValueError): c.add('test text') assert c.multiply(5) == 5000
def test_subtract(): c = Calculator(1000) with pytest.raises(ValueError): c.subtract('test text') assert c.subtract(100) == 900
def test_multiple_cal(self): cal1 = Calculator() cal2 = Calculator() self.calculator.add(cal1.add(1, 2), cal2.subtract(3, 4)) self.assertEqual(2, self.calculator.result)
def test_divide(): c = Calculator(1000) with pytest.raises(ValueError): c.add('test text') assert c.divide(10) == 100
def setUp(self): self.calculator = Calculator()
def test_n_root(): c = Calculator(10000) with pytest.raises(ValueError): c.add('test text') assert c.n_root(2) == 100
def setUp(self) -> None: self.calculator = Calculator()
class MyTestCase(unittest.TestCase): def setUp(self): self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_cal_return_sum(self): result = self.calculator.add(1, 2) self.assertEqual(3, result) def test_cal_return_diff(self): result = self.calculator.subtract(1, 2) self.assertEqual(-1, result) def test_cal_return_mul(self): result = self.calculator.multiply(1, 2) self.assertEqual(2, result) def test_cal_return_div(self): result = self.calculator.divide(2, 1) self.assertEqual(2, result) def test_cal_access_sum_result(self): self.calculator.add(1, 2) self.assertEqual(3, self.calculator.result) def test_cal_access_diff_result(self): self.calculator.subtract(1, 2) self.assertEqual(-1, self.calculator.result) def test_cal_access_multi_result(self): self.calculator.multiply(1, 2) self.assertEqual(2, self.calculator.result) def test_cal_access_div_result(self): self.calculator.divide(2, 1) self.assertEqual(2, self.calculator.result) def test_multiple_cals(self): cal1 = Calculator() cal2 = Calculator() self.calculator.add(cal1.add(1, 2), cal2.subtract(3, 4)) self.assertEqual(2, self.calculator.result)