Browse Source

added another testcase for addition where the result needs to be reduced and updated the code accordingly

remotes/origin/feature/feature-fractions
fdai7764 11 months ago
parent
commit
fb15dfa3ec
  1. 2
      src/main/py/fractions.py
  2. 3
      src/test/py/test_fractions.py

2
src/main/py/fractions.py

@ -19,4 +19,4 @@ def addFractions(num1, denom1, num2, denom2):
num2 *= frac2Offset num2 *= frac2Offset
denom2 *= frac2Offset denom2 *= frac2Offset
result_num = num1 + num2 result_num = num1 + num2
return (result_num, denom1)
return reduceFraction(result_num, denom1)

3
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): 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)) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save