def test_sorted(self): """A test to ensure the tree maintains sorted order.""" keys = list(set([randint(0, 2 ^ 64) for i in range(0, 128)])) items = [(key, None) for key in keys] d = SplayDict(items) self.assertEquals(len(keys), len(d)) self.assertEqual(len(keys), len(list(d))) self.assertEqual(list(sorted(keys)), list(d.keys()))
def test_fuzz_insertions(self): """A test that inserts random keys into the tree and checks that they were all inserted.""" key_range = 2**64 value_range = 1024 key_set = set() d = SplayDict() for value in range(0, value_range): key = randint(0, key_range) d.put(key, value) key_set.add(key) keys = list(d.keys()) self.assertEqual(len(keys), len(key_set), "Length should reflect number of items inserted.") self.assertEqual(len(keys), len(list(keys)), "Iteration should find all items in tree.")