import time
import random
from util.randomNames import names_pool, generate_find_set


def run_test(records, insert_func, find_func, delete_func):
    structure = None

    start = time.perf_counter()
    for name, phone in records:
        structure = insert_func(structure, name, phone)
    insert_time = time.perf_counter() - start

    find_set = generate_find_set()

    start = time.perf_counter()
    for name in find_set:
        find_func(structure, name)
    find_time = time.perf_counter() - start

    start = time.perf_counter()
    for name in random.sample(names_pool, 50):
        structure = delete_func(structure, name)
    delete_time = time.perf_counter() - start

    return {
        "insert": insert_time,
        "find": find_time,
        "delete": delete_time
    }