From 602fa8fb6b5237afd3b017c80ae75b2e3df14a6f Mon Sep 17 00:00:00 2001
From: fdai7764 <jeremy-francis.kaiser@informatik.hs-fulda.de>
Date: Fri, 19 Jan 2024 12:51:57 +0100
Subject: [PATCH] added another testcase for addition of fractions with
 different denominators and updated code accordingly

---
 src/main/py/fractions.py      | 10 +++++++++-
 src/test/py/test_fractions.py |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/main/py/fractions.py b/src/main/py/fractions.py
index 0445045..675f974 100644
--- a/src/main/py/fractions.py
+++ b/src/main/py/fractions.py
@@ -1,4 +1,4 @@
-from src.main.py.more_advanced_calculations import gcd
+from src.main.py.more_advanced_calculations import gcd, lcm
 
 def frac_to_dec(num, denom):
     return num/denom
@@ -10,5 +10,13 @@ def reduceFraction(num, denom):
     return (num, denom)
 
 def addFractions(num1, denom1, num2, denom2):
+    if denom1 != denom2:
+        fractionExpansionFactor = lcm(denom1, denom2)
+        frac1Offset = fractionExpansionFactor / denom1
+        frac2Offset = fractionExpansionFactor /denom2
+        num1 *= frac1Offset
+        denom1 *= frac1Offset
+        num2 *= frac2Offset
+        denom2 *= frac2Offset
     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 64bf0cb..2a0e09c 100644
--- a/src/test/py/test_fractions.py
+++ b/src/test/py/test_fractions.py
@@ -21,6 +21,9 @@ class fractions(unittest.TestCase):
     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))
 
+    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))
+
 
 if __name__ == '__main__':
     unittest.main()