Ejemplo n.º 1
0
class CalculatorTest(unittest.TestCase):
    def setUp(self):
        self.calc = Calculator()

    def test_last_answer_init(self):
        value = self.calc.last_answer
        self.assertEqual(value, 0.0, FAILURE)

    def test_add(self):
        value = self.calc.add(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 6.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_subtract(self):
        value = self.calc.subtract(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 1.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_subtract_negative(self):
        value = self.calc.subtract(NUMBER_2, NUMBER_1)
        self.assertEqual(value, -1.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_multiply(self):
        value = self.calc.multiply(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 6.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_divide(self):
        value = self.calc.divide(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 1.5, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_divide_by_zero(self):
        self.assertRaises(ZeroDivisionError, self.calc.divide, NUMBER_1, 0)
Ejemplo n.º 2
0
class CalcTestCase(unittest.TestCase):
    def setUp(self):
        self.C = Calculator()

    def test_multiplication_with_ints(self):
        self.assertEqual(self.C.multiply(5, 5), 25)

    def test_add_with_ints(self):
        self.assertEqual(self.C.add(1, 5), 6)
        self.assertEqual(self.C.add(2, 2), 4)

    def test_div(self):
        self.assertEqual(self.C.div(10, 2), 5)
Ejemplo n.º 3
0
 def test_multiply(self):
     cases = [
         {
             'first': 5,
             'second': 5,
             'expected': 25,
         },
         {
             'first': 0,
             'second': 0,
             'expected': 0,
         },
         {
             'first': 200,
             'second': 4,
             'expected': 800,
         },
         {
             'first': -5,
             'second': 9,
             'expected': -45,
         },
         {
             'first': 5,
             'second': -9,
             'expected': -45,
         },
         {
             'first': 0,
             'second': 100000,
             'expected': 0,
         },
     ]
     for case in cases:
         first = case['first']
         second = case['second']
         self.assertEqual(case['expected'],
                          Calculator.multiply(first, second))
Ejemplo n.º 4
0
class TestCalculator(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print("Set up class")
        self.calc = Calculator()
        # Create an instance of the calculator that can be used in all tests

    @classmethod
    def tearDownClass(self):
        print("Tear down class")

    def test_add(self):
        self.assertEqual(self.calc.add(2, 7), 9)

    # Write test methods for subtract, multiply, and divide

    def test_subtract(self):
        self.assertEqual(self.calc.subtract(7, 2), 5)

    def test_multiply(self):
        self.assertEqual(self.calc.multiply(2, 4), 8)

    def test_divide(self):
        self.assertEqual(self.calc.divide(8, 2), 4)
class CalculatorTest(unittest.TestCase):
    def setUp(self):
        self.calc = Calculator()

    def test_last_answer_init(self):
        value = self.calc.last_answer
        self.assertEqual(value, 0.0, FAILURE)

    def test_add(self):
        value = self.calc.add(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 5.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_subtract(self):
        value = self.calc.subtract(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 1.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_subtract_negative(self):
        value = self.calc.subtract(NUMBER_2, NUMBER_1)
        self.assertEqual(value, -1.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_multiply(self):
        value = self.calc.multiply(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 6.0, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_divide(self):
        value = self.calc.divide(NUMBER_1, NUMBER_2)
        self.assertEqual(value, 1.5, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_divide_by_zero(self):
        self.assertRaises(ZeroDivisionError, self.calc.divide, NUMBER_1, 0)

    def test_max_greater(self):
        value = self.calc.maximum(NUMBER_1, NUMBER_2)
        self.assertEqual(value, NUMBER_1, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_max_less(self):
        value = self.calc.maximum(NUMBER_2, NUMBER_1)
        self.assertEqual(value, NUMBER_1, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_max_equal(self):
        value = self.calc.maximum(NUMBER_1, NUMBER_1)
        self.assertEqual(value, NUMBER_1, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_min_greater(self):
        value = self.calc.minimum(NUMBER_1, NUMBER_2)
        self.assertEqual(value, NUMBER_2, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_min_less(self):
        value = self.calc.minimum(NUMBER_2, NUMBER_1)
        self.assertEqual(value, NUMBER_2, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_min_equal(self):
        value = self.calc.minimum(NUMBER_2, NUMBER_2)
        self.assertEqual(value, NUMBER_2, FAILURE)
        self.assertEqual(value, self.calc.last_answer, FAILURE)

    def test_force_value(self):
        self.calc._last_answer = 5
        value = self.calc._last_answer
        self.assertEqual(value, 5, FAILURE)

    def tearDown(self):
        pass
Ejemplo n.º 6
0
 def test_multiply(self):
     # Test multiply
     self.assertAlmostEqual(Calculator.multiply(2, 4), 8)
     self.assertAlmostEqual(Calculator.multiply(5, 5), 25)
     self.assertAlmostEqual(Calculator.multiply(3.3, 6.5), 21.45)
Ejemplo n.º 7
0
def test_multiply():
    calculator = Calculator()
    assert calculator.multiply(5, 1) == 5
    assert calculator.multiply(1, -3) == -3
    assert calculator.multiply(0, 2) == 0
Ejemplo n.º 8
0
def test_mul():
    calc = Calculator()

    assert calc.multiply(5, 5) == 25
    assert calc.multiply(5, -5) == -25
    assert calc.multiply(5, '$') == 'invalid input'