Exemple #1
0
from cache.LRUCache import LRUCache

if __name__ == '__main__':
    cache = LRUCache(2)
    cache.set(2, 1)
    print cache.peekAll()
    cache.set(1, 1)
    print cache.peekAll()
    cache.get(2)
    print cache.peekAll()
    cache.set(4, 1)
    print cache.peekAll()
    cache.get(1)
    print cache.peekAll()
    node = cache.get(2)
    print cache.peekAll()
Exemple #2
0
 def testHasEntryWithoutLoad(self):
     c = LRUCache(5)
     self.assertFalse(c.has_entry('hello'))
Exemple #3
0
    def testEvictionWithLookup(self):
        c = LRUCache(3)
        c.load_entry('hello', 'world')
        c.load_entry('yellow', 'duck')
        c.load_entry('blue', 'sky')
        c.get_entry('hello')
        c.load_entry('brown', 'bear')

        self.assertTrue(c.has_entry('hello'))
        self.assertFalse(c.has_entry('yellow'))
        self.assertTrue(c.has_entry('blue'))
        self.assertTrue(c.has_entry('brown'))
Exemple #4
0
 def testHasEntryWithLoadAndSizeOne(self):
     c = LRUCache(1)
     c.load_entry('hello', 'world')
     self.assertTrue(c.has_entry('hello'))
     c.load_entry('yellow', 'duck')
     self.assertTrue(c.has_entry('yellow'))
     self.assertFalse(c.has_entry('hello'))
     c.load_entry('blue', 'sky')
     self.assertTrue(c.has_entry('blue'))
     self.assertFalse(c.has_entry('yellow'))
     self.assertFalse(c.has_entry('hello'))
     c.load_entry('brown', 'bear')
     self.assertTrue(c.has_entry('brown'))
     self.assertFalse(c.has_entry('blue'))
     self.assertFalse(c.has_entry('yellow'))
     self.assertFalse(c.has_entry('hello'))
Exemple #5
0
 def testHasEntryWithLoadAndSizeZero(self):
     c = LRUCache(0)
     c.load_entry('hello', 'world')
     self.assertFalse(c.has_entry('hello'))
Exemple #6
0
 def testHasEntryWithLoad(self):
     c = LRUCache(5)
     c.load_entry('hello', 'world')
     self.assertTrue(c.has_entry('hello'))