From fb15dfa3ec2dc29762039489a9ac7ace8035751f Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Fri, 19 Jan 2024 12:55:11 +0100 Subject: [PATCH] added another testcase for addition where the result needs to be reduced and updated the code accordingly --- src/main/py/fractions.py | 2 +- src/test/py/test_fractions.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/py/fractions.py b/src/main/py/fractions.py index 675f974..8ec5347 100644 --- a/src/main/py/fractions.py +++ b/src/main/py/fractions.py @@ -19,4 +19,4 @@ def addFractions(num1, denom1, num2, denom2): num2 *= frac2Offset denom2 *= frac2Offset result_num = num1 + num2 - return (result_num, denom1) \ No newline at end of file + return reduceFraction(result_num, denom1) \ No newline at end of file diff --git a/src/test/py/test_fractions.py b/src/test/py/test_fractions.py index 2a0e09c..f20ec44 100644 --- a/src/test/py/test_fractions.py +++ b/src/test/py/test_fractions.py @@ -24,6 +24,9 @@ class fractions(unittest.TestCase): def test_add_fractions_1_by_10_and_1_by_5_should_be_3_by_10(self): self.assertEqual(addFractions(1,10,1,5), (3,10)) + def test_add_fractions_1_by_10_and_2_by_5_should_be_1_by_2(self): + self.assertEqual(addFractions(1, 10, 2, 5), (1, 2)) + if __name__ == '__main__': unittest.main()