From 93cf931baeff3af154b1de9918b15a72d061eaa2 Mon Sep 17 00:00:00 2001 From: Gguidini Date: Thu, 14 Dec 2023 15:34:56 -0300 Subject: [PATCH] exponentiation --- app/calculator.py | 3 +++ app/test_calculator.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/calculator.py b/app/calculator.py index 8a976b25..9bff13f8 100644 --- a/app/calculator.py +++ b/app/calculator.py @@ -13,3 +13,6 @@ def divide(x, y): if y == 0: return 'Cannot divide by 0' return x * 1.0 / y + + def exponent(x, y): + return x ** y \ No newline at end of file diff --git a/app/test_calculator.py b/app/test_calculator.py index f5641938..cf9ddd70 100644 --- a/app/test_calculator.py +++ b/app/test_calculator.py @@ -29,3 +29,8 @@ def test_divide(): assert Calculator.divide(0, 2.0) == 0 assert Calculator.divide(-4, 2.0) == -2.0 # assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0' + +def test_exponent(): + assert Calculator.exponent(2, 2) == 4 + assert Calculator.exponent(3, 2) == 9 + assert Calculator.exponent(5, 2) == 25 \ No newline at end of file