From f766ce85a9dc0a770019c2e2f0958798080c9ff0 Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Sat, 27 Jan 2024 13:51:58 +0100 Subject: [PATCH] added test to check if multiplication of two roots with both negative numbers returns minus1 to indicate error as well as corresponding functionality --- 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 fb73efe..75c27b4 100644 --- a/src/main/py/calculations_with_roots.py +++ b/src/main/py/calculations_with_roots.py @@ -1,4 +1,6 @@ import math def multiplyRoots(first_number, second_number): + if first_number < 0 or second_number < 0: + return -1 return math.sqrt(first_number * second_number) \ No newline at end of file diff --git a/src/test/py/test_calculations_with_roots.py b/src/test/py/test_calculations_with_roots.py index 17fb5c2..66fc1e1 100644 --- a/src/test/py/test_calculations_with_roots.py +++ b/src/test/py/test_calculations_with_roots.py @@ -15,6 +15,9 @@ class calculationsWithRoots(unittest.TestCase): def test_sqrt_2_times_sqrt_8_should_be_4(self): self.assertEqual(multiplyRoots(2, 8), 4) + def test_sqrt_negative_2_times_sqrt_negative_8_should_be_negative_one_for_error(self): + self.assertEqual(multiplyRoots(-2, -8), -1) + if __name__ == '__main__': unittest.main()