Esempio n. 1
0
def test_slice(bs: bytes) -> None:
    ba = Bitarray()
    ba.push_bytes_back(bs)
    ba1 = ba
    assert ba1[:8].pop_byte_front() == ba1.pop_byte_front()
    ba2 = ba
    assert ba2[:] == ba2
Esempio n. 2
0
def test_iadd(bs1: bytes, bs2: bytes) -> None:
    ba1 = Bitarray()
    ba1.push_bytes_back(bs1)
    ba2 = Bitarray()
    ba2.push_bytes_back(bs2)
    ba1 += ba2

    assert len(ba1) == 8 * (len(bs1) + len(bs2))

    bs3 = bs1 + bs2
    for i in range(len(bs3)):
        assert ba1.pop_byte_front() == ascii2byte(bs3[i])
Esempio n. 3
0
def test_int_conversion(x: int) -> None:
    assert Bitarray.from_int(x).to_int() == x
Esempio n. 4
0
def test_len(bs: bytes) -> None:
    ba = Bitarray()
    ba.push_bytes_back(bs)
    assert len(ba) == 8 * len(bs)
Esempio n. 5
0
def test_push_pop_empty_input(bs: bytes) -> None:
    ba = Bitarray()
    ba.push_bytes_back(bs)
    with pytest.raises(IndexError):
        ba.pop_byte_front()
Esempio n. 6
0
def test_push_pop(bs: bytes) -> None:
    ba = Bitarray()
    ba.push_bytes_back(bs)
    for i in range(len(bs)):
        assert ba.pop_byte_front() == ascii2byte(bs[i])
Esempio n. 7
0
def test_int_conversion_reverse(bs: bytes):
    ba = Bitarray()
    ba.push_bytes_back(bs)
    assert Bitarray.from_int(ba.to_int()).to_int() == ba.to_int()