Пример #1
0
def test_bitarray_clear():
    ba = BitArray(1234)
    ba.clear()
    assert ba.is_zero()
    assert not ba.is_all_on()
    assert ba.get_highest_on_bit() == -1
    assert ba.get_highest_off_bit() == -1

    ba = BitArray.all_on()
    ba.clear()
    assert ba.is_zero()
    assert not ba.is_all_on()
    assert ba.get_highest_on_bit() == -1
    assert ba.get_highest_off_bit() == -1
Пример #2
0
def test_bitarray_constructor_sparse():
    # Create a BitArray from a SparseArray.
    ba = BitArray(SparseArray.all_on())
    assert ba.is_all_on()

    ba = BitArray(SparseArray())
    assert ba.is_zero()

    sa = SparseArray()
    sa.set_range(3, 64)
    sa.set_range(0, 1)
    sa.clear_range(60, 2)
    ba = BitArray(sa)
    exp = 0b1111100111111111111111111111111111111111111111111111111111111111001
    assert ba.__getstate__() == exp

    sa.invert_in_place()
    ba = BitArray(sa)
    assert ba.__getstate__() == ~exp