From b79cd2f7ab56a06d0ff776d373ccbcad35578f27 Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Fri, 19 Jan 2024 18:36:36 +0100 Subject: [PATCH] added test to check for fraction to string conversion as well as corresponding functionality --- src/main/py/fractions.py | 5 ++++- src/test/py/test_fractions.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/py/fractions.py b/src/main/py/fractions.py index ce1c287..101f37d 100644 --- a/src/main/py/fractions.py +++ b/src/main/py/fractions.py @@ -30,4 +30,7 @@ def multiplyFractions(num1, denom1, num2, denom2): return reduceFraction(result_num, result_denom) def divideFractions(num1, denom1, num2, denom2): - return multiplyFractions(num1, denom1, denom2, num2) \ No newline at end of file + return multiplyFractions(num1, denom1, denom2, num2) + +def fraction_to_string(num, denom): + return str(num) + " / " + str(denom) \ No newline at end of file diff --git a/src/test/py/test_fractions.py b/src/test/py/test_fractions.py index 9613789..b049bfa 100644 --- a/src/test/py/test_fractions.py +++ b/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): 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__': unittest.main()