def test_devision_by_zero(self): exc = None try: gcd(3, 0) except Exception as err: exc = err self.assertIsNotNone(str(exc)) self.assertEqual(str(exc), 'Cannot divide by zero')
def sum_of_two_fractions(frac1, frac2): denominator = gcd(frac1[1], frac2[1]) denominator = (frac1[1] * frac2[1]) // denominator nominator = (frac1[0] * (denominator // frac1[1]) + frac2[0] * (denominator // frac2[1])) res = simplify_fraction((nominator, denominator)) if str(res) == 'Cannot divide by zero': raise ZeroDivisionError('Cannot divide by zero') else: return res
def lcm(a, b): return (a * b) // gcd(a, b)
def test_when_the_number_is_not_imaculate_then_return_the_gcd(self): expr = (7, 21) expected_result = 7 self.assertEqual(gcd(expr[0], expr[1]), expected_result)
def test_with_irreducible_fraction(self): res = gcd(9, 28) self.assertEqual(res, 1)
def test_with_reducible_fraction(self): res = gcd(12, 8) self.assertEqual(res, 4)