From 8bdb5073c4b28b50a176b8aa82132e29d3c53502 Mon Sep 17 00:00:00 2001 From: kieuoanh-nguyen Date: Mon, 9 Oct 2023 12:01:25 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=85=20Add=20functions=20for=20exponen?= =?UTF-8?q?tiating=20and=20square=5Froot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/__init__.py | 2 +- calculator/calcurator.py | 9 +++++++++ calculator/tests/unit_tests_calculator.py | 12 +++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/calculator/__init__.py b/calculator/__init__.py index ad8e9df..070dec8 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, exponentiate, square_root \ No newline at end of file diff --git a/calculator/calcurator.py b/calculator/calcurator.py index 51cb993..4e8cb3a 100644 --- a/calculator/calcurator.py +++ b/calculator/calcurator.py @@ -1,3 +1,5 @@ +import math + def add(x, y): """Returns the sum of x and y.""" return x + y @@ -16,3 +18,10 @@ def divide(x, y): def subtract(x, y): """Returns the difference between x and y.""" return x - y + +def exponentiate (x,y): + return x**y + +def square_root (x): + return math.sqrt(x) + diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index 3295ba8..82598ab 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, exponentiate, square_root 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_exponentiation(): + assert exponentiate(2, 3) == 8 + assert exponentiate(5, 0) == 1 + assert exponentiate(3, -2) == 1/9 + +def test_square_root(): + assert square_root(4) == 2 + assert square_root(25) == 5 + assert square_root(9) == 3 \ No newline at end of file From bd890bab036dea5a802843da29a87ccac53d8750 Mon Sep 17 00:00:00 2001 From: kieuoanh-nguyen Date: Mon, 9 Oct 2023 12:26:25 +0200 Subject: [PATCH 2/4] fixed type --- calculator/tests/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/calculator/tests/__init__.py b/calculator/tests/__init__.py index e69de29..80e6b02 100644 --- a/calculator/tests/__init__.py +++ b/calculator/tests/__init__.py @@ -0,0 +1 @@ +from .calculator import add, subtract, divide, multiply, exponentiate, square_root \ No newline at end of file From 32b40b4c159b535299b8f1a58c12fb342d5dbb85 Mon Sep 17 00:00:00 2001 From: kieuoanh-nguyen Date: Mon, 9 Oct 2023 12:28:40 +0200 Subject: [PATCH 3/4] update name --- calculator/__init__.py | 1 - calculator/{calcurator.py => calculator.py} | 0 2 files changed, 1 deletion(-) delete mode 100644 calculator/__init__.py rename calculator/{calcurator.py => calculator.py} (100%) diff --git a/calculator/__init__.py b/calculator/__init__.py deleted file mode 100644 index 070dec8..0000000 --- a/calculator/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .calcurator import add, subtract, divide, multiply, exponentiate, square_root \ 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 From 1258a5858f04584fc2d4ccb3aec6d4f7ac5cd2f3 Mon Sep 17 00:00:00 2001 From: kieuoanh-nguyen Date: Mon, 9 Oct 2023 12:31:50 +0200 Subject: [PATCH 4/4] relocate --- calculator/{tests => }/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename calculator/{tests => }/__init__.py (100%) diff --git a/calculator/tests/__init__.py b/calculator/__init__.py similarity index 100% rename from calculator/tests/__init__.py rename to calculator/__init__.py