Exemplo n.º 1
0
class CalculatorTests(TestCase):
    def setUp(self):
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)
Exemplo n.º 2
0
class CalculatorTests(TestCase):
    """Tests for calculator method"""
    def setUp(self):
        """setup for calculator tests"""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        """error raised when only one number entered"""
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        """tests adder method is called correctly"""
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        """tests subtracter method is called correctly"""
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)

    def test_divider_call(self):
        """tests divider method is called correctly"""
        self.divider.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.divide()

        self.divider.calc.assert_called_with(1, 2)

    def test_multiplier_call(self):
        """tests multiplier method is called correctly"""
        self.multiplier.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.multiply()

        self.multiplier.calc.assert_called_with(1, 2)
Exemplo n.º 3
0
class CalculatorTests(TestCase):
    """Unit test for initiating the calculator"""
    def setUp(self):
        """Initializes the calculator"""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        """Tests if there's sufficient operands"""
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        """Test if the add functions adds in correct order"""
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        """Test if the subtract functions adds in correct order"""
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)

    def test_multiplier_call(self):
        """Test if the multiply functions adds in correct order"""
        self.multiplier.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.multiply()

        self.multiplier.calc.assert_called_with(1, 2)

    def test_divider_call(self):
        """Test if the divide functions adds in correct order"""
        self.divider.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.divide()

        self.divider.calc.assert_called_with(1, 2)
Exemplo n.º 4
0
class CalculatorTests(TestCase):
    def setUp(self):
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_multiplier(self):
        lis = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        answers = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]
        index = 0
        for nums in enumerate(lis, 1):
            x, y = nums
            self.calculator.enter_number(x)
            self.calculator.enter_number(y)
            result = self.calculator.multiply()
            self.assertEqual(answers[index], result)
            index += 1

    def test_divider(self):
        lis = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]
        answers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        index = 0
        for nums in enumerate(lis, 1):
            x, y = nums
            self.calculator.enter_number(y)
            self.calculator.enter_number(x)
            result = self.calculator.divide()
            self.assertEqual(answers[index], result)
            index += 1

    def test_insufficient_operands(self):
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)
Exemplo n.º 5
0
class CalculatorTests(TestCase):
    def setUp(self):
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()
        # Numbers are inserted at index 0.  Either switch this or switch the
        # calc function call order.
        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)

    def test_multiplier_call(self):
        self.multiplier.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.multiply()

        self.multiplier.calc.assert_called_with(1, 2)

    def test_divider_call(self):
        self.divider.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.divide()

        self.divider.calc.assert_called_with(1, 2)
Exemplo n.º 6
0
class CalculatorTests(TestCase):
    """
    This class tests mocking
    """
    def setUp(self):
        """
        This method initializes variables
        """
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        """
        This method tests InsufficientOperands
        """
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        """
        This method tests mock adder
        """
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        """
        This method tests mock subtracter
        """
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)
    def test_module(self):
        """
        Test the Adder, Subtracter, Multiplier, Divider classes and
        the Calculator class concurrently.
        """
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
class TestCalculator(unittest.TestCase):
    def setUp(self):
        self.calculator = Calculator()

    def test_add_given_two_values_should_return_the_correct_value(self):
        result = self.calculator.add(10, 10)

        self.assertEqual(first=result,
                         second=20,
                         msg='Invalid sum operation performed.')

    def test_subtract_given_two_values_should_return_the_correct_value(self):
        result = self.calculator.subtract(10, 10)

        self.assertEqual(first=result,
                         second=0,
                         msg='Invalid subtract operation performed.')

    def test_multiply_given_two_values_should_return_the_correct_value(self):
        result = self.calculator.multiply(10, 10)

        self.assertEqual(first=result,
                         second=100,
                         msg='Invalid multiply operation performed.')

    def test_divide_given_two_values_should_return_the_correct_value(self):
        result = self.calculator.divide(10, 10)

        self.assertEqual(first=result,
                         second=1,
                         msg='Invalid divide operation performed.')
Exemplo n.º 9
0
    def test_module(self):
        """Test that a sequence of operations produces the expected result."""
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)

        with self.assertRaises(InsufficientOperands):
            calculator.add()
Exemplo n.º 10
0
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        result = calculator.multiply()

        self.assertEqual((2*5), result)

        calculator.enter_number(46)

        result = calculator.add()

        self.assertEqual(result, (46+(2*5)))

        calculator.enter_number(8)

        result = calculator.divide()

        self.assertEqual(result, (8 / (46+(2*5))))

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(result, (1 - (8 / (46+(2*5)))))
Exemplo n.º 11
0
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        result_add = calculator.add()

        self.assertEqual(56, result_add)

        calculator.enter_number(8)

        result_divide = calculator.divide()

        self.assertEqual(7, result_divide)

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
Exemplo n.º 12
0
class ModuleTests(TestCase):
    """Test the calculator module/UI during random, sustained usage."""
    def setUp(self):
        self.calculator = Calculator(a(), s(), m(), d())

    def test_module(self):
        """
        Make sure the calculator returns the correct value after a
        series of random number entries and operations.
        """
        self.calculator.enter_number(5)
        self.calculator.enter_number(2)

        self.calculator.multiply()

        self.calculator.enter_number(46)

        self.calculator.add()

        self.calculator.enter_number(8)

        self.calculator.divide()

        self.calculator.enter_number(1)

        result = self.calculator.subtract()

        self.assertEqual(6, result)

    def test_after_division_by_zero(self):
        """
        Make sure an insufficient operands exception occurs if a user
        immediately invokes an operation after a division by zero error
        without specifying another number. (Following a division by
        zero, the stack is cleared, and only a zero is left there.)
        """
        self.calculator.enter_number(15)
        self.calculator.enter_number(5)
        self.calculator.enter_number(0)
        self.calculator.divide()  # Div by 0 clears stack and pushes 0
        with self.assertRaises(InsufficientOperands):
            self.calculator.subtract()
        self.calculator.enter_number(8)
        result = self.calculator.subtract()
        self.assertEqual(-8, result)
    def test_module_insufficient_operands(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        with self.assertRaises(InsufficientOperands):
            calculator.subtract()
Exemplo n.º 14
0
class CalculatorTests(TestCase):
    def setUp(self):
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        self.adder.calc = MagicMock(return_value=(2 + 1))

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        result = self.calculator.add()

        self.adder.calc.assert_called_with(2, 1)
        self.assertEqual(result, (2 + 1))

    def test_subtracter_call(self):
        self.subtracter.calc = MagicMock(return_value=(2 - 1))

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        result = self.calculator.subtract()

        self.subtracter.calc.assert_called_with(2, 1)
        self.assertEqual(result, (2 - 1))

    def test_multiplier_call(self):
        self.multiplier.calc = MagicMock(return_value=(2 * 1))

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        result = self.calculator.multiply()

        self.multiplier.calc.assert_called_with(2, 1)
        self.assertEqual(result, (2 * 1))

    def test_divider_call(self):
        self.divider.calc = MagicMock(return_value=(2 / 1))

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        result = self.calculator.divide()

        self.divider.calc.assert_called_with(2, 1)
        self.assertEqual(result, (2 / 1))
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.calculator = Calculator()

    # Unit test 1
    def test_instantiate_calculator(self):
        self.assertIsInstance(self.calculator, Calculator)

    # Unit test 2
    def test_subtraction(self):
        test_data = CsvReader( BASE_DIR + "/data/UnitTestSubtraction.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)

    # Unit test 3
    def test_addition(self):
        test_data = CsvReader(BASE_DIR + "/data/UnitTestAddition.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)

    # Unit test 4
    def test_multiplication(self):
        test_data = CsvReader(BASE_DIR + "/data/UnitTestMultiplication.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)

    # Unit test 5
    def test_division(self):
        test_data = CsvReader(BASE_DIR + "/data/UnitTestDivision.csv").data
        for row in test_data:
            result = float(row['Result'])
            self.assertEqual(round(self.calculator.divide(row['Value 1'], row['Value 2'])), round(result))
            self.assertEqual(round(self.calculator.result), round(result))

    # Unit test 6
    def test_square(self):
        test_data = CsvReader(BASE_DIR + "/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)

    # Unit test 7
    def test_square_root(self):
        test_data = CsvReader(BASE_DIR + "/data/UnitTestSquareRoot.csv").data
        for row in test_data:
            result = float(row['Result'])
            self.assertEqual(round(self.calculator.squareroot(row['Value 1'])), round(result))
            self.assertEqual(round(self.calculator.result), round(result))
    def test_module_zero_division_error(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.subtract()

        calculator.enter_number(0)

        with self.assertRaises(ZeroDivisionError):
            calculator.divide()
Exemplo n.º 17
0
class CalculatorTests(TestCase):
    """Contain tests for Calculator class."""
    def setUp(self):
        """Initialize calculator with new operator objects."""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        """Test Insufficient Operands exception."""
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        """Test a call to the Adder function using MagicMock."""
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(2, 1)

    def test_subtracter_call(self):
        """Test a call to the Divider function using MagicMock."""
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(2, 1)
class CalculatorTests(TestCase):
    """Series of Calculator Tests"""
    def setUp(self):
        """Test case that setups the other test cases from range -10 to 10"""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        """Test insufficient operands"""
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        """Test Case Adds Two Numbers"""
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        """Test Case Subtracts Two Numbers"""
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)
Exemplo n.º 19
0
 def test_module(self):
     """
     Testing the calculator by calling each methods
     """
     calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())
     calculator.enter_number(5)
     calculator.enter_number(2)
     calculator.multiply()
     calculator.enter_number(46)
     calculator.add()
     calculator.enter_number(8)
     calculator.divide()
     calculator.enter_number(1)
     result = calculator.subtract()
     self.assertEqual(6, result)
Exemplo n.º 20
0
class CalculatorTests(TestCase):
    """various test"""
    def setUp(self):
        """Set up for calc tests so don't have to rewrite"""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()
        # Line is too long, but whatever.
        self.calculator = Calculator(self.adder, self.subtracter, self.multiplier, self.divider)

    def test_insufficient_operands(self):
        """Will it  raise an error when there aren't enough operands?"""
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        """Does adder call adder in the right order?"""
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        """Does subtractor call subtractor in the right order?"""
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()
        self.subtracter.calc.assert_called_with(1, 2)
Exemplo n.º 21
0
    def test_module(self):
        '''Runs the actual integration test, going through all calculator calls
        and testing the end result'''

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())
        calculator.enter_number(5)
        calculator.enter_number(2)
        calculator.multiply()
        calculator.enter_number(46)
        calculator.add()
        calculator.enter_number(8)
        calculator.divide()
        calculator.enter_number(1)
        result = calculator.subtract()
        assert result == 6
Exemplo n.º 22
0
class CalculatorTests(TestCase):
    def setUp(self):
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)

    def test_insufficient_operands(self):
        self.calculator.enter_number(0)

        with self.assertRaises(InsufficientOperands):
            self.calculator.add()

    def test_adder_call(self):
        # Why we use Mock here?
        # Instead of calling adder, we are going to pretend, so we are tesing
        # the code that is actually in the calculator
        self.adder.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.add()

        self.adder.calc.assert_called_with(1, 2)

    def test_subtracter_call(self):
        self.subtracter.calc = MagicMock(return_value=0)

        self.calculator.enter_number(1)
        self.calculator.enter_number(2)
        self.calculator.subtract()

        self.subtracter.calc.assert_called_with(1, 2)
Exemplo n.º 23
0
 def result():
     first_term = request.form.get("first_term", type=int)
     second_term = request.form.get("second_term", type=int)
     operation = request.form.get("operation")
     c = Calculator(first_term, second_term)
     if operation == 'Add':
         res = c.add()
     elif operation == 'Subtract':
         res = c.subtract()
     elif operation == 'Multiply':
         res = c.multiply()
     elif operation == 'Divide':
         res = c.divide()
     else:
         res = 'INVALID CHOICE'
     return render_template('result.html', result=res)
Exemplo n.º 24
0
    def test_module(self):
        """The first of... one test module(s). lol lazy."""
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
    def test_module(self):
        "Tests Addition, multiplication, subtraction, division" ""
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
    def test_module(self):
        '''doc string'''
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(56)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(0, result)
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        # Tests
        # Add:
        self.assertEqual(7, calculator.add())

        # Subtract:
        calculator.enter_number(5)
        self.assertEqual(2, calculator.subtract())

        # Multiply:
        calculator.enter_number(5)
        self.assertEqual(10, calculator.multiply())

        # Divide:
        calculator.enter_number(1)
        self.assertEqual(10, calculator.divide())
Exemplo n.º 28
0
    def test_module(self):
        """ Tests each module against an expected output to ensure accuracy. """
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        # Tests
        # Add:
        self.assertEqual(7, calculator.add())

        # Subtract:
        calculator.enter_number(5)
        self.assertEqual(2, calculator.subtract())

        # Multiply:
        calculator.enter_number(5)
        self.assertEqual(10, calculator.multiply())

        # Divide:
        calculator.enter_number(1)
        self.assertEqual(10, calculator.divide())
    def test_module(self):
        """Tests all calculator modules."""

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()  #10

        calculator.enter_number(46)

        calculator.add()  #56

        calculator.enter_number(8)

        calculator.divide()  #7

        calculator.enter_number(1)

        result = calculator.subtract()  #6

        self.assertEqual(6, result)  #Result should equal 6
    def test_module(self):
        """Test that calculator performs operations as expected"""

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)