From 3e30d191eeceeacbe59382d18c42f0575aad937a Mon Sep 17 00:00:00 2001 From: mgardzinski Date: Thu, 4 Apr 2024 16:57:29 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=8E=A8=20Fixed=20`calculator`=20name?= =?UTF-8?q?=20and=20=20static=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/__init__.py | 2 +- calculator/{calcurator.py => calculator.py} | 3 +++ calculator/tests/unit_tests_calculator.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) rename calculator/{calcurator.py => calculator.py} (99%) diff --git a/calculator/__init__.py b/calculator/__init__.py index ad8e9df..cb601c3 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 diff --git a/calculator/calcurator.py b/calculator/calculator.py similarity index 99% rename from calculator/calcurator.py rename to calculator/calculator.py index 51cb993..3a3b716 100644 --- a/calculator/calcurator.py +++ b/calculator/calculator.py @@ -2,10 +2,12 @@ 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 +15,7 @@ def divide(x, y): else: return "Error: Division by zero" + def subtract(x, y): """Returns the difference between x and y.""" return x - y diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index 3295ba8..a12925e 100644 --- a/calculator/tests/unit_tests_calculator.py +++ b/calculator/tests/unit_tests_calculator.py @@ -2,21 +2,25 @@ from calculator import add, multiply, divide, subtract + 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 From bf3d40e715525b51f7ad61079f1d7e6351dd7d0c Mon Sep 17 00:00:00 2001 From: mgardzinski Date: Thu, 4 Apr 2024 17:00:16 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20Added=20`exponentiate`=20functi?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/__init__.py | 2 +- calculator/calculator.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/calculator/__init__.py b/calculator/__init__.py index cb601c3..1c71c71 100644 --- a/calculator/__init__.py +++ b/calculator/__init__.py @@ -1 +1 @@ -from .calculator import add, subtract, divide, multiply +from .calculator import add, subtract, divide, multiply, exponentiate diff --git a/calculator/calculator.py b/calculator/calculator.py index 3a3b716..7e52000 100644 --- a/calculator/calculator.py +++ b/calculator/calculator.py @@ -19,3 +19,8 @@ def divide(x, y): 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 From 1e6d95524d32934aec0ec1509e9e9c012a01d49f Mon Sep 17 00:00:00 2001 From: mgardzinski Date: Thu, 4 Apr 2024 17:04:11 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=85=20Added=20`test=5Fexponentiate`?= =?UTF-8?q?=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/tests/unit_tests_calculator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index a12925e..b9913fa 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 def test_addition(): @@ -25,3 +25,9 @@ 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 From f0a4fefb233439e2de26364367ae9e96aaa11cc8 Mon Sep 17 00:00:00 2001 From: mgardzinski Date: Fri, 5 Apr 2024 11:14:06 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=85=20Added=20`test=5Froot=5Fsquare`?= 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 | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/calculator/__init__.py b/calculator/__init__.py index 1c71c71..3a66ee4 100644 --- a/calculator/__init__.py +++ b/calculator/__init__.py @@ -1 +1 @@ -from .calculator import add, subtract, divide, multiply, exponentiate +from .calculator import add, subtract, divide, multiply, exponentiate, root_square diff --git a/calculator/tests/unit_tests_calculator.py b/calculator/tests/unit_tests_calculator.py index b9913fa..2f11441 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, exponentiate +from calculator import add, multiply, divide, subtract, exponentiate, root_square def test_addition(): @@ -31,3 +31,9 @@ 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 From cc4c73fcc1716f062e6d18d2abdef0088be8764e Mon Sep 17 00:00:00 2001 From: mgardzinski Date: Fri, 5 Apr 2024 11:35:29 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=A8=20Added=20`root=5Fsquare`=20funct?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculator/calculator.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/calculator/calculator.py b/calculator/calculator.py index 7e52000..fab219c 100644 --- a/calculator/calculator.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 @@ -24,3 +27,8 @@ def subtract(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)