Browse Source

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

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

4
src/main/py/fractions.py

@ -22,4 +22,6 @@ def addFractions(num1, denom1, num2, denom2):
return reduceFraction(result_num, denom1) return reduceFraction(result_num, denom1)
def multiplyFractions(num1, denom1, num2, denom2): def multiplyFractions(num1, denom1, num2, denom2):
return (num1 * num2, denom1 * denom2)
result_num = num1 * num2
result_denom = denom1 * denom2
return reduceFraction(result_num, result_denom)

3
src/test/py/test_fractions.py

@ -30,6 +30,9 @@ class fractions(unittest.TestCase):
def test_multiply_fractions_1_by_2_and_1_by_2_should_be_1_by_4(self): def test_multiply_fractions_1_by_2_and_1_by_2_should_be_1_by_4(self):
self.assertEqual(multiplyFractions(1,2,1,2), (1,4)) self.assertEqual(multiplyFractions(1,2,1,2), (1,4))
def test_multiply_fractions_1_by_5_and_5_by_3_should_be_1_by_3(self):
self.assertEqual(multiplyFractions(1,5,5,3), (1,3))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save