def test_retrive_collision(): hashtable = Hashtable() hashtable.add("fried", "chicken") hashtable.add("fired", "the employee") actual = [hashtable.get("fried"), hashtable.get("fired")] expect = ["chicken", "the employee"] assert actual == expect
def test_handle_collision(): hashtable = Hashtable() hashtable.add('fall', 'to the ground') hashtable.add('fall', 'as in seasons') for bucket in hashtable._buckets: if bucket: actual = str(bucket) assert actual == "['fall', 'to the ground']->['fall', 'as in seasons']->None"
def test_contains(): hashtable = Hashtable() hashtable.add("Hello", "It is me") actual = hashtable.contains('Hello') expected = True assert actual == expected actual2 = hashtable.contains("Where") expected2 = False assert actual2 == expected2
def tree_intersection(binary1, binary2): arr = [] tree1 = binary1.pre_order() tree2 = binary2.pre_order() hash = Hashtable() for root in tree1: hash.add(str(root), str(root)) for root in tree2: if hash.contains(str(root)): arr.append(root) if len(arr) == 0: return 'There are no intersections' else: return arr
def test_add_key_value(): hashtable = Hashtable() actual = hashtable.add("DOB", "1996") expect = ["DOB", "1996"] assert actual == expect
def test_get_none_value(): hashtable = Hashtable() hashtable.add('length', 174) actual = hashtable.get('wight') expect = None assert actual == expect
def test_get_value(): hashtable = Hashtable() hashtable.add('length', 174) actual = hashtable.get('length') expect = 174 assert actual == expect