def test_unlimited_dict(self): d = LimitedDict() for i in range(10): d[i] = i for i in range(10): self.assertEqual(d[i], i)
def test_limited_dict_with_step(self): d = LimitedDict(max_len=10, step=3) for i in range(10): d[i] = i d[10] = 10 self.assertEqual(len(d), 10) self.assertNotIn(0, d) t = d[1] + 10 # access the oldest item d[11] = t # then try to evict it self.assertEqual(len(d), 10) self.assertIn(1, d)
def test_limited_dict(self): d = LimitedDict(max_len=3) d[1] = 1 d[2] = 2 d[3] = 3 self.assertEqual(len(d), 3) d[4] = 4 self.assertEqual(len(d), 3) self.assertNotIn(1, d) t = d[2] + 3 # access the oldest item d[5] = t # then try to evict it self.assertEqual(len(d), 3) self.assertIn(2, d)