Ejemplo n.º 1
0
def test_str():
    bits = Bits()
    assert str(bits) == ""
    bits.bools = [1]
    assert str(bits) == "1"
    bits.bools = [1, 1, 0, 1]
    assert str(bits) == "1101"
Ejemplo n.º 2
0
def test_lrc():
    b = Bits()
    assert b.lrc(0) == None
    assert b.lrc(4) == None

    b.bools = [0]
    assert b.lrc(0) == None
    assert b.lrc(1) == [0]

    b.bools = [
        0, 0, 0, 0,
        1, 0, 0, 0,
        0, 1, 0, 0,
        1, 1, 0, 0,
    ]
    assert b.lrc(4) == [0, 0, 0, 0]
    assert b.lrc(6) == None
    assert b.lrc(8) == [0, 1, 0, 0, 0, 1, 0, 0]

    # With parity bits
    b.bools = [
        0, 0, 0, 0, 1,
        1, 0, 0, 0, 0,
        0, 1, 0, 0, 0,
        1, 1, 0, 0, 1,
    ]
    assert b.lrc(5) == [0, 0, 0, 0, 0]