From 14c7de516b59a4d8bb8da6d5bde904ea2ff1120f Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Sat, 27 Jan 2024 15:58:09 +0100 Subject: [PATCH] added test for dividing the roots of two negative numbers and functionality to filter out corresponding math errors --- src/main/py/calculations_with_roots.py | 2 ++ src/test/py/test_calculations_with_roots.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/main/py/calculations_with_roots.py b/src/main/py/calculations_with_roots.py index 2bd92a8..da59537 100644 --- a/src/main/py/calculations_with_roots.py +++ b/src/main/py/calculations_with_roots.py @@ -6,6 +6,8 @@ def multiplyRoots(first_number, second_number): return sqrt(first_number * second_number) def divideRoots(first_number, second_number): + if first_number < 0 or second_number < 0: + return -1 return sqrt(first_number / second_number) def sqrt_power(base, exponent): diff --git a/src/test/py/test_calculations_with_roots.py b/src/test/py/test_calculations_with_roots.py index 7c672d9..6e10384 100644 --- a/src/test/py/test_calculations_with_roots.py +++ b/src/test/py/test_calculations_with_roots.py @@ -21,6 +21,9 @@ class calculationsWithRoots(unittest.TestCase): def test_divide_sqrt_16_by_sqrt_4_should_be_2(self): self.assertEqual(divideRoots(16,4), 2) + def test_divide_sqrt_negative_16_by_sqrt_negative_4_should_be_negative_1_for_error(self): + self.assertEqual(divideRoots(-16,-4), -1) + def test_sqrt_4_to_power_of_3_should_be_8(self): self.assertEqual(sqrt_power(4, 3), 8)