main_marking5/bf_test.sh
changeset 424 daf561a83ba6
parent 394 839ad118e467
child 463 0315d9983cd0
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 
     6 
    15 echo -e "ratified by the assessment board -- this is not an official" >> $out
    15 echo -e "ratified by the assessment board -- this is not an official" >> $out
    16 echo -e "results transcript." >> $out
    16 echo -e "results transcript." >> $out
    17 echo -e "" >> $out
    17 echo -e "" >> $out
    18 
    18 
    19 # marks for CW10 part 1
    19 # marks for CW10 part 1
    20 marks=$(( 0 ))
    20 marks=$(( 0.0 ))
    21 
    21 
    22 # compilation tests
    22 # compilation tests
    23 
    23 
    24 function scala_compile {
    24 function scala_compile {
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    34 function scala_assert_thirty {
    34 function scala_assert_thirty {
    35   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
    35   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
    36 }
    36 }
    37 
    37 
    38 # purity test
    38 # purity test
    39 
       
    40 function scala_vars {
    39 function scala_vars {
    41    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
    40    (sed 's/immutable/ok/g' c$out > cb$out;
       
    41     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
    42 }
    42 }
    43 
    43 
    44 
    44 
    45 
    45 
    46 echo -e "" >> $out
    46 echo -e "" >> $out
    88   echo -e " load_bff(\"foobar.bf\") == \"\"" | tee -a $out  
    88   echo -e " load_bff(\"foobar.bf\") == \"\"" | tee -a $out  
    89    
    89    
    90   if (scala_assert "bf.scala" "bf_test1.scala")
    90   if (scala_assert "bf.scala" "bf_test1.scala")
    91   then
    91   then
    92       echo -e "  --> success" | tee -a $out
    92       echo -e "  --> success" | tee -a $out
    93       marks=$(( marks + 1 ))
    93       marks=$(( marks + 0.5 ))
    94   else
    94   else
    95       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
    95       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
    96   fi
    96   fi
    97 fi
    97 fi
    98 
    98 
   107   echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out
   107   echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" | tee -a $out
   108   
   108   
   109   if (scala_assert "bf.scala" "bf_test2.scala")
   109   if (scala_assert "bf.scala" "bf_test2.scala")
   110   then
   110   then
   111       echo -e "  --> success" | tee -a $out
   111       echo -e "  --> success" | tee -a $out
   112       marks=$(( marks + 1 ))
   112       marks=$(( marks + 0.5 ))
   113   else
   113   else
   114       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   114       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   115   fi
   115   fi
   116 fi
   116 fi
   117 
   117 
   129     echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" | tee -a $out
   129     echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" | tee -a $out
   130   
   130   
   131   if (scala_assert "bf.scala" "bf_test3.scala")
   131   if (scala_assert "bf.scala" "bf_test3.scala")
   132   then
   132   then
   133       echo -e "  --> success" | tee -a $out
   133       echo -e "  --> success" | tee -a $out
   134       marks=$(( marks + 2 ))
   134       marks=$(( marks + 2.0 ))
   135   else
   135   else
   136       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   136       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   137   fi
   137   fi
   138 fi
   138 fi
   139 
   139 
   142 if [ $tsts -eq 0 ]
   142 if [ $tsts -eq 0 ]
   143 then
   143 then
   144   echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
   144   echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out
   145   echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
   145   echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out
   146   echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
   146   echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out
   147   echo -e " run(\"++++++++++#>+***#\") == Map(0 -> 10, 1 -> 1000)" | tee -a $out
       
   148   echo -e " run(\"+++>+@+@+@+@+@\") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)" | tee -a $out
       
   149   
   147   
   150   echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
   148   echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out
   151   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
   149   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out
   152   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
   150   echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out
   153   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
   151   echo -e "               +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out
   154   echo -e " run(hello, Map()) == " | tee -a $out
   152   echo -e " run(hello, Map()) == " | tee -a $out
   155   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   153   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   156   
   154   
   157   if (scala_assert "bf.scala" "bf_test4.scala")
   155   if (scala_assert "bf.scala" "bf_test4.scala")
   158   then
   156   then
   159       echo -e "  --> success" | tee -a $out
   157       echo -e "  --> success (mark 1%)" | tee -a $out
   160       marks=$(( marks + 1 ))
   158       marks=$(( marks + 1.0 ))
   161   else
   159   else
   162       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   160       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   163   fi
   161   fi
   164 fi
   162 fi
   165 
   163 
   166 sleep 10
       
   167 
   164 
   168 if [ $tsts -eq 0 ]
   165 if [ $tsts -eq 0 ]
   169 then
   166 then
   170   echo -e " val bench_small = \"\"\">+[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++" | tee -a $out
   167   echo -e " val bench_small = \"\"\">+[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++" | tee -a $out
   171   echo -e "  [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++" | tee -a $out
   168   echo -e "  [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++" | tee -a $out
   178   if (scala_assert_thirty "bf.scala" "bf_test4b.scala")
   175   if (scala_assert_thirty "bf.scala" "bf_test4b.scala")
   179   then
   176   then
   180       END=$(date +%s)
   177       END=$(date +%s)
   181       DIFF=$(( $END - $START ))
   178       DIFF=$(( $END - $START ))
   182       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
   179       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
   183       echo -e "  --> success" | tee -a $out
   180       echo -e "  --> success (mark 1%)" | tee -a $out
   184       marks=$(( marks + 1 ))
   181       marks=$(( marks + 1.0 ))
   185   else
   182   else
   186       END=$(date +%s)
   183       END=$(date +%s)
   187       DIFF=$(( $END - $START ))
   184       DIFF=$(( $END - $START ))
   188       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
   185       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
   189       echo -e "  --> TEST FAILED\n" | tee -a $out
   186       echo -e "  --> TEST FAILED\n" | tee -a $out
   190   fi
   187   fi
   191 fi
   188 fi
   192 
   189 
   193 sleep 10
       
   194 
   190 
   195 echo -e "" >> $out
   191 echo -e "" >> $out
   196 echo -e "Below is the feedback for your submission of bfc.scala" >> $out
   192 echo -e "Below is the feedback for your submission of bfc.scala" >> $out
   197 echo -e "" >> $out
   193 echo -e "" >> $out
   198 
   194 
   248   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   244   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   249   
   245   
   250   if (scala_assert "bfc.scala" "bf_test5.scala")
   246   if (scala_assert "bfc.scala" "bf_test5.scala")
   251   then
   247   then
   252       echo -e "  --> success" | tee -a $out
   248       echo -e "  --> success" | tee -a $out
   253       marks=$(( marks + 1 ))
   249       marks=$(( marks + 1.0 ))
   254   else
   250   else
   255       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   251       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   256   fi
   252   fi
   257 fi
   253 fi
   258 
   254 
   274   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   270   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   275   
   271   
   276   if (scala_assert "bfc.scala" "bf_test6.scala")
   272   if (scala_assert "bfc.scala" "bf_test6.scala")
   277   then
   273   then
   278       echo -e "  --> success" | tee -a $out
   274       echo -e "  --> success" | tee -a $out
   279       marks=$(( marks + 1 ))
   275       marks=$(( marks + 1.0 ))
   280   else
   276   else
   281       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   277       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   282   fi
   278   fi
   283 fi
   279 fi
   284 
   280 
   299   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   295   echo -e "       Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out
   300   
   296   
   301   if (scala_assert "bfc.scala" "bf_test7.scala")
   297   if (scala_assert "bfc.scala" "bf_test7.scala")
   302   then
   298   then
   303       echo -e "  --> success (+ 2%)" | tee -a $out
   299       echo -e "  --> success (+ 2%)" | tee -a $out
   304       marks=$(( marks + 2 ))
   300       marks=$(( marks + 2.0 ))
   305   else
   301   else
   306       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   302       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
   307   fi
   303   fi
   308 fi
   304 fi
   309 
   305 
   310 
   306 
   311 ## final marks
   307 ## final marks
   312 echo -e "Overall mark for Part 5 (Scala)" | tee -a $out
   308 echo -e "Overall mark for Part 5 (Scala)" | tee -a $out
   313 echo -e "$marks" | tee -a $out
   309 printf " %0.1f\n" $marks | tee -a $out
   314 
   310 
   315 sleep 12