|
1 #!/bin/bash |
|
2 set -euo pipefail |
|
3 |
|
4 |
|
5 out=${1:-output} |
|
6 |
|
7 echo -e "" > $out |
|
8 |
|
9 echo -e "Below is the feedback for your submission postfix.scala and postfix2.scala" >> $out |
|
10 echo -e "" >> $out |
|
11 |
|
12 # compilation tests |
|
13 |
|
14 function scala_compile { |
|
15 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) |
|
16 } |
|
17 |
|
18 # functional tests |
|
19 |
|
20 function scala_assert { |
|
21 (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) |
|
22 } |
|
23 |
|
24 # purity test |
|
25 |
|
26 function scala_vars { |
|
27 (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) |
|
28 } |
|
29 |
|
30 |
|
31 |
|
32 # compilation test |
|
33 |
|
34 echo -e "postfix.scala runs?" >> $out |
|
35 |
|
36 if (scala_compile postfix.scala) |
|
37 then |
|
38 echo -e " --> yes" >> $out |
|
39 tsts=$(( 0 )) |
|
40 else |
|
41 echo -e " --> SCALA DID NOT RUN postfix.scala\n" >> $out |
|
42 tsts=$(( 1 )) |
|
43 fi |
|
44 |
|
45 |
|
46 # var, return, ListBuffer test |
|
47 # |
|
48 echo -e "postfix.scala does not contain vars, returns etc?" >> $out |
|
49 |
|
50 if [ $tsts -eq 0 ] |
|
51 then |
|
52 if (scala_vars postfix.scala) |
|
53 then |
|
54 echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
|
55 tsts=$(( 1 )) |
|
56 else |
|
57 echo -e " --> success" >> $out |
|
58 tsts=$(( 0 )) |
|
59 fi |
|
60 fi |
|
61 |
|
62 |
|
63 ### postfix tests |
|
64 |
|
65 if [ $tsts -eq 0 ] |
|
66 then |
|
67 echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out |
|
68 echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out |
|
69 echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out |
|
70 echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out |
|
71 |
|
72 if (scala_assert "postfix.scala" "postfix_test7.scala") |
|
73 then |
|
74 echo -e " --> success" >> $out |
|
75 else |
|
76 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
77 fi |
|
78 fi |
|
79 |
|
80 |
|
81 |
|
82 if [ $tsts -eq 0 ] |
|
83 then |
|
84 echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out |
|
85 echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out |
|
86 echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out |
|
87 echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out |
|
88 echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out |
|
89 echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out |
|
90 |
|
91 if (scala_assert "postfix.scala" "postfix_test8.scala") |
|
92 then |
|
93 echo -e " --> success" >> $out |
|
94 else |
|
95 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
96 fi |
|
97 fi |
|
98 |
|
99 echo -e "" >> $out |
|
100 |
|
101 ### postfix2 tests |
|
102 |
|
103 |
|
104 # compilation test |
|
105 |
|
106 echo -e "postfix2.scala runs?" >> $out |
|
107 |
|
108 if (scala_compile postfix2.scala) |
|
109 then |
|
110 echo -e " --> yes" >> $out |
|
111 tsts1=$(( 0 )) |
|
112 else |
|
113 echo -e " --> SCALA DID NOT RUN postfix2.scala\n" >> $out |
|
114 tsts1=$(( 1 )) |
|
115 fi |
|
116 |
|
117 |
|
118 # var, return, ListBuffer test |
|
119 # |
|
120 echo -e "\n\npostfix2.scala does not contain vars, returns etc?" >> $out |
|
121 |
|
122 if [ $tsts1 -eq 0 ] |
|
123 then |
|
124 if (scala_vars postfix2.scala) |
|
125 then |
|
126 echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out |
|
127 tsts1=$(( 1 )) |
|
128 else |
|
129 echo -e " --> success" >> $out |
|
130 tsts1=$(( 0 )) |
|
131 fi |
|
132 fi |
|
133 |
|
134 |
|
135 if [ $tsts1 -eq 0 ] |
|
136 then |
|
137 echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out |
|
138 echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out |
|
139 echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out |
|
140 echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out |
|
141 echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " >> $out |
|
142 echo -e " List(\"3\", \"4\", \"8\", \"\*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" >> $out |
|
143 echo -e " " >> $out |
|
144 echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out |
|
145 echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out |
|
146 echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out |
|
147 echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out |
|
148 echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out |
|
149 echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out |
|
150 echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" >> $out |
|
151 echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" >> $out |
|
152 echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out |
|
153 echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out |
|
154 |
|
155 if (scala_assert "postfix2.scala" "postfix_test9.scala") |
|
156 then |
|
157 echo -e " --> success" >> $out |
|
158 else |
|
159 echo -e " --> \n ONE TEST FAILED\n" >> $out |
|
160 fi |
|
161 fi |
|
162 |