Browse Source

added test to check for fraction to string conversion as well as corresponding functionality

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

3
src/main/py/fractions.py

@ -31,3 +31,6 @@ def multiplyFractions(num1, denom1, num2, denom2):
def divideFractions(num1, denom1, num2, denom2): def divideFractions(num1, denom1, num2, denom2):
return multiplyFractions(num1, denom1, denom2, num2) return multiplyFractions(num1, denom1, denom2, num2)
def fraction_to_string(num, denom):
return str(num) + " / " + str(denom)

3
src/test/py/test_fractions.py

@ -39,6 +39,9 @@ class fractions(unittest.TestCase):
def test_divide_fractions_10_by_3_and_20_by_9_should_be_3_by_2(self): def test_divide_fractions_10_by_3_and_20_by_9_should_be_3_by_2(self):
self.assertEqual(divideFractions(10,3,20,9), (3,2)) self.assertEqual(divideFractions(10,3,20,9), (3,2))
def test_fraction_2_by_5_to_string(self):
self.assertEqual(fraction_to_string(2,5), "2 / 5")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save