From 2aff63923c17a942464ca34ce9a4cd99e41b533e Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Fri, 19 Jan 2024 12:41:28 +0100 Subject: [PATCH] added test for addition of two fractions as well as corresponding functionality --- src/main/py/fractions.py | 4 ++++ src/test/py/test_fractions.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/main/py/fractions.py b/src/main/py/fractions.py index 2d86a21..0445045 100644 --- a/src/main/py/fractions.py +++ b/src/main/py/fractions.py @@ -8,3 +8,7 @@ def reduceFraction(num, denom): num /= gcdOfFraction denom /= gcdOfFraction return (num, denom) + +def addFractions(num1, denom1, num2, denom2): + result_num = num1 + num2 + return (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 8fe3a62..64bf0cb 100644 --- a/src/test/py/test_fractions.py +++ b/src/test/py/test_fractions.py @@ -18,6 +18,9 @@ class fractions(unittest.TestCase): def test_reduce_fraction_56_by_32_should_be_7_by_4(self): self.assertEqual(reduceFraction(56,32), (7,4)) + def test_add_fractions_1_by_5_and_2_by_5_should_be_3_by_5(self): + self.assertEqual(addFractions(1,5,2,5), (3,5)) + if __name__ == '__main__': unittest.main()