Ejemplo n.º 1
0
def test_gf_irreducible_p():
    assert gf_irred_p_ben_or([7], 11, ZZ) == True
    assert gf_irred_p_ben_or([7,3], 11, ZZ) == True
    assert gf_irred_p_ben_or([7,3,1], 11, ZZ) == False

    assert gf_irred_p_rabin([7], 11, ZZ) == True
    assert gf_irred_p_rabin([7,3], 11, ZZ) == True
    assert gf_irred_p_rabin([7,3,1], 11, ZZ) == False

    assert gf_irreducible_p([7], 11, ZZ, method='ben-or') == True
    assert gf_irreducible_p([7,3], 11, ZZ, method='ben-or') == True
    assert gf_irreducible_p([7,3,1], 11, ZZ, method='ben-or') == False

    assert gf_irreducible_p([7], 11, ZZ, method='rabin') == True
    assert gf_irreducible_p([7,3], 11, ZZ, method='rabin') == True
    assert gf_irreducible_p([7,3,1], 11, ZZ, method='rabin') == False

    raises(KeyError, "gf_irreducible_p([7], 11, ZZ, method='other')")

    f = [1, 9,  9, 13, 16, 15,  6,  7,  7,  7, 10]
    g = [1, 7, 16,  7, 15, 13, 13, 11, 16, 10,  9]

    h = gf_mul(f, g, 17, ZZ)

    assert gf_irred_p_ben_or(f, 17, ZZ) == True
    assert gf_irred_p_ben_or(g, 17, ZZ) == True

    assert gf_irred_p_ben_or(h, 17, ZZ) == False

    assert gf_irred_p_rabin(f, 17, ZZ) == True
    assert gf_irred_p_rabin(g, 17, ZZ) == True

    assert gf_irred_p_rabin(h, 17, ZZ) == False
Ejemplo n.º 2
0
def test_gf_irreducible_p():
    assert gf_irred_p_ben_or([7], 11, ZZ) == True
    assert gf_irred_p_ben_or([7, 3], 11, ZZ) == True
    assert gf_irred_p_ben_or([7, 3, 1], 11, ZZ) == False

    assert gf_irred_p_rabin([7], 11, ZZ) == True
    assert gf_irred_p_rabin([7, 3], 11, ZZ) == True
    assert gf_irred_p_rabin([7, 3, 1], 11, ZZ) == False

    assert gf_irreducible_p([7], 11, ZZ, method='ben-or') == True
    assert gf_irreducible_p([7, 3], 11, ZZ, method='ben-or') == True
    assert gf_irreducible_p([7, 3, 1], 11, ZZ, method='ben-or') == False

    assert gf_irreducible_p([7], 11, ZZ, method='rabin') == True
    assert gf_irreducible_p([7, 3], 11, ZZ, method='rabin') == True
    assert gf_irreducible_p([7, 3, 1], 11, ZZ, method='rabin') == False

    raises(KeyError, "gf_irreducible_p([7], 11, ZZ, method='other')")

    f = [1, 9, 9, 13, 16, 15, 6, 7, 7, 7, 10]
    g = [1, 7, 16, 7, 15, 13, 13, 11, 16, 10, 9]

    h = gf_mul(f, g, 17, ZZ)

    assert gf_irred_p_ben_or(f, 17, ZZ) == True
    assert gf_irred_p_ben_or(g, 17, ZZ) == True

    assert gf_irred_p_ben_or(h, 17, ZZ) == False

    assert gf_irred_p_rabin(f, 17, ZZ) == True
    assert gf_irred_p_rabin(g, 17, ZZ) == True

    assert gf_irred_p_rabin(h, 17, ZZ) == False
Ejemplo n.º 3
0
def test_gf_irreducible_p():
    assert gf_irred_p_ben_or([7], 11, ZZ) == True
    assert gf_irred_p_ben_or([7,3], 11, ZZ) == True
    assert gf_irred_p_ben_or([7,3,1], 11, ZZ) == False

    assert gf_irred_p_rabin([7], 11, ZZ) == True
    assert gf_irred_p_rabin([7,3], 11, ZZ) == True
    assert gf_irred_p_rabin([7,3,1], 11, ZZ) == False

    config.setup('GF_IRRED_METHOD', 'ben-or')

    assert gf_irreducible_p([7], 11, ZZ) == True
    assert gf_irreducible_p([7,3], 11, ZZ) == True
    assert gf_irreducible_p([7,3,1], 11, ZZ) == False

    config.setup('GF_IRRED_METHOD', 'rabin')

    assert gf_irreducible_p([7], 11, ZZ) == True
    assert gf_irreducible_p([7,3], 11, ZZ) == True
    assert gf_irreducible_p([7,3,1], 11, ZZ) == False

    config.setup('GF_IRRED_METHOD', 'other')
    raises(KeyError, lambda: gf_irreducible_p([7], 11, ZZ))
    config.setup('GF_IRRED_METHOD')

    f = [1, 9,  9, 13, 16, 15,  6,  7,  7,  7, 10]
    g = [1, 7, 16,  7, 15, 13, 13, 11, 16, 10,  9]

    h = gf_mul(f, g, 17, ZZ)

    assert gf_irred_p_ben_or(f, 17, ZZ) == True
    assert gf_irred_p_ben_or(g, 17, ZZ) == True

    assert gf_irred_p_ben_or(h, 17, ZZ) == False

    assert gf_irred_p_rabin(f, 17, ZZ) == True
    assert gf_irred_p_rabin(g, 17, ZZ) == True

    assert gf_irred_p_rabin(h, 17, ZZ) == False
Ejemplo n.º 4
0
def test_gf_irreducible_p():
    assert gf_irred_p_ben_or(ZZ.map([7]), 11, ZZ) is True
    assert gf_irred_p_ben_or(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irred_p_ben_or(ZZ.map([7, 3, 1]), 11, ZZ) is False

    assert gf_irred_p_rabin(ZZ.map([7]), 11, ZZ) is True
    assert gf_irred_p_rabin(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irred_p_rabin(ZZ.map([7, 3, 1]), 11, ZZ) is False

    config.setup("GF_IRRED_METHOD", "ben-or")

    assert gf_irreducible_p(ZZ.map([7]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3, 1]), 11, ZZ) is False

    config.setup("GF_IRRED_METHOD", "rabin")

    assert gf_irreducible_p(ZZ.map([7]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3, 1]), 11, ZZ) is False

    config.setup("GF_IRRED_METHOD", "other")
    raises(KeyError, lambda: gf_irreducible_p([7], 11, ZZ))
    config.setup("GF_IRRED_METHOD")

    f = ZZ.map([1, 9, 9, 13, 16, 15, 6, 7, 7, 7, 10])
    g = ZZ.map([1, 7, 16, 7, 15, 13, 13, 11, 16, 10, 9])

    h = gf_mul(f, g, 17, ZZ)

    assert gf_irred_p_ben_or(f, 17, ZZ) is True
    assert gf_irred_p_ben_or(g, 17, ZZ) is True

    assert gf_irred_p_ben_or(h, 17, ZZ) is False

    assert gf_irred_p_rabin(f, 17, ZZ) is True
    assert gf_irred_p_rabin(g, 17, ZZ) is True

    assert gf_irred_p_rabin(h, 17, ZZ) is False