def test_Branch_isin_map(): l = Leaf(item=b"Hello", key=b"A") store = {l.identity(): l} b = l.add(store, item=b"World", key=b"B") assert b.is_in(store, b"Hello", b"A") assert b.is_in(store, b"World", b"B") assert not b.is_in(store, b"World", b"C")
def test_store(): _flushDB() r = RedisStore() l = Leaf("Hello") r[l.identity()] = l assert r[l.identity()].identity() == l.identity()
def test_store(): _flushDB() r = RedisStore() l = Leaf(b"Hello", b"Hello") r[l.identity()] = l assert r[l.identity()].identity() == l.identity()
def test_Branch_multi(): l = Leaf("Hello") store = {l.identity() : l} b = l.multi_add(store, ["B", "C"]) b.check(store) assert b.is_in(store, "B") assert b.is_in(store, "C") assert b.is_in(store, "Hello")
def test_Branch_multi(): l = Leaf(b"Hello", b"Hello") store = {l.identity(): l} b = l.multi_add(store, [b"B", b"C"], [b"B", b"C"]) b.check(store) assert b.is_in(store, b"B", b"B") assert b.is_in(store, b"C", b"C") assert b.is_in(store, b"Hello", b"Hello")
def test_double_add(): l = Leaf(item=b"Hello", key=b"A") store = {l.identity(): l} b = l.add(store, item=b"World", key=b"B") assert b.is_in(store, b"Hello", b"A") assert b.is_in(store, b"World", b"B") assert not b.is_in(store, b"World", b"C") b = b.add(store, item=b"World2", key=b"B") assert b.lookup(store, b"B") == (b"B", b"World") assert not b.lookup(store, b"B") == (b"B", b"World2")
def test_Branch_add(): l = Leaf("Hello") store = {l.identity() : l} b = l.add(store, "World") b2 = b.add(store, "Doom") assert isinstance(b2, Branch) assert b2.left_branch in store assert b2.right_branch in store assert b2.identity() in store b2.check(store)
def test_Branch_add(): l = Leaf(b"Hello", b"Hello") store = {l.identity(): l} b = l.add(store, b"World", b"World") b2 = b.add(store, b"Doom", b"Doom") assert isinstance(b2, Branch) assert b2.left_branch in store assert b2.right_branch in store assert b2.identity() in store b2.check(store)
def test_Leaf_add(): l = Leaf(b"Hello", b"Hello") store = {l.identity(): l} b = l.add(store, b"World", b"World") assert isinstance(b, Branch) assert b.left_branch in store assert b.right_branch in store assert b.identity() in store assert store[b.left_branch].item <= b.pivot assert store[b.right_branch].item > b.pivot
def test_Leaf_add(): l = Leaf("Hello") store = {l.identity() : l} b = l.add(store, "World") assert isinstance(b, Branch) assert b.left_branch in store assert b.right_branch in store assert b.identity() in store assert store[b.left_branch].item <= b.pivot assert store[b.right_branch].item > b.pivot
def test_lookup(): l = Leaf(item=b"Hello", key=b"A") store = {l.identity(): l} b = l.add(store, item=b"World", key=b"B") assert b.is_in(store, b"Hello", b"A") assert b.is_in(store, b"World", b"B") assert not b.is_in(store, b"World", b"C") assert b.lookup(store, b"B") == (b"B", b"World") try: b.lookup(store, b"B") == (b"B", b"World2") assert False except: assert True try: b.lookup(store, b"C") == (b"B", b"World2") assert False except: assert True
def test_add_like_a_monkey(): root = Leaf(b"Hello", b"Hello") store = {root.identity(): root} from os import urandom for _ in range(100): item = urandom(32) root = root.add(store, item, item) root.check(store) assert root.is_in(store, item, item)
def test_add_like_a_monkey(): root = Leaf("Hello") store = {root.identity() : root} from os import urandom for _ in range(100): item = urandom(32) root = root.add(store, item) root.check(store) assert root.is_in(store, item)
def test_store(rstore): l = Leaf(b"Hello", b"Hello") rstore[l.identity()] = l assert rstore[l.identity()].identity() == l.identity()
def test_Branch_isin(): l = Leaf("Hello") store = {l.identity() : l} b = l.add(store, "World") assert b.is_in(store, "Hello") assert b.is_in(store, "World")
def test_Branch_isin(): l = Leaf(b"Hello", b"Hello") store = {l.identity(): l} b = l.add(store, b"World", b"World") assert b.is_in(store, b"Hello", b"Hello") assert b.is_in(store, b"World", b"World")
def test_leaf_isin_map(): l = Leaf(item=b"Hello", key=b"World") store = {l.identity(): l} b = l.add(store, b"World", b"World") assert l.is_in(store, item=b"Hello", key=b"World")
def test_leaf_isin(): l = Leaf(b"Hello", b"Hello") store = {l.identity(): l} b = l.add(store, b"Woitemrld", b"Woitemrld") assert l.is_in(store, b"Hello", b"Hello")