From 14a79a280fc0986fddd08cd58027b76520ba9381 Mon Sep 17 00:00:00 2001 From: mlodydodek Date: Fri, 5 Apr 2024 17:17:17 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20Added=20a=20feature=20to=20calc?= =?UTF-8?q?ulate=20root=20square=20of=20a=20number?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/calcurator.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/calculator/calcurator.py b/calculator/calcurator.py index 51cb993..01e54b5 100644 --- a/calculator/calcurator.py +++ b/calculator/calcurator.py @@ -1,3 +1,6 @@ +import math + + def add(x, y): """Returns the sum of x and y.""" return x + y @@ -16,3 +19,7 @@ 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) From 4f429a500fb935e9827ea9bd09e59bafcfd90205 Mon Sep 17 00:00:00 2001 From: mlodydodek Date: Fri, 5 Apr 2024 17:20:38 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=85=20Added=20tests=20for=20square=5F?= =?UTF-8?q?root()=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/__init__.py | 2 +- calculator/tests/unit_tests_calculator.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/calculator/__init__.py b/calculator/__init__.py index ad8e9df..a89fc5a 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 .calcurator import add, subtract, divide, multiply, square_root \ No newline at end of file diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index 3295ba8..95fb7fd 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 def test_addition(): assert add(5, 3) == 8 @@ -21,3 +21,8 @@ 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 From 454e75d081e80427caf5e78c454c7c6e749faa75 Mon Sep 17 00:00:00 2001 From: mlodydodek Date: Fri, 5 Apr 2024 17:24:08 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20Added=20a=20feautre=20to=20calc?= =?UTF-8?q?ulate=20power=20of=20one=20number=20with=20another?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/calcurator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/calculator/calcurator.py b/calculator/calcurator.py index 01e54b5..ab95ec3 100644 --- a/calculator/calcurator.py +++ b/calculator/calcurator.py @@ -23,3 +23,7 @@ def subtract(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 From 091a69de08a6247d950e2ecdf55b8432cd20bb22 Mon Sep 17 00:00:00 2001 From: mlodydodek Date: Fri, 5 Apr 2024 17:24:32 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=85=20Added=20tests=20for=20exponenti?= =?UTF-8?q?ation()=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/__init__.py | 2 +- calculator/tests/unit_tests_calculator.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/calculator/__init__.py b/calculator/__init__.py index a89fc5a..aa9bd74 100644 --- a/calculator/__init__.py +++ b/calculator/__init__.py @@ -1 +1 @@ -from .calcurator import add, subtract, divide, multiply, square_root \ No newline at end of file +from .calcurator import add, subtract, divide, multiply, square_root, exponentiate \ No newline at end of file diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index 95fb7fd..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, square_root +from calculator import add, multiply, divide, subtract, square_root, exponentiate def test_addition(): assert add(5, 3) == 8 @@ -26,3 +26,8 @@ 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 From 0aa4c9351d8f1ce9194299b8f71c48546426ad88 Mon Sep 17 00:00:00 2001 From: mlodydodek Date: Fri, 5 Apr 2024 17:28:07 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=8E=A8=20Fixed=20a=20typo=20in=20calc?= =?UTF-8?q?ulator.py=20file=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/__init__.py | 2 +- calculator/{calcurator.py => calculator.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename calculator/{calcurator.py => calculator.py} (100%) diff --git a/calculator/__init__.py b/calculator/__init__.py index aa9bd74..3b44aa0 100644 --- a/calculator/__init__.py +++ b/calculator/__init__.py @@ -1 +1 @@ -from .calcurator import add, subtract, divide, multiply, square_root, exponentiate \ 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 100% rename from calculator/calcurator.py rename to calculator/calculator.py