Esempio n. 1
0
def test_random_set_and_get_keys():
	tree = RedBlackTree(StubStorage())
	ten_k = list(range(10000))
	pairs = list(zip(random.sample(ten_k, 10), random.sample(ten_k, 10)))
	for i, (k, v) in enumerate(pairs, start=1):
		tree.set(k, v)
	for k, v in pairs:
		assert tree.get(k) == v
Esempio n. 2
0
def test_red_children_are_black():
	t = RedBlackTree(StubStorage())
	t.set(2,1)
	t.set(7,1)
	t.set(3,1)
	t.set(5,1)
	t.set(6,1)
	t.set(1,1)
	t.set(4,1)
	t.set(8,1)
	t.set(9,1)
	t.set(10,1)
	t.set(11,1)
	t.set(12,1)
	t.set(13,1)
	t.set(14,1)
	t.set(15,1)
	t.set(16,1)
	rootNode = t._follow(t._tree_ref)
	assert red_children_are_black(t, rootNode)
Esempio n. 3
0
def test_root_black_property():
	t = RedBlackTree(StubStorage())
	t.set(2,1)
	t.set(7,1)
	t.set(3,1)
	t.set(5,1)
	t.set(6,1)
	t.set(1,1)
	t.set(4,1)
	t.set(8,1)
	t.set(9,1)
	t.set(10,1)
	t.set(11,1)
	t.set(12,1)
	t.set(13,1)
	t.set(14,1)
	t.set(15,1)
	t.set(16,1)
	rootNode = t._follow(t._tree_ref)
	assert root_black(rootNode)
Esempio n. 4
0
 def __init__(self, f):
     self._storage = Storage(f)
     self._tree = RedBlackTree(self._storage)
Esempio n. 5
0
def test_overwrite_and_get_key():
	tree = RedBlackTree(StubStorage())
	tree.set('a', 'b')
	tree.set('a', 'c')
	assert tree.get('a') == 'c'
Esempio n. 6
0
def test_set_and_get_key():
	tree = RedBlackTree(StubStorage())
	tree.set('a', 'b')
	assert tree.get('a') == 'b'
Esempio n. 7
0
def test_missing_key():
	tree = RedBlackTree(StubStorage())
	with raises(KeyError):
		tree.get('key')