-
Notifications
You must be signed in to change notification settings - Fork 5
/
test
executable file
·71 lines (57 loc) · 1.33 KB
/
test
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -e
assert() {
if [[ $1 != $2 ]]; then
echo "Wrong answer! Expected [$1], found [$2]"
if [[ -n $3 ]]; then
echo "(input array was [$3])"
fi
exit 1
fi
}
test_suite() {
local prog=${*:2}
local input_n input_arr expected
exec 5< "../_test/$1.in"
exec 6< "../_test/$1.out"
read expected <&6
local k=0
while [[ -n $expected ]]; do
read input_n <&5
read input_arr <&5
printf "Running test case $((++k)) (size $input_n)... "
local actual=$(printf "$input_n\n$input_arr\n" | $prog)
if [[ -n $ALLOW_TRAILING_SPACE ]]; then
actual=$(echo $actual | xargs)
fi
assert "$expected" "$actual" "$input_arr"
echo "Done"
read expected <&6 ||:
done
exec 5<&-
exec 6<&-
echo "All tests in dataset $1 passed!"
}
test_static() {
local prog=$@
local expected='1 2 3 4 5 6 7 8 9 10'
local actual=$($prog)
assert "$expected" "$actual"
echo "Static test passed!"
}
error() {
echo "Error: $1."
exit 1
}
cd "$1" || error "implementation $1 not found"
source .env
[[ -n $RUN_CMD ]] || error "no run command for $1 was defined"
eval "$BUILD_CMD" || error "build failed"
TEST_SUITES=${TEST_SUITES:-test1,test2}
for suite in ${TEST_SUITES//,/ }; do
if [[ $suite == 'static' ]]; then
test_static $RUN_CMD
else
test_suite $suite $RUN_CMD
fi
done