Beispiel #1
0
    def test_stats(self):
        for size in SIZES:
            l = TTLRU(size)
            for i in range(size):
                l[i] = str(i)

            self.assertTrue(l.get_stats() == (0, 0))

            val = l[0]
            self.assertTrue(l.get_stats() == (1, 0))

            val = l.get(0, None)
            self.assertTrue(l.get_stats() == (2, 0))

            val = l.get(-1, None)
            self.assertTrue(l.get_stats() == (2, 1))

            try:
                val = l[-1]
            except:
                pass

            self.assertTrue(l.get_stats() == (2, 2))

            l.clear()
            self.assertTrue(len(l) == 0)
            self.assertTrue(l.get_stats() == (0, 0))
Beispiel #2
0
 def test_clear(self):
     for size in SIZES:
         l = TTLRU(size)
         for i in range(size + 5):
             l[i] = str(i)
         l.clear()
         for i in range(size):
             l[i] = str(i)
         for i in range(size):
             _ = l[random.randint(0, size - 1)]
         l.clear()
         self.assertTrue(len(l) == 0)