def test_reset(self): cache = LRUCache(3,60) cache.set("a", 34) cache.reset() self.assertEqual(cache.keys(), []) self.assertEqual(cache.values(), []) self.assertEqual(cache.last_updated, None)
def test_reset(self): c = LRUCache(3) c.put(4, 2) c.put(1, 1) c.put(2, 3) # after reset, nothing existing in the cache c.reset() self.assertEqual(c.size(), 0) self.assertEqual(c.cache(), {})
def test_all(self): c = LRUCache(5) c.put(1, 'one') c.put(2, 'two') c.put(3, 'three') c.delete(3) self.assertEqual(c.size(), 2) self.assertEqual(c.cache(), {2: 'two', 1: 'one'}) c.put(4, 'four') c.put(6, 'six') self.assertEqual(c.get(1), 'one') self.assertEqual(c.size(), 4) self.assertEqual(c.cache(), {1: 'one', 6: 'six', 4: 'four', 2: 'two'}) self.assertEqual(c.get(3), -1) c.put(1, 'five') self.assertEqual(c.cache(), {1: 'five', 6: 'six', 4: 'four', 2: 'two'}) c.put(12, 'twelve') self.assertEqual(c.cache(), { 12: 'twelve', 1: 'five', 6: 'six', 4: 'four', 2: 'two' }) c.put(5, 'five') self.assertEqual(c.cache(), { 5: 'five', 12: 'twelve', 1: 'five', 6: 'six', 4: 'four' }) self.assertEqual(c.get(2), -1) c.reset() self.assertEqual(c.size(), 0) self.assertEqual(c.cache(), {})