def test_fuzz_deletions(): """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 = OrderedTreeDict() for value in range(0, value_range): key = randint(0, key_range) d.put(key, value) key_set.add(key) sorted_keys = list(sorted(key_set)) sorted_keys_slice = sorted_keys[0:len(sorted_keys) // 2] for key in sorted_keys_slice: d.delete(key) assert len(d) > 0 assert key not in d assert d.depth() <= int(2 * math.log( len(d), 2)), "Should stay as balanced as a red black tree. " keys = list(d.keys()) assert len( keys) == len(sorted_keys_slice ), "Length should reflect number of items inserted." assert len(keys) == len( list(keys)), "Iteration should find all items in tree."
def test_insertion_left_and_right(): d = OrderedTreeDict() d.put(0, 0) d.put(-1, -1) d.put(1, 1) assert len(d) == 3, "Length should reflect number of items inserted," assert d.depth() <= 2, "Not balanced."
def test_fuzz_insertions(): """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 = OrderedTreeDict() for value in range(0, value_range): key = randint(0, key_range) d.put(key, value) key_set.add(key) keys = list(d.keys()) assert len(keys) == len( key_set), "Length should reflect number of items inserted." assert len(keys) == len( list(keys)), "Iteration should find all items in tree." assert d.depth() <= math.ceil(1.44 * math.log2(len(d))), "Should stay as balanced as an avl tree as long as " \ "there are only insertions. "