Browse Source

added test for fraction reduction as well as corresponding functionality

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

10
src/main/py/fractions.py

@ -1,2 +1,10 @@
from src.main.py.more_advanced_calculations import gcd
def frac_to_dec(num, denom): def frac_to_dec(num, denom):
return num/denom
return num/denom
def reduceFraction(num, denom):
gcdOfFraction = gcd(num, denom)
num /= gcdOfFraction
denom /= gcdOfFraction
return (num, denom)

3
src/test/py/test_fractions.py

@ -15,6 +15,9 @@ class fractions(unittest.TestCase):
def test_dec_value_of_negative_20_by_5_should_be_negative_4(self): def test_dec_value_of_negative_20_by_5_should_be_negative_4(self):
self.assertEqual(frac_to_dec(-20,5), -4) self.assertEqual(frac_to_dec(-20,5), -4)
def test_reduce_fraction_56_by_32_should_be_7_by_4(self):
self.assertEqual(reduceFraction(56,32), (7,4))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save