125
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
|
6 |
|
|
7 |
out=${1:-output}
|
|
8 |
|
302
|
9 |
echo -e "" > $out
|
125
|
10 |
|
302
|
11 |
echo -e "Below is the feedback for your submission collatz.scala" >> $out
|
|
12 |
echo -e "" >> $out
|
125
|
13 |
|
|
14 |
|
|
15 |
# compilation tests
|
|
16 |
|
|
17 |
function scala_compile {
|
472
|
18 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$1" ) #2> c$out 1> c$out)
|
125
|
19 |
}
|
|
20 |
|
|
21 |
# functional tests
|
|
22 |
|
|
23 |
function scala_assert {
|
472
|
24 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" ) #2> /dev/null 1> /dev/null)
|
125
|
25 |
}
|
|
26 |
|
|
27 |
# purity test
|
472
|
28 |
function scala_vars {
|
|
29 |
(sed 's/immutable/ok/g' c$out > cb$out;
|
|
30 |
egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
|
|
31 |
}
|
125
|
32 |
|
|
33 |
|
|
34 |
|
346
|
35 |
### compilation test
|
|
36 |
|
|
37 |
echo -e "collatz.scala runs?" >> $out
|
|
38 |
|
|
39 |
if (scala_compile collatz.scala)
|
|
40 |
then
|
360
|
41 |
echo -e " --> success" >> $out
|
346
|
42 |
tsts=$(( 0 ))
|
|
43 |
else
|
|
44 |
echo -e " --> SCALA DID NOT RUN collatz.scala\n" >> $out
|
|
45 |
tsts=$(( 1 ))
|
|
46 |
fi
|
|
47 |
|
|
48 |
|
|
49 |
|
125
|
50 |
# var, .par return, ListBuffer test
|
|
51 |
#
|
|
52 |
|
346
|
53 |
if [ $tsts -eq 0 ]
|
356
|
54 |
then
|
|
55 |
echo -e "collatz.scala does not contain VARS, RETURNS etc?" >> $out
|
|
56 |
|
346
|
57 |
if (scala_vars collatz.scala)
|
|
58 |
then
|
|
59 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)\n" >> $out
|
|
60 |
tsts=$(( 1 ))
|
|
61 |
else
|
360
|
62 |
echo -e " --> success" >> $out
|
346
|
63 |
tsts=$(( 0 ))
|
|
64 |
fi
|
|
65 |
fi
|
125
|
66 |
|
|
67 |
|
|
68 |
### collatz tests
|
|
69 |
|
|
70 |
if [ $tsts -eq 0 ]
|
|
71 |
then
|
302
|
72 |
echo -e "collatz.scala tests:" >> $out
|
|
73 |
echo -e " collatz(1) == 0" >> $out
|
|
74 |
echo -e " collatz(6) == 8" >> $out
|
|
75 |
echo -e " collatz(9) == 19" >> $out
|
125
|
76 |
|
|
77 |
if (scala_assert "collatz.scala" "collatz_test1.scala")
|
|
78 |
then
|
302
|
79 |
echo -e " --> success" >> $out
|
125
|
80 |
else
|
302
|
81 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
125
|
82 |
fi
|
|
83 |
fi
|
|
84 |
|
|
85 |
### collatz-max tests
|
|
86 |
|
|
87 |
if [ $tsts -eq 0 ]
|
|
88 |
then
|
302
|
89 |
echo -e " collatz_max(10) == (19, 9)" >> $out
|
|
90 |
echo -e " collatz_max(100) == (118, 97)" >> $out
|
|
91 |
echo -e " collatz_max(1000) == (178, 871)" >> $out
|
|
92 |
echo -e " collatz_max(10000) == (261, 6171)" >> $out
|
|
93 |
echo -e " collatz_max(100000) == (350, 77031)" >> $out
|
|
94 |
echo -e " collatz_max(1000000) == (524, 837799)" >> $out
|
125
|
95 |
|
|
96 |
if (scala_assert "collatz.scala" "collatz_test2.scala")
|
|
97 |
then
|
302
|
98 |
echo -e " --> success" >> $out
|
125
|
99 |
else
|
302
|
100 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
125
|
101 |
fi
|
|
102 |
fi
|
|
103 |
|
|
104 |
|
343
|
105 |
### last-odd tests
|
|
106 |
|
|
107 |
if [ $tsts -eq 0 ]
|
|
108 |
then
|
|
109 |
echo -e " last_odd(113) == 85" >> $out
|
|
110 |
echo -e " last_odd(84) == 21" >> $out
|
|
111 |
echo -e " last_odd(605) == 341" >> $out
|
|
112 |
|
|
113 |
if (scala_assert "collatz.scala" "collatz_test3.scala")
|
|
114 |
then
|
|
115 |
echo -e " --> success" >> $out
|
|
116 |
else
|
|
117 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
|
118 |
fi
|
|
119 |
fi
|