import sys
import unittest


sys.path.append('../')


from unstdlib.standard import RecentlyUsedContainer


class TestRecentlyUsedContainer(unittest.TestCase):
    def test_maxsize(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        self.assertEqual(len(d), 5)

        for i in xrange(5):
            self.assertEqual(d[i], str(i))

        d[i+1] = str(i+1)

        self.assertEqual(len(d), 5)
        self.assertFalse(0 in d)
        self.assertTrue(i+1 in d)

    def test_expire(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        for i in xrange(5):
            d.get(0)

        # Add one more entry
        d[5] = '5'

        # Check state
        self.assertEqual(d.keys(), [0, 2, 3, 4, 5])

    def test_pruning(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(5):
            d[i] = str(i)

        # Contend 2 entries for the most-used slot to balloon the heap
        for i in xrange(100):
            d.get(i % 2)

        self.assertTrue(len(d.access_log) <= d.CLEANUP_FACTOR * d._maxsize)

    def test_same_key(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(10):
            d['foo'] = i

        self.assertEqual(d.keys(), ['foo'])

        d._prune_invalidated_entries()

        self.assertEqual(len(d.access_log), 1)

    def test_access_ordering(self):
        d = RecentlyUsedContainer(5)

        for i in xrange(10):
            d[i] = True

        self.assertEqual(d._get_ordered_access_keys(), [9,8,7,6,5])

        new_order = [7,8,6,9,5]
        for k in reversed(new_order):
            d[k]

        self.assertEqual(d._get_ordered_access_keys(), new_order)


if __name__ == '__main__':
    unittest.main()

@@ -69,16 +69,29 @@
 standard
+.collections_
  import 
@@ -112,16 +112,16 @@
 ntainer%0A
-
 %0A%0Aclass 
@@ -492,16 +492,16 @@
 0 in d)%0A
+
         
@@ -531,1234 +531,8 @@
 d)%0A%0A
-    def test_expire(self):%0A        d = RecentlyUsedContainer(5)%0A%0A        for i in xrange(5):%0A            d%5Bi%5D = str(i)%0A%0A        for i in xrange(5):%0A            d.get(0)%0A%0A        # Add one more entry%0A        d%5B5%5D = '5'%0A%0A        # Check state%0A        self.assertEqual(d.keys(), %5B0, 2, 3, 4, 5%5D)%0A%0A    def test_pruning(self):%0A        d = RecentlyUsedContainer(5)%0A%0A        for i in xrange(5):%0A            d%5Bi%5D = str(i)%0A%0A        # Contend 2 entries for the most-used slot to balloon the heap%0A        for i in xrange(100):%0A            d.get(i %25 2)%0A%0A        self.assertTrue(len(d.access_log) %3C= d.CLEANUP_FACTOR * d._maxsize)%0A%0A    def test_same_key(self):%0A        d = RecentlyUsedContainer(5)%0A%0A        for i in xrange(10):%0A            d%5B'foo'%5D = i%0A%0A        self.assertEqual(d.keys(), %5B'foo'%5D)%0A%0A        d._prune_invalidated_entries()%0A%0A        self.assertEqual(len(d.access_log), 1)%0A%0A    def test_access_ordering(self):%0A        d = RecentlyUsedContainer(5)%0A%0A        for i in xrange(10):%0A            d%5Bi%5D = True%0A%0A        self.assertEqual(d._get_ordered_access_keys(), %5B9,8,7,6,5%5D)%0A%0A        new_order = %5B7,8,6,9,5%5D%0A        for k in reversed(new_order):%0A            d%5Bk%5D%0A%0A        self.assertEqual(d._get_ordered_access_keys(), new_order)%0A%0A
 %0Aif 

Remove outdated tests.