class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def tearDown(self): if CsvReader.data is not None: CsvReader.data = [] def test_divide_method_calculator(self): self.test_data = CsvReader( 'src/Tests/CalculatorTests/data/division.csv').data for row in self.test_data: self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertRaises(ZeroDivisionError, self.calculator.divide('0', row['Value 2']))
class CalculatorTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def test_instantiate_calculator(self): self.assertIsInstance(self.calculator, Calculator) def test_sum(self): self.assertEqual(self.calculator.sum(3, 4), 7) def test_difference(self): self.assertEqual(self.calculator.difference(1, 4), -3) def test_product(self): self.assertEqual(self.calculator.product(3, 9), 27) def test_quotient(self): self.assertEqual(self.calculator.quotient(10, 100), 10) def test_power(self): self.assertEqual(self.calculator.power(5, 3), 125) def test_root(self): self.assertEqual(self.calculator.rt(25), 5) def test_log(self): self.assertEqual(self.calculator.log(10, 1), 0)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def tearDown(self): if CsvReader.data is not None: CsvReader.data = [] def test_square_root_method_calculator(self): self.test_data = CsvReader('src/Tests/CalculatorTests/data/squareRoot.csv').data for row in self.test_data: self.assertEqual(self.calculator.square_root(row['Value 1']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.calculator = Calculator() def tearDown(self): if CsvReader.data is not None: CsvReader.data = [] def test_add_method_calculator(self): self.test_data = CsvReader('src/Tests/CalculatorTests/data/addition.csv').data for row in self.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 setUp(self) -> None: self.calculator = Calculator()
def test_instantiate_calculator(self): self.calculator = Calculator() self.assertIsInstance(self.calculator, Calculator)
def test_results_property_calculator(self): self.calculator = Calculator() self.assertEqual(self.calculator.result, 0)