Beispiel #1
0
def test_ones_override_with_1():
    mask = IndexBitMask("0001")

    result = mask.apply(0b10)

    expected = [0b11]

    assert expected == result
Beispiel #2
0
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())
Beispiel #4
0
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)
Beispiel #5
0
 def __init__(self) -> None:
     super().__init__()
     self.mask = IndexBitMask("0" * 36)
Beispiel #6
0
def test_larger_x():
    mask = IndexBitMask("XX")
    result = mask.apply(0b11)  # Doesn't really matter
    expected = set(range(4))

    assert expected == set(result)
Beispiel #7
0
def test_zeros_leave_stuff():
    mask = IndexBitMask("0000")

    assert [0b11011] == mask.apply(0b11011)