Ejemplo n.º 1
0
def test_cocode():
    print("")
    for i in range(200):
        # Test power map, inveriosn, sign, theta, and conversion to GCode
        n1 = randint(0, 0x1fff)
        p1 = PLoop(n1)
        ccvector = randint(0, 0xffffff)
        coc = mat24.vect_to_cocode(ccvector)
        cclist = [i for i in range(24) if (ccvector >> i) & 1]
        cc1 = Cocode(cclist)
        cc2 = Cocode(coc)
        if i < 1:
            print("\nTesting", GcVector(ccvector), ", cocode =", cc1)
        assert cc1 == cc2
        u = Parity(mat24.scalar_prod(p1.value, cc1.value))
        assert p1 & cc1 == u == cc1 & p1 == u * 1 == u + 0
        par = Parity(randint(0, 1))
        assert cc1 + par == par + cc1 == cc1.value // 0x800 + par
        assert cc1 % 2 == Parity(cc1)
        assert len(cc1) == mat24.cocode_weight(cc1.value)
        if len(cc1) < 4:
            syndrome = mat24.cocode_syndrome(cc1.value)
            assert cc1.syndrome().value == syndrome
            syn_from_list = sum(1 << i
                                for i in GcVector(ccvector).syndrome_list())
            assert syn_from_list == syndrome
        i = randint(0, 23)
        assert cc1.syndrome(i).value == mat24.cocode_syndrome(cc1.value, i)
        syndrome_list = cc1.syndrome(i).bit_list
        assert len(cc1) == len(syndrome_list)
        assert syndrome_list == mat24.cocode_to_bit_list(cc1.value, i)
Ejemplo n.º 2
0
def test_T(n_cases):
    for p in characteristics():
        sp = space(p)
        for _ in range(n_cases):            
            o = randint(0, 758)
            so = randint(0, 63)
            coc = Cocode(SubOctad(o, so))
            v = GcVector (coc.syndrome(randint(0,23)))
            sgn = randint(0, 1)
            pl = PLoopZ(sgn) * Octad(o)
            gc = GCode(pl)
            scalar = randint(1, p-1) + p * randint(-5, 5)
            assert gc == GCode(pl)
            ref = (-1)**sgn * sp('T', o, so)
            for sign, d in ((sgn,o), (sgn,gc), (0, pl)):
                for par2 in (so, coc, v):
                    assert (-1)**sign * sp('T', d, par2) == ref
                    mmv = sp()
                    mmv['T', d, par2] = (-1)**sign * scalar
                    assert mmv == scalar * ref
                    signed_scalar = (-1)**sign * scalar % p
                    assert mmv['T', d, par2] == signed_scalar