| 168 |      1 | #!/bin/bash
 | 
|  |      2 | 
 | 
|  |      3 | # to make the script fail safely
 | 
|  |      4 | set -euo pipefail
 | 
|  |      5 | 
 | 
|  |      6 | out=${1:-output}
 | 
|  |      7 | 
 | 
|  |      8 | echo "" > $out
 | 
|  |      9 | 
 | 
|  |     10 | 
 | 
|  |     11 | echo "Below is the feedback and provisional marks for your submission" >> $out
 | 
|  |     12 | echo "for assignment 8 Part 1.  Please note all marks are provisional until" >> $out
 | 
|  |     13 | echo "ratified by the assessment board -- this is not an official" >> $out
 | 
|  |     14 | echo "results transcript." >> $out
 | 
|  |     15 | echo "" >> $out
 | 
|  |     16 | 
 | 
|  |     17 | # marks for CW8 part 1
 | 
|  |     18 | marks=$(( 0 ))
 | 
|  |     19 | 
 | 
|  |     20 | # compilation tests
 | 
|  |     21 | 
 | 
|  |     22 | function scala_compile {
 | 
|  |     23 |     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
 | 
|  |     24 | }
 | 
|  |     25 | 
 | 
|  |     26 | # functional tests
 | 
|  |     27 | 
 | 
|  |     28 | function scala_assert {
 | 
|  |     29 |     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
|  |     30 | }
 | 
|  |     31 | 
 | 
|  |     32 | # purity test
 | 
|  |     33 | 
 | 
|  |     34 | function scala_vars {
 | 
|  |     35 |    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
 | 
|  |     36 | }
 | 
|  |     37 | 
 | 
|  |     38 | 
 | 
|  |     39 | # var, return, ListBuffer test
 | 
|  |     40 | #
 | 
|  |     41 | echo "re.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
 | 
|  |     42 | 
 | 
|  |     43 | if (scala_vars re.scala)
 | 
|  |     44 | then
 | 
|  |     45 |   echo "  --> test failed" | tee -a $out
 | 
|  |     46 |   tsts0=$(( 1 ))
 | 
|  |     47 | else
 | 
|  |     48 |   echo "  --> success" | tee -a $out
 | 
|  |     49 |   tsts0=$(( 0 )) 
 | 
|  |     50 | fi
 | 
|  |     51 | 
 | 
|  |     52 | 
 | 
|  |     53 | # compilation test
 | 
|  |     54 | if  [ $tsts0 -eq 0 ]
 | 
|  |     55 | then    
 | 
|  |     56 |   echo "re.scala runs?" | tee -a $out
 | 
|  |     57 | 
 | 
|  |     58 |   if (scala_compile re.scala)
 | 
|  |     59 |   then
 | 
|  |     60 |     echo "  --> success" | tee -a $out
 | 
|  |     61 |     tsts1=$(( 0 ))
 | 
|  |     62 |   else
 | 
|  |     63 |     echo "  --> scala re.scala did not run successfully" | tee -a $out
 | 
|  |     64 |     tsts1=$(( 1 )) 
 | 
|  |     65 |   fi
 | 
|  |     66 | else
 | 
|  |     67 |   tsts1=$(( 1 ))     
 | 
|  |     68 | fi
 | 
|  |     69 | 
 | 
|  |     70 | 
 | 
|  |     71 | 
 | 
|  |     72 | if [ $tsts1 -eq 0 ]
 | 
|  |     73 | then
 | 
|  |     74 |   echo " nullable(ZERO) == false" | tee -a $out
 | 
|  |     75 |   echo " nullable(ONE) == true" | tee -a $out
 | 
|  |     76 |   echo " nullable(CHAR('a')) == false" | tee -a $out
 | 
|  |     77 |   echo " nullable(ZERO | ONE) == true" | tee -a $out
 | 
|  |     78 |   echo " nullable(ZERO | CHAR('a')) == false" | tee -a $out
 | 
|  |     79 |   echo " nullable(ONE ~  ONE) == true" | tee -a $out
 | 
|  |     80 |   echo " nullable(ONE ~ CHAR('a')) == false" | tee -a $out
 | 
|  |     81 |   echo " nullable(STAR(ZERO)) == true" | tee -a $out
 | 
|  |     82 |   
 | 
|  |     83 |   if (scala_assert "re.scala" "re1a_test.scala")
 | 
|  |     84 |   then
 | 
|  |     85 |       echo "  --> success" | tee -a $out
 | 
|  |     86 |       marks=$(( marks + 1 ))
 | 
|  |     87 |   else
 | 
|  |     88 |       echo "  --> test failed" | tee -a $out
 | 
|  |     89 |   fi
 | 
|  |     90 | fi
 | 
|  |     91 | 
 | 
|  |     92 | 
 | 
|  |     93 | 
 | 
|  |     94 | if [ $tsts1 -eq 0 ]
 | 
|  |     95 | then
 | 
|  |     96 |   echo " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out
 | 
|  |     97 |   echo " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out
 | 
|  |     98 |   echo " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out
 | 
|  |     99 |   echo " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out
 | 
|  |    100 |   echo " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out
 | 
|  |    101 |   
 | 
|  |    102 |   if (scala_assert "re.scala" "re1b_test.scala")
 | 
|  |    103 |   then
 | 
|  |    104 |       echo "  --> success" | tee -a $out
 | 
|  |    105 |       marks=$(( marks + 1 ))
 | 
|  |    106 |   else
 | 
|  |    107 |       echo "  --> test failed" | tee -a $out
 | 
|  |    108 |   fi
 | 
|  |    109 | fi
 | 
|  |    110 | 
 | 
|  |    111 | 
 | 
|  |    112 | 
 | 
|  |    113 | if [ $tsts1 -eq 0 ]
 | 
|  |    114 | then
 | 
|  |    115 |   echo " simp(ZERO | ONE) == ONE" | tee -a $out
 | 
|  |    116 |   echo " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out
 | 
|  |    117 |   echo " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out
 | 
|  |    118 |   echo " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out
 | 
|  |    119 |   echo " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out
 | 
|  |    120 |   echo " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out
 | 
|  |    121 |   echo " simp(CHAR('a') ~ CHAR('a')) == CHAR('a') ~ CHAR('a')" | tee -a $out
 | 
|  |    122 |   echo " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out
 | 
|  |    123 |   echo " simp(ALT((CHAR('a') | ZERO) ~ ONE," | tee -a $out
 | 
|  |    124 |   echo "          ((ONE | CHAR('b')) | CHAR('c')) ~ (CHAR('d') ~ ZERO))) == CHAR('a')" | tee -a $out
 | 
|  |    125 |   echo " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out
 | 
|  |    126 |   echo " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out
 | 
|  |    127 |   echo " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out
 | 
|  |    128 |   echo " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
 | 
|  |    129 |   echo "    the Iterator produces the rexp" | tee -a $out
 | 
|  |    130 |   echo "" | tee -a $out
 | 
|  |    131 |   echo "      SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)" | tee -a $out
 | 
|  |    132 |   echo "" | tee -a $out
 | 
|  |    133 |   echo "    where SEQ is nested 50 times." | tee -a $out
 | 
|  |    134 |   if (scala_assert "re.scala" "re1c_test.scala")
 | 
|  |    135 |   then
 | 
|  |    136 |       echo "  --> success" | tee -a $out
 | 
|  |    137 |       marks=$(( marks + 2 ))
 | 
|  |    138 |   else
 | 
|  |    139 |       echo "  --> test failed" | tee -a $out
 | 
|  |    140 |   fi
 | 
|  |    141 | fi
 | 
|  |    142 | 
 | 
|  |    143 | 
 | 
|  |    144 | if [ $tsts1 -eq 0 ]
 | 
|  |    145 | then
 | 
|  |    146 |   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out
 | 
|  |    147 |   echo " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out
 | 
|  |    148 |   echo " ders(List('b'),EVIL) == ONE" | tee -a $out
 | 
|  |    149 |   echo " ders(List('b','b'),EVIL) == ZERO" | tee -a $out
 | 
|  |    150 |   echo " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out
 | 
|  |    151 |   echo " matcher(EVIL, \"a\" * 50 ++ \"b\") == true" | tee -a $out
 | 
|  |    152 |   echo " matcher(EVIL, \"a\" * 50) == false" | tee -a $out
 | 
|  |    153 |   echo " matcher(EVIL, \"b\") == true" | tee -a $out
 | 
|  |    154 |   echo " matcher(EVIL, \"bb\") == false" | tee -a $out
 | 
|  |    155 |   echo " matcher(\"abc\", \"abc\") == true" | tee -a $out
 | 
|  |    156 |   echo " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out
 | 
|  |    157 |   echo " matcher(ONE, \"\") == true" | tee -a $out
 | 
|  |    158 |   echo " matcher(ZERO, \"\") == false" | tee -a $out
 | 
|  |    159 |   echo " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out
 | 
|  |    160 |   echo " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
 | 
|  |    161 |   
 | 
|  |    162 |   if (scala_assert "re.scala" "re1d_test.scala")
 | 
|  |    163 |   then
 | 
|  |    164 |       echo "  --> success" | tee -a $out
 | 
|  |    165 |       marks=$(( marks + 1 ))
 | 
|  |    166 |   else
 | 
|  |    167 |       echo "  --> test failed" | tee -a $out
 | 
|  |    168 |   fi
 | 
|  |    169 | fi
 | 
|  |    170 | 
 | 
|  |    171 | 
 | 
|  |    172 | if [ $tsts1 -eq 0 ]
 | 
|  |    173 | then
 | 
|  |    174 |   echo " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out  
 | 
|  |    175 |   echo " size(der('a', der('a', EVIL))) == 28" | tee -a $out
 | 
|  |    176 |   echo " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out
 | 
|  |    177 |   echo " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out
 | 
|  |    178 |   echo " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
 | 
|  |    179 |   
 | 
|  |    180 |   if (scala_assert "re.scala" "re1e_test.scala")
 | 
|  |    181 |   then
 | 
|  |    182 |       echo "  --> success" | tee -a $out
 | 
|  |    183 |       marks=$(( marks + 1 ))
 | 
|  |    184 |   else
 | 
|  |    185 |       echo "  --> test failed" | tee -a $out
 | 
|  |    186 |   fi
 | 
|  |    187 | fi
 | 
|  |    188 | 
 | 
|  |    189 | 
 | 
|  |    190 | ## final marks
 | 
|  |    191 | echo "Overall mark for CW 8, Part 1" | tee -a $out
 | 
|  |    192 | echo "$marks" | tee -a $out
 | 
|  |    193 | 
 | 
|  |    194 | 
 |