diff --git a/calculator/__init__.py b/calculator/__init__.py index ad8e9df..3b44aa0 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, square_root, exponentiate \ No newline at end of file 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..ab95ec3 100644 --- a/calculator/calcurator.py +++ b/calculator/calculator.py @@ -1,3 +1,6 @@ +import math + + def add(x, y): """Returns the sum of x and y.""" return x + y @@ -16,3 +19,11 @@ def divide(x, y): def subtract(x, y): """Returns the difference between x and y.""" return x - y + +def square_root(x): + """Returns the square root of x.""" + return math.sqrt(x) + +def exponentiate(x, y): + """Returns x raised to the power of y.""" + return x ** y diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index 3295ba8..7cf0586 100644 --- a/calculator/tests/unit_tests_calculator.py +++ b/calculator/tests/unit_tests_calculator.py @@ -1,6 +1,6 @@ # test_calculator.py -from calculator import add, multiply, divide, subtract +from calculator import add, multiply, divide, subtract, square_root, exponentiate def test_addition(): assert add(5, 3) == 8 @@ -21,3 +21,13 @@ def test_subtraction(): assert subtract(10, 7) == 3 assert subtract(5, 5) == 0 assert subtract(7, 10) == -3 + +def test_square_root(): + assert square_root(9) == 3 + assert square_root(0) == 0 + assert square_root(36) == 6 + +def test_exponentiation(): + assert exponentiate(2, 3) == 8 + assert exponentiate(5, 0) == 1 + assert exponentiate(3, -2) == 1/9