forked from ruippeixotog/quicksort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·173 lines (159 loc) · 4.46 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
function 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
}
function run_suite {
prog=${*:2}
exec 5< "../_test/$1.in"
read input_n <&5
while [[ -n $input_n ]]; do
read input_arr <&5
printf "$input_n\n$input_arr\n" | $prog
read input_n <&5
done
exec 5<&-
}
function test_suite {
prog=${*:2}
exec 5< "../_test/$1.in"
exec 6< "../_test/$1.out"
read expected <&6
while [[ -n $expected ]]; do
read input_n <&5
read input_arr <&5
actual=$(printf "$input_n\n$input_arr\n" | $prog)
assert "$expected" "$actual" "$input_arr"
read expected <&6
done
exec 5<&-
exec 6<&-
echo "All tests in dataset $1 passed!"
}
function test_static {
prog=$@
expected='1 2 3 4 5 6 7 8 9 10'
actual=$($prog)
assert "$expected" "$actual"
echo "Static test passed!"
}
if [ $1 == "all" ]; then
for lang in $(ls -d */ | egrep -v '^_' | tr -d /); do
echo "Testing $lang version..."
./test $lang
done
exit 0
fi
cd $1 || exit 1
case $1 in
apl) wget -q -nc https://raw.githubusercontent.com/ngn/apl/f31f06/lib/apl.js && \
chmod +x apl.js && \
test_suite test1 ./apl.js quicksort.apl
;;
assembly) nasm -g -f elf quicksort.asm && \
gcc -m32 -o quicksort quicksort.o && \
test_suite test1 ./quicksort
;;
bash) test_suite test1 bash quicksort.sh
;;
bash-pipes) test_suite test1 bash quicksort.sh
;;
c) gcc quicksort.c -o quicksort && \
test_suite test1 ./quicksort
;;
clojure) test_suite test1 clojure quicksort.clj
;;
c#) mcs Quicksort.cs && \
test_suite test1 mono Quicksort.exe
;;
c++) g++ quicksort.cpp -o quicksort && \
test_suite test1 ./quicksort
;;
c++-meta) g++ quicksort.cpp -o quicksort && \
test_static ./quicksort
;;
erlang) test_suite test1 escript quicksort.erl
;;
fortran) gfortran -o quicksort quicksort.f95 && \
test_suite test1 ./quicksort
;;
f#) fsharpc --nologo Quicksort.fs && \
test_suite test1 mono Quicksort.exe
;;
go) go build quicksort.go && \
test_suite test1 ./quicksort
;;
groovy) test_suite test1 groovy quicksort.groovy
;;
haskell) ghc quicksort.hs -v0 -o quicksort && \
test_suite test1 ./quicksort
;;
idris) idris quicksort.idr -o quicksort && \
test_suite test1 ./quicksort
;;
idris-proof) idris quicksort.idr -o quicksort && \
test_suite test2 ./quicksort
;;
io) test_suite test1 io quicksort.io
;;
java) javac Quicksort.java && \
test_suite test1 java Quicksort
;;
javascript) test_suite test1 node quicksort.js
;;
joy) test_static joy quicksort.joy
;;
kotlin) kotlinc quicksort.kt && \
test_suite test1 kotlin QuicksortKt
;;
lisp) test_suite test1 clisp quicksort.lisp
;;
lua) test_suite test1 lua quicksort.lua
;;
nim) nim c --hints=off --verbosity=0 --nimcache=/tmp/nim quicksort.nim && \
test_suite test1 ./quicksort
;;
pascal) fpc -v0 quicksort.pas && \
test_suite test1 ./quicksort
;;
perl) test_suite test1 perl quicksort.pl
;;
php) php -S localhost:8000 > /dev/null 2>&1 &
trap "kill -9 $!" EXIT
sleep 1
test_static curl -s localhost:8000/quicksort.php
;;
prolog) swipl -q --stand_alone=true --goal=main --toplevel=halt \
--foreign=save -o quicksort -c quicksort.pl && \
test_suite test1 ./quicksort
;;
python) test_suite test1 python quicksort.py
;;
racket) test_suite test1 racket quicksort.rkt
;;
ruby) test_suite test1 ruby quicksort.rb
;;
rust) rustc quicksort.rs && \
test_suite test1 ./quicksort
;;
scala) scalac Quicksort.scala && \
test_suite test1 scala Quicksort
;;
scala-typelevel) scalac -language:_ Quicksort.scala && \
test_static scala Quicksort
;;
sml) ml-build quicksort.cm Quicksort.main sml-image > /dev/null && \
test_suite test1 sml @SMLload=sml-image
;;
swift) swiftc quicksort.swift && \
test_suite test1 ./quicksort
;;
vb.net) vbnc -nologo -quiet Quicksort.vb && \
test_suite test1 mono Quicksort.exe
;;
esac