예제 #1
0
def test_setting_single_bit_to_1():

    bitmask = BitMask("XXXX1")

    my_int = 2
    assert 3 == bitmask.apply(my_int)

    bitmask = BitMask("1XXXX")
    my_int = 2
    assert 18 == bitmask.apply(my_int)
예제 #2
0
class Memory(SpecialSetMemory):
    def __init__(self):
        super().__init__()
        self.mask = BitMask("X" * 36)

    def __setitem__(self, index, value):
        masked_value = self.mask.apply(value)

        if masked_value < 0 or masked_value >= 2 ** 36:
            raise ValueError(f"{value} not valid.")

        self.set_at_raw(index, masked_value)
예제 #3
0
def test_general_setting():
    bitmask = BitMask("XXX01")
    assert 1 == bitmask.apply(2)
예제 #4
0
def test_setting_single_but_to_0():
    bitmask = BitMask("XXX0X")

    assert 1 == bitmask.apply(3)