def test_fixed_sized_dict(self): N = 10000 queue = FixedSizeDict(N + 1) for i in range(N): queue[i] = i # no keys were delted assert len(queue) == N assert queue.popitem(last=False)[0] == 0 assert queue.popitem(last=True)[0] == N - 1 # add another queue[N + 1] = 35 queue[N + 2] = 35 queue[N + 3] = 35 # now 1/5th of keys is delted assert len(queue) == N - (N // 5) + 1 # make sure only the oldest ones were deleted assert queue.popitem(last=False)[0] == (N // 5) + 1
def __init__(self, *args: Any, **kwargs: Any) -> None: # create a fixed sized message queue self._queue = FixedSizeDict(10000) super().__init__(*args, **kwargs)