Exemplo n.º 1
0
def test_bitarray_has_any_of():
    ba = BitArray()
    assert not ba.has_any_of(100, 200)

    ba = BitArray()
    ba.set_range(0, 53)
    assert ba.has_any_of(52, 1)
    assert ba.has_any_of(52, 100)
    assert not ba.has_any_of(53, 45)

    ba = BitArray()
    ba.invert_in_place()
    assert ba.has_any_of(0, 1)
    assert ba.has_any_of(53, 45)
    assert ba.has_any_of(0, 100)
Exemplo n.º 2
0
def test_bitarray_set_word():
    # Non-inverted
    expected = 9876 | (123456 << (BitArray.num_bits_per_word * 3))
    ba = BitArray(0)
    ba.set_word(0, 9876)
    ba.set_word(3, 123456)
    assert ba.__getstate__() == expected
    assert not ba.is_all_on()

    # Inverted
    ba = BitArray(0)
    ba.invert_in_place()
    ba.set_word(2, 1234)
    full_word = (1 << BitArray.num_bits_per_word) - 1
    expected = ~((full_word & ~1234) << (BitArray.num_bits_per_word * 2))
    assert ba.__getstate__() == expected
    assert not ba.is_all_on()