diff --git a/calculator/__init__.py b/calculator/__init__.py index ad8e9df..3a66ee4 100644 --- a/calculator/__init__.py +++ b/calculator/__init__.py @@ -1 +1 @@ -from .calcurator import add, subtract, divide, multiply \ No newline at end of file +from .calculator import add, subtract, divide, multiply, exponentiate, root_square diff --git a/calculator/calcurator.py b/calculator/calculator.py similarity index 67% rename from calculator/calcurator.py rename to calculator/calculator.py index 51cb993..fab219c 100644 --- a/calculator/calcurator.py +++ b/calculator/calculator.py @@ -1,11 +1,16 @@ +import math + + def add(x, y): """Returns the sum of x and y.""" return x + y + def multiply(x, y): """Returns the product of x and y.""" return x * y + def divide(x, y): """Returns the result of dividing x by y.""" if y != 0: @@ -13,6 +18,17 @@ def divide(x, y): else: return "Error: Division by zero" + def subtract(x, y): """Returns the difference between x and y.""" return x - y + + +def exponentiate(x, y): + """Returns x raised to the power of y.""" + return x**y + + +def root_square(x): + """Returns the square root of x.""" + return math.sqrt(x) diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index 3295ba8..2f11441 100644 --- a/calculator/tests/unit_tests_calculator.py +++ b/calculator/tests/unit_tests_calculator.py @@ -1,23 +1,39 @@ # test_calculator.py -from calculator import add, multiply, divide, subtract +from calculator import add, multiply, divide, subtract, exponentiate, root_square + def test_addition(): assert add(5, 3) == 8 assert add(0, 0) == 0 assert add(-5, 5) == 0 + def test_multiplication(): assert multiply(4, 6) == 24 assert multiply(0, 10) == 0 assert multiply(-3, 7) == -21 + def test_division(): assert divide(8, 2) == 4.0 assert divide(10, 5) == 2.0 assert divide(7, 0) == "Error: Division by zero" + def test_subtraction(): assert subtract(10, 7) == 3 assert subtract(5, 5) == 0 assert subtract(7, 10) == -3 + + +def test_exponentiate(): + assert exponentiate(2, 2) == 4 + assert exponentiate(-3, 3) == -27 + assert exponentiate(9, 0) == 1 + + +def test_root_square(): + assert root_square(4) == 2 + assert root_square(25) == 5 + assert root_square(9) == 3