|
1 #!/bin/bash |
|
2 set -e |
|
3 |
|
4 out=${1:-output} |
|
5 |
|
6 echo "" > $out |
|
7 |
|
8 echo "Below is the feedback for your submission of CW 8, Part 2." >> $out |
|
9 echo "" >> $out |
|
10 |
|
11 |
|
12 # compilation tests |
|
13 |
|
14 function scala_compile { |
|
15 (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) |
|
16 } |
|
17 |
|
18 # functional tests |
|
19 |
|
20 function scala_assert { |
|
21 (ulimit -t 30 -m 1024000 ; 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|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) |
|
28 } |
|
29 |
|
30 |
|
31 # var, return, ListBuffer test |
|
32 # |
|
33 echo "bf.scala does not contain vars, returns etc?" >> $out |
|
34 |
|
35 if (scala_vars bf.scala) |
|
36 then |
|
37 echo " --> fail" >> $out |
|
38 tsts0=$(( 1 )) |
|
39 else |
|
40 echo " --> success" >> $out |
|
41 tsts0=$(( 0 )) |
|
42 fi |
|
43 |
|
44 |
|
45 # compilation test |
|
46 if [ $tsts0 -eq 0 ] |
|
47 then |
|
48 echo "bf.scala runs?" >> $out |
|
49 |
|
50 if (scala_compile bf.scala) |
|
51 then |
|
52 echo " --> success" >> $out |
|
53 tsts1=$(( 0 )) |
|
54 else |
|
55 echo " --> scala bf.scala did not run successfully" >> $out |
|
56 tsts1=$(( 1 )) |
|
57 fi |
|
58 else |
|
59 tsts1=$(( 1 )) |
|
60 fi |
|
61 |
|
62 |
|
63 |
|
64 if [ $tsts1 -eq 0 ] |
|
65 then |
|
66 echo " sread(Map(), 2) == 0" >> $out |
|
67 echo " sread(Map(2 -> 1), 2) == 1" >> $out |
|
68 echo " write(Map(), 1, 2) == Map(1 -> 2)" >> $out |
|
69 echo " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out |
|
70 |
|
71 if (scala_assert "bf.scala" "bf1a_test.scala") |
|
72 then |
|
73 echo " --> success" >> $out |
|
74 else |
|
75 echo " --> test failed" >> $out |
|
76 fi |
|
77 fi |
|
78 |
|
79 |
|
80 |
|
81 if [ $tsts1 -eq 0 ] |
|
82 then |
|
83 echo " jumpRight(\"[******]***\", 1, 0) == 8" >> $out |
|
84 echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out |
|
85 echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out |
|
86 echo " jumpRight(\"[**[***]***\", 1, 0) == 11" >> $out |
|
87 echo " jumpRight(\"[*[][]*]***\", 1, 0) == 8" >> $out |
|
88 echo " jumpLeft(\"[******]***\", 6, 0) == 1" >> $out |
|
89 echo " jumpLeft(\"[******]***\", 7, 0) == -1" >> $out |
|
90 echo " jumpLeft(\"[*[][]*]***\", 6, 0) == 1" >> $out |
|
91 |
|
92 if (scala_assert "bf.scala" "bf1b_test.scala") |
|
93 then |
|
94 echo " --> success" >> $out |
|
95 else |
|
96 echo " --> test failed" >> $out |
|
97 fi |
|
98 fi |
|
99 |
|
100 |
|
101 |
|
102 if [ $tsts1 -eq 0 ] |
|
103 then |
|
104 echo " start(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out |
|
105 echo " start(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out |
|
106 echo " start(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out |
|
107 echo " start({{hello world prg 1}}, Map()) == " >> $out |
|
108 echo " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" >> $out |
|
109 |
|
110 if (scala_assert "bf.scala" "bf1c_test.scala") |
|
111 then |
|
112 echo " --> success" >> $out |
|
113 else |
|
114 echo " --> test failed" >> $out |
|
115 fi |
|
116 fi |
|
117 |
|
118 |
|
119 |
|
120 |