def test_rbt_del_min(): rbt = RBT(None) rbt.add(1) assert rbt.find(1) == True rbt.add(2) assert rbt.find(2) == True assert rbt.find(3) == False # pudb.set_trace() rbt.del_min() assert rbt.find(1) == False assert rbt.find(2) == True
def test_rbt_delete(): rbt = RBT(None) rbt.add(1) rbt.add(2) rbt.add(3) rbt.delete(2) assert rbt.find(2) == False assert rbt.find(1) == True assert rbt.find(3) == True rbt.add(2) rbt.delete(5) assert rbt.find(1) == True assert rbt.find(2) == True assert rbt.find(3) == False
def test_rbt_del_max(): rbt = RBT(None) rbt.add(1) rbt.add(3) rbt.del_max() assert rbt.find(3) == False assert rbt.find(1) == True
print('file path is required') try: with open(data, 'r') as f: for line in f: for word in line.split(): parsed = parse_input_strings(word) if len(parsed) > 0: data_structure.insert(parsed) except FileNotFoundError as e: print('file not found', e) elif action == 'delete' and data is not None: data_structure.delete(data) elif action == 'find' and data is not None: print('1' if data_structure.find(data) is not None else '0') # following options are for BST and RBT only elif chosen_data_structure != 'hmap': if action == 'min': t = data_structure.minimum() if t is not None: print(t.value) else: print() elif action == 'max': t = data_structure.maximum() if t is not None: print(t.value) else:
rbt.insert(t) end = time() rbt_insert_times.append(end-begin) # calculate the average insertion time llist_insert_times_avg = sum(llist_insert_times)/len(llist_insert_times) rbt_insert_times_avg = sum(rbt_insert_times)/len(rbt_insert_times) # measure searching time t = randint(0, items_count) begin = time() x = llist.find(t) end = time() llist_find_time = end - begin begin = time() x = rbt.find(t) end = time() rbt_find_time = end - begin print('llist insert avg:', llist_insert_times_avg) print('rbt insert avg :', rbt_insert_times_avg) print('avg insert rate :', rbt_insert_times_avg/llist_insert_times_avg) print('rbt faster :', rbt_insert_times_avg < llist_insert_times_avg) print() print('llist find time :', llist_find_time) print('rbt find time :', rbt_find_time) print('rbt faster :', rbt_find_time < llist_find_time)