Esempio n. 1
0
 def shift_to_2pi(self, x: Fraction):
     """
     Takes a fraction that represents a coefficient of pi and shifts it
     so it lies in the range 0 to 2
     :param x: Fraction
     :return: Fraction
     """
     if x.to_real() > 0:
         if int(x.to_real()) % 2 == 0:
             x -= int(x.to_real())
         else:
             x = x - int(x.to_real()) + 1
     else:
         if (int(x.to_real()) - 1) % 2 == 0:
             x -= int(x.to_real()) - 1
         else:
             x = x - (int(x.to_real()) - 1) + 1
     return x
Esempio n. 2
0
def test_fraction_simplification(a, b):
    """Tests that simplifying a fraction doesn't affect it's value"""
    frac = Fraction(a, b)
    assert frac.to_real() == a / b