Browse Source

added test for addition of two fractions as well as corresponding functionality

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

4
src/main/py/fractions.py

@ -8,3 +8,7 @@ def reduceFraction(num, denom):
num /= gcdOfFraction num /= gcdOfFraction
denom /= gcdOfFraction denom /= gcdOfFraction
return (num, denom) return (num, denom)
def addFractions(num1, denom1, num2, denom2):
result_num = num1 + num2
return (result_num, denom1)

3
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): def test_reduce_fraction_56_by_32_should_be_7_by_4(self):
self.assertEqual(reduceFraction(56,32), (7,4)) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save