def test_ones_override_with_1(): mask = IndexBitMask("0001") result = mask.apply(0b10) expected = [0b11] assert expected == result
def test_x_floats(): mask = IndexBitMask("10X") result = mask.apply(0b010) expected = {0b110, 0b111} assert expected == set(result)
def test_sets_all(): mem = FloatingMemory() mask = IndexBitMask("10X") mem.mask = mask mem[2] = 42 # 2 is 0b10, so mask generates 110 and 111 = 6 and 7 assert {(6, 42), (7, 42)} == set(mem.items())
class FloatingMemory(SpecialSetMemory): def __init__(self) -> None: super().__init__() self.mask = IndexBitMask("0" * 36) def __setitem__(self, index, value): if value < 0 or value >= 2 ** 36: raise ValueError(f"{value} not valid.") for masked_index in self.mask.apply(index): self.set_at_raw(masked_index, value)
def __init__(self) -> None: super().__init__() self.mask = IndexBitMask("0" * 36)
def test_larger_x(): mask = IndexBitMask("XX") result = mask.apply(0b11) # Doesn't really matter expected = set(range(4)) assert expected == set(result)
def test_zeros_leave_stuff(): mask = IndexBitMask("0000") assert [0b11011] == mask.apply(0b11011)