main_marking3/re_test.sh
changeset 424 daf561a83ba6
parent 390 175a950470a9
child 426 b51467741af2
equal deleted inserted replaced
423:e9d14d58be3c 424:daf561a83ba6
     1 #!/bin/bash
     1 #!/bin/zsh
     2 
     2 
     3 # to make the script fail safely
     3 # to make the script fail safely
     4 set -euo pipefail
     4 set -euo pipefail
     5 
     5 
     6 out=${1:-output}
     6 out=${1:-output}
    14 echo -e "ratified by the assessment board -- this is not an official" >> $out
    14 echo -e "ratified by the assessment board -- this is not an official" >> $out
    15 echo -e "results transcript." >> $out
    15 echo -e "results transcript." >> $out
    16 echo -e "" >> $out
    16 echo -e "" >> $out
    17 
    17 
    18 # marks for CW8
    18 # marks for CW8
    19 marks=$(( 0 ))
    19 marks=$(( 0.0 ))
    20 
    20 
    21 # compilation tests
    21 # compilation tests
    22 
    22 
    23 function scala_compile {
    23 function scala_compile {
    24   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    24   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    33 function scala_assert_thirty {
    33 function scala_assert_thirty {
    34   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
    34   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
    35 }
    35 }
    36 
    36 
    37 # purity test
    37 # purity test
    38 
       
    39 function scala_vars {
    38 function scala_vars {
    40    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
    39    (sed 's/immutable/ok/g' c$out > cb$out;
       
    40     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
    41 }
    41 }
       
    42 
    42 
    43 
    43 echo -e "" >> $out
    44 echo -e "" >> $out
    44 echo -e  "Below is the feedback for your submission re.scala" >> $out
    45 echo -e  "Below is the feedback for your submission re.scala" >> $out
    45 echo -e  "" >> $out
    46 echo -e  "" >> $out
    46 
    47 
    95   echo -e " nullable(STAR(ZERO)) == true" | tee -a $out
    96   echo -e " nullable(STAR(ZERO)) == true" | tee -a $out
    96   
    97   
    97   if (scala_assert "re.scala" "re_test1.scala")
    98   if (scala_assert "re.scala" "re_test1.scala")
    98   then
    99   then
    99       echo -e "  --> success" | tee -a $out
   100       echo -e "  --> success" | tee -a $out
   100       marks=$(( marks + 1 ))
   101       marks=$(( marks + 0.5 ))
   101   else
   102   else
   102       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   103       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   103   fi
   104   fi
   104 fi
   105 fi
   105 
   106 
   129   echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE)" | tee -a $out
   130   echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE)" | tee -a $out
   130 
   131 
   131   if (scala_assert "re.scala" "re_test2.scala")
   132   if (scala_assert "re.scala" "re_test2.scala")
   132   then
   133   then
   133       echo -e "  --> success" | tee -a $out
   134       echo -e "  --> success" | tee -a $out
   134       marks=$(( marks + 1 ))
   135       marks=$(( marks + 1.0 ))
   135   else
   136   else
   136       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   137       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   137   fi
   138   fi
   138 fi
   139 fi
   139 
   140 
   159   echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" | tee -a $out
   160   echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" | tee -a $out
   160   
   161   
   161   if (scala_assert "re.scala" "re_test3.scala")
   162   if (scala_assert "re.scala" "re_test3.scala")
   162   then
   163   then
   163       echo -e "  --> success" | tee -a $out
   164       echo -e "  --> success" | tee -a $out
   164       marks=$(( marks + 1 ))
   165       marks=$(( marks + 1.0 ))
   165   else
   166   else
   166       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   167       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   167   fi
   168   fi
   168 fi
   169 fi
       
   170 
       
   171 ### re3a flts test
       
   172 
       
   173 if [ $tsts -eq 0 ]
       
   174 then
       
   175   echo -e " flts(Nil) == Nil" | tee -a $out
       
   176   echo -e " flts(ZERO::ZERO::Nil) == Nil" | tee -a $out
       
   177   echo -e " flts(ZERO::ONE::ZERO::ONE::Nil) == List(ONE, ONE)" | tee -a $out
       
   178   echo -e " flts(ONE::ALTs(List(ONE))::ONE::Nil) == List(ONE, ONE, ONE)" | tee -a $out
       
   179   echo -e " flts(ONE::ALTs(List(ONE))::ONE::ALTs(List(ONE))::Nil) == List(ONE, ONE, ONE, ONE)" | tee -a $out
       
   180   
       
   181   if (scala_assert "re.scala" "re_test3a.scala")
       
   182   then
       
   183       echo -e "  --> success" | tee -a $out
       
   184       marks=$(( marks + 1.0 ))
       
   185   else
       
   186       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   187   fi
       
   188 fi
       
   189 
       
   190 
   169 
   191 
   170 ### re4 test
   192 ### re4 test
   171 
   193 
   172 if [ $tsts -eq 0 ]
   194 if [ $tsts -eq 0 ]
   173 then
   195 then
   189   echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
   211   echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out
   190   
   212   
   191   if (scala_assert "re.scala" "re_test4.scala")
   213   if (scala_assert "re.scala" "re_test4.scala")
   192   then
   214   then
   193       echo -e "  --> success" | tee -a $out
   215       echo -e "  --> success" | tee -a $out
   194       marks=$(( marks + 1 ))
   216       marks=$(( marks + 1.0 ))
   195   else
   217   else
   196       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   218       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   197   fi
   219   fi
   198 fi
   220 fi
   199 
   221 
   209   echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
   231   echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out
   210   
   232   
   211   if (scala_assert "re.scala" "re_test5.scala")
   233   if (scala_assert "re.scala" "re_test5.scala")
   212   then
   234   then
   213       echo -e "  --> success" | tee -a $out
   235       echo -e "  --> success" | tee -a $out
   214       marks=$(( marks + 1 ))
   236       marks=$(( marks + 0.5 ))
   215   else
   237   else
   216       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   238       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   217   fi
   239   fi
   218 fi
   240 fi
   219 
   241 
   220 ### re6 'power' test 1
   242 ### re6 'power' test 1
   221 
   243 
   222 sleep 5
       
   223 
   244 
   224 if [ $tsts -eq 0 ]
   245 if [ $tsts -eq 0 ]
   225 then
   246 then
   226   echo -e " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
   247   echo -e " simp(Iterator.iterate(ONE:Rexp)(r => SEQ(r, ONE | ONE)).drop(50).next) == ONE" | tee -a $out
   227   echo -e "    ...the Iterator produces the rexp" | tee -a $out
   248   echo -e "    ...the Iterator produces the rexp" | tee -a $out
   238   then
   259   then
   239       END=$(date +%s)
   260       END=$(date +%s)
   240       DIFF=$(( $END - $START ))
   261       DIFF=$(( $END - $START ))
   241       echo "   This test ran for $DIFF seconds" | tee -a $out
   262       echo "   This test ran for $DIFF seconds" | tee -a $out
   242       echo -e "  --> success" | tee -a $out
   263       echo -e "  --> success" | tee -a $out
   243       marks=$(( marks + 1 ))
   264       marks=$(( marks + 0.5 ))
   244   else
   265   else
   245       END=$(date +%s)
   266       END=$(date +%s)
   246       DIFF=$(( $END - $START ))
   267       DIFF=$(( $END - $START ))
   247       echo "  This test ran for $DIFF seconds" | tee -a $out
   268       echo "  This test ran for $DIFF seconds" | tee -a $out
   248       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   269       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   249   fi
   270   fi
   250 fi
   271 fi
   251 
   272 
   252 sleep 10
       
   253 
   273 
   254 ### re7 'power' test 2
   274 ### re7 'power' test 2
   255 
   275 
   256 if [ $tsts -eq 0 ]
   276 if [ $tsts -eq 0 ]
   257 then
   277 then
   264   then
   284   then
   265       END=$(date +%s)
   285       END=$(date +%s)
   266       DIFF=$(( $END - $START ))
   286       DIFF=$(( $END - $START ))
   267       echo "   This test ran for $DIFF seconds" | tee -a $out
   287       echo "   This test ran for $DIFF seconds" | tee -a $out
   268       echo -e "  --> success" | tee -a $out
   288       echo -e "  --> success" | tee -a $out
   269       marks=$(( marks + 1 ))
   289       marks=$(( marks + 0.5 ))
   270   else
   290   else
   271       END=$(date +%s)
   291       END=$(date +%s)
   272       DIFF=$(( $END - $START ))
   292       DIFF=$(( $END - $START ))
   273       echo "  This test ran for $DIFF seconds" | tee -a $out
   293       echo "  This test ran for $DIFF seconds" | tee -a $out
   274       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   294       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   275   fi
   295   fi
   276 fi
   296 fi
   277 
   297 
   278 sleep 10
   298 
   279 
   299 
   280 ## final marks
   300 ## final marks
   281 echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out
   301 echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out
   282 echo -e "$marks" | tee -a $out
   302 printf " %0.1f\n" $marks | tee -a $out
   283 
   303 
   284 
   304 
       
   305