Ejemplo n.º 1
0
def test_egcd_consistency(a, b):
    d, x, y = extended_gcd(a, b)
    if a == b == 0:
        assert d == x == y == 0
    elif a == 0:
        assert d == b and x == 0 and y == 1
    elif b == 0:
        assert d == a and x == 1 and y == 0
    else:
        qa = max(1, (a / d) / 2)
        qb = max(1, (b / d) / 2)
        assert (a % d == 0 and b % d == 0
                and a * x + b * y == d
                and -qb <= x <= qb
                and -qa <= y <= qa)
Ejemplo n.º 2
0
def test_egcd_reversed(a, b):
    if a != b:
        d0, x0, y0 = extended_gcd(a, b)
        d1, x1, y1 = extended_gcd(b ,a)
        assert (d0, x0, y0) == (d1, y1, x1)
Ejemplo n.º 3
0
def test_egcd_ret_type(a ,b):
    d, x, y = extended_gcd(a, b)
    assert_is_integer(d)
    assert_is_integer(x)
    assert_is_integer(y)
Ejemplo n.º 4
0
def test_egcd_known(a, b, d, x ,y):
    assert (d, x, y) == extended_gcd(a, b)
Ejemplo n.º 5
0
def test_egcd_seq_type(a, b):
    assert type(extended_gcd(a, b)) == tuple