aboutsummaryrefslogtreecommitdiff
path: root/Practical2/tester/test.sh
blob: 8f42b77661f5cf1db8e1d17b7cf1797708c242da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
dir="$(dirname $0)/.."
samples="./tester/samples"
cmd="./checkout"

failed=0

cd "$dir"
for tc in "$samples/"*.in; do
    answer=$(cat ${tc/in/out})
    header=$(head -n1 "$tc" | tr -d '\n')
    echo -n "Running $(printf '%-15s' "$(basename $tc)") $(printf '%-10s' "($answer ")$(printf '%-10s' "/ $header)") ... "
    time_start=$(($(date +%s%N)/1000000))
    result=$(eval "cat '$tc' | $cmd")
    time_end=$(($(date +%s%N)/1000000))
    time=`expr $time_end - $time_start`
    if [ "$result" != "$answer" ]; then
        echo "failure ($time ms)."
        failed=$(($failed+1))
    else
        echo "success ($time ms)."
    fi
done
cd - >/dev/null

if [ $failed -eq 0 ]; then
    echo "All tests passed."
elif [ $failed -eq 1 ]; then
    echo "1 test failed."
else
    echo "$failed tests failed."
fi