Browse Source

added test for multiplication of fractions and corresponding functionality

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

5
src/main/py/fractions.py

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

3
src/test/py/test_fractions.py

@ -27,6 +27,9 @@ class fractions(unittest.TestCase):
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))
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))
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save