#!/usr/bin/env bash

make

test_id_list=("65606" "1239383" "43850" "1858224" "360417" "47772" "195305" "869606611" "370244025" "109655" "129567706" "62449" "130219375" "1216406" "5559852" "410804" "904633" "3318382" "7109048" "172385")
test_ids=$(printf '%s\n' "${test_id_list[@]}")

for program in ./id_query_naive ./id_query_indexed ./id_query_binsort; do
    echo -e "\n===testing $program==="
    result=$(echo -e "$test_ids" | "$program" 20000records.tsv)

    if [ "$(echo "$result" | grep 'not found')" == "" ]; then
        echo "All ids found"
    else
        echo "$result" | grep 'not found'
    fi

    echo "$result" | grep 'Total query runtime'
done

test_coord_list=("0 0" "0 51.5" "45 45" "0 -90" "50 10" "10 10")
test_coords=$(printf '%s\n' "${test_coord_list[@]}")

for program in ./coord_query_naive ./coord_query_kdtree; do
    echo -e "\n===Testing $program==="
    result=$(echo -e "$test_coords" | "$program" 20000records.tsv)

    echo "$result" | grep 'Total query runtime'
done
