def test_trie_dict_hypothesis(): random.seed(0) trials = 10000 size = 8 key_len = 8 for _ in range(trials): t = Trie() normal_dict = {} # insert num_keys = random.randint(0, size) for _ in range(num_keys): key = ''.join( random.choices('a0!///', k=random.randint(1, key_len))) value = str(random.randint(1, key_len)) clean_key = '/'.join(split(key)) t.put(split(key), value) normal_dict[clean_key] = value assert split(key) in t assert t.flatten() == normal_dict assert set(_join_items(t.items([]))) == set(normal_dict.items()) assert set(_join_keys(t.keys([]))) == set(normal_dict.keys()) assert len(t) == len(normal_dict) # clone clone = t.clone() assert t.flatten() == clone.flatten() assert t.to_json() == clone.to_json() assert _join_keys(t.keys([])) == _join_keys(clone.keys([])) assert _join_items(t.items([])) == _join_items(clone.items([])) # delete for key in list(normal_dict.keys()): del normal_dict[key] t.discard(split(key)) assert split(key) not in t assert t.flatten() == normal_dict assert set(_join_items(t.items([]))) == set(normal_dict.items()) assert set(_join_keys(t.keys([]))) == set(normal_dict.keys()) assert len(t) == len(normal_dict)
def test_split_all(): assert split('///x/////y////////z/a////////////c////////') == [ 'x', 'y', 'z', 'a', 'c' ]
def test_split_double_separators(): assert split('x//y') == ['x', 'y']
def test_split_leading_separator(): assert split('/x/y/z/') == ['x', 'y', 'z']
def test_split_trailing_separator(): assert split('x/y/z/') == ['x', 'y', 'z']
def test_split_multiple_separators(): assert split('x/y/z') == ['x', 'y', 'z']
def test_split_one_separator(): assert split('x/y') == ['x', 'y']
def test_split_no_separator(): assert split('x') == ['x']