211
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# to make the script fail safely
|
|
4 |
set -euo pipefail
|
|
5 |
|
|
6 |
|
|
7 |
out=${1:-output}
|
|
8 |
|
|
9 |
echo "" > $out
|
|
10 |
|
|
11 |
echo "Below is the feedback for your submission docdiff.scala" >> $out
|
|
12 |
echo "" >> $out
|
|
13 |
|
|
14 |
|
|
15 |
# compilation tests
|
|
16 |
|
|
17 |
function scala_compile {
|
283
|
18 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
|
211
|
19 |
}
|
|
20 |
|
|
21 |
# functional tests
|
|
22 |
|
|
23 |
function scala_assert {
|
283
|
24 |
(ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
|
211
|
25 |
}
|
|
26 |
|
|
27 |
# purity test
|
|
28 |
|
|
29 |
function scala_vars {
|
|
30 |
(egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
|
|
31 |
}
|
|
32 |
|
|
33 |
|
|
34 |
# var, .par return, ListBuffer test
|
|
35 |
#
|
|
36 |
echo "docdiff.scala does not contain vars, returns etc?" >> $out
|
|
37 |
|
|
38 |
if (scala_vars docdiff.scala)
|
|
39 |
then
|
283
|
40 |
echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
|
211
|
41 |
tsts0=$(( 0 ))
|
|
42 |
else
|
283
|
43 |
echo -e " --> success" >> $out
|
211
|
44 |
tsts0=$(( 0 ))
|
|
45 |
fi
|
|
46 |
|
|
47 |
### compilation test
|
|
48 |
|
|
49 |
|
|
50 |
if [ $tsts0 -eq 0 ]
|
|
51 |
then
|
|
52 |
echo "docdiff.scala runs?" >> $out
|
|
53 |
|
|
54 |
if (scala_compile docdiff.scala)
|
|
55 |
then
|
283
|
56 |
echo -e " --> success" >> $out
|
211
|
57 |
tsts=$(( 0 ))
|
|
58 |
else
|
283
|
59 |
echo -e " --> SCALA DID NOT RUN docdiff.scala" >> $out
|
211
|
60 |
tsts=$(( 1 ))
|
|
61 |
fi
|
|
62 |
else
|
|
63 |
tsts=$(( 1 ))
|
|
64 |
fi
|
|
65 |
|
|
66 |
### docdiff clean tests
|
|
67 |
|
|
68 |
if [ $tsts -eq 0 ]
|
|
69 |
then
|
283
|
70 |
echo -e "docdiff.scala tests:" >> $out
|
|
71 |
echo -e " clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" >> $out
|
|
72 |
echo -e " clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" >> $out
|
211
|
73 |
|
|
74 |
if (scala_assert "docdiff.scala" "docdiff_test1.scala")
|
|
75 |
then
|
283
|
76 |
echo -e " --> success\n" >> $out
|
211
|
77 |
else
|
283
|
78 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
211
|
79 |
fi
|
|
80 |
fi
|
|
81 |
|
|
82 |
### docdiff occurrences tests
|
|
83 |
|
|
84 |
if [ $tsts -eq 0 ]
|
|
85 |
then
|
283
|
86 |
echo -e " occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " >> $out
|
|
87 |
echo -e " Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" >> $out
|
|
88 |
echo -e " " >> $out
|
|
89 |
echo -e " occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " >> $out
|
|
90 |
echo -e " Map(\"d\" -> 3, \"b\" -> 2)" >> $out
|
211
|
91 |
|
|
92 |
if (scala_assert "docdiff.scala" "docdiff_test2.scala")
|
|
93 |
then
|
283
|
94 |
echo -e " --> success\n" >> $out
|
211
|
95 |
else
|
283
|
96 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
211
|
97 |
fi
|
|
98 |
fi
|
|
99 |
|
|
100 |
### docdiff prod tests
|
|
101 |
|
|
102 |
if [ $tsts -eq 0 ]
|
|
103 |
then
|
283
|
104 |
echo -e " val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
|
|
105 |
echo -e " val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
|
|
106 |
echo -e " " >> $out
|
|
107 |
echo -e " prod(l1, l2) == 7 " >> $out
|
|
108 |
echo -e " prod(l1, l1) == 7 " >> $out
|
|
109 |
echo -e " prod(l2, l2) == 13 " >> $out
|
211
|
110 |
|
|
111 |
if (scala_assert "docdiff.scala" "docdiff_test3.scala")
|
|
112 |
then
|
283
|
113 |
echo -e " --> success\n" >> $out
|
211
|
114 |
else
|
283
|
115 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
211
|
116 |
fi
|
|
117 |
fi
|
|
118 |
|
|
119 |
### docdiff overlap tests
|
|
120 |
|
|
121 |
if [ $tsts -eq 0 ]
|
|
122 |
then
|
283
|
123 |
echo -e " val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
|
|
124 |
echo -e " val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
|
|
125 |
echo -e " " >> $out
|
|
126 |
echo -e " overlap(l1, l2) == 0.5384615384615384 " >> $out
|
|
127 |
echo -e " overlap(l1, l1) == 1.0 " >> $out
|
|
128 |
echo -e " overlap(l2, l2) == 1.0 " >> $out
|
211
|
129 |
|
|
130 |
if (scala_assert "docdiff.scala" "docdiff_test4.scala")
|
|
131 |
then
|
283
|
132 |
echo -e " --> success\n" >> $out
|
211
|
133 |
else
|
283
|
134 |
echo -e " --> ONE OF THE TESTS FAILED\n" >> $out
|
211
|
135 |
fi
|
|
136 |
fi
|