import time
import random
from typing import Callable, Any
from task1.util.randomNames import names_pool_to_find, names_pool

def test(records: list,
         insert_func: Callable[[Any, str, str], Any],
         find_func: Callable[[Any, str], Any],
         delete_func: Callable[[Any, str], Any]) -> dict:
    data = None
    
    # Вставка всех записей
    start = time.perf_counter()
    for item in records:
        data = insert_func(data, item[0], item[1])
    end = time.perf_counter()
    insert_time = end - start

    # Поиск 110 случайных записей
    start = time.perf_counter()
    for name in names_pool_to_find:
        find_func(data, name)
    end = time.perf_counter()
    find_time = end - start

    # Удаление 50 случайных записей
    start = time.perf_counter()
    for name in random.choices(names_pool, k = 50):
        data = delete_func(data, name)
    end = time.perf_counter()
    delete_time = end - start
    
    return {
        "insert_time" : insert_time ,
        "find_time" : find_time ,
        "delete_time":  delete_time
    }
