solutions

OOP Calculator

The objective of the following assignment is to build a simple calculator using Object Oriented Programming.

This is the interface it should follow:

calculator = Calculator()

calculator.add(2, 4)  # 6
calculator.subtract(8, 1)  # 7
calculator.multiply(3, 5)  # 15
calculator.divide(5, 2)  # 2.5

Test Cases

test subtract - Run Test

def test_subtract():
    calc = Calculator()
    assert calc.subtract(5, 2) == 3

test divide - Run Test

def test_divide():
    calc = Calculator()
    assert calc.divide(9, 3) == 3.0

test multiply - Run Test

def test_multiply():
    calc = Calculator()
    assert calc.multiply(7, 9) == 63

test add - Run Test

def test_add():
    calc = Calculator()
    assert calc.add(5, 2) == 7

test divide decimal - Run Test

def test_divide_decimal():
    calc = Calculator()
    assert calc.divide(9, 2) == 4.5