core_marking3/postfix_test.sh
changeset 424 daf561a83ba6
parent 394 839ad118e467
child 463 0315d9983cd0
equal deleted inserted replaced
423:e9d14d58be3c 424:daf561a83ba6
       
     1 #!/bin/zsh
       
     2 set -euo pipefail
       
     3 
       
     4 
       
     5 out=${1:-output}
       
     6 
       
     7 echo -e "" > $out
       
     8 
       
     9 echo `date` >> $out
       
    10 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    11 echo -e "of the Core Part 3 (Scala).  Please note all marks are provisional until" >> $out
       
    12 echo -e "ratified by the assessment board -- this is not an official" >> $out
       
    13 echo -e "results transcript." >> $out
       
    14 echo -e "" >> $out
       
    15 
       
    16 echo -e "Below is the feedback for your submission docdiff.scala" >> $out
       
    17 echo -e "" >> $out
       
    18 
       
    19 
       
    20 # marks for CW9 preliminary
       
    21 marks=$(( 0.0 ))
       
    22 
       
    23 
       
    24 # compilation tests
       
    25 
       
    26 function scala_compile {
       
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    28 }
       
    29 
       
    30 # functional tests
       
    31 
       
    32 function scala_assert {
       
    33   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    34 }
       
    35 
       
    36 # purity test
       
    37 function scala_vars {
       
    38    (sed 's/immutable/ok/g' c$out > cb$out;
       
    39     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
       
    40 }
       
    41 
       
    42 
       
    43 # compilation test
       
    44 
       
    45 echo -e "postfix.scala runs?" | tee -a $out
       
    46 
       
    47 if (scala_compile postfix.scala)
       
    48 then
       
    49    echo -e "  --> success" | tee -a $out
       
    50    tsts=$(( 0 ))
       
    51 else
       
    52    echo -e "  --> SCALA DID NOT RUN postfix.scala\n" | tee -a $out
       
    53    tsts=$(( 1 ))
       
    54 fi
       
    55 
       
    56 
       
    57 
       
    58 # var, return, ListBuffer test
       
    59 #
       
    60 if  [ $tsts -eq 0 ]
       
    61   then   
       
    62   echo -e "postfix.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
    63 
       
    64   if (scala_vars postfix.scala)
       
    65   then
       
    66     echo -e "  --> FAIL\n" | tee -a $out  
       
    67     tsts=$(( 1 ))
       
    68   else
       
    69     echo -e "  --> success" | tee -a $out  
       
    70     tsts=$(( 0 )) 
       
    71   fi
       
    72 else
       
    73   tsts=$(( 1 ))  
       
    74 fi  
       
    75 
       
    76 
       
    77 
       
    78 ### postfix tests
       
    79 
       
    80 if [ $tsts -eq 0 ]
       
    81 then
       
    82   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out
       
    83   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out
       
    84   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out
       
    85   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out
       
    86   
       
    87   if (scala_assert "postfix.scala" "postfix_test1.scala")
       
    88   then
       
    89     echo -e "  --> success" | tee -a $out
       
    90     marks=$(( marks + 1.0 ))
       
    91   else
       
    92     echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
    93   fi
       
    94 fi
       
    95 
       
    96 
       
    97 
       
    98 if [ $tsts -eq 0 ]
       
    99 then
       
   100   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out
       
   101   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out
       
   102   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out
       
   103   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out
       
   104   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out
       
   105   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out
       
   106   
       
   107   if (scala_assert "postfix.scala" "postfix_test2.scala")
       
   108   then
       
   109      echo -e "  --> success" | tee -a $out
       
   110      marks=$(( marks + 1.0 ))
       
   111   else
       
   112      echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   113   fi
       
   114 fi
       
   115 
       
   116 
       
   117 
       
   118 ### postfix2 tests
       
   119 
       
   120 echo -e "Below is the feedback for your submission postfix2.scala" >> $out
       
   121 echo -e "" >> $out
       
   122 
       
   123 # compilation test
       
   124 
       
   125 echo -e "postfix2.scala runs?" | tee -a $out
       
   126 
       
   127 if (scala_compile postfix2.scala)
       
   128 then
       
   129    echo -e "  --> success" | tee -a $out
       
   130    tsts=$(( 0 ))
       
   131 else
       
   132    echo -e "  --> SCALA DID NOT RUN postfix2.scala\n" | tee -a $out
       
   133    tsts=$(( 1 )) 
       
   134 fi
       
   135 
       
   136 
       
   137 # var, return, ListBuffer test
       
   138 #
       
   139 if  [ $tsts -eq 0 ]
       
   140 then     
       
   141   echo -e "postfix2.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
   142 
       
   143   if (scala_vars postfix2.scala)
       
   144   then
       
   145     echo -e "  --> FAIL\n" | tee -a $out  
       
   146     tsts=$(( 1 ))
       
   147   else
       
   148     echo -e "  --> success" | tee -a $out  
       
   149     tsts=$(( 0 )) 
       
   150   fi
       
   151 else
       
   152   tsts=$(( 1 ))  
       
   153 fi
       
   154 
       
   155 
       
   156 
       
   157 
       
   158 if [ $tsts -eq 0 ]
       
   159 then
       
   160   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out
       
   161   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out
       
   162   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out
       
   163   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out
       
   164   echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " | tee -a $out
       
   165   echo -e "         List(\"3\", \"4\", \"8\", \"*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" | tee -a $out
       
   166   
       
   167   if (scala_assert "postfix2.scala" "postfix_test3.scala")
       
   168   then
       
   169       echo -e "  --> success" | tee -a $out
       
   170       marks=$(( marks + 0.5 ))
       
   171   else
       
   172       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   173   fi
       
   174 fi
       
   175 
       
   176 if [ $tsts -eq 0 ]
       
   177 then
       
   178   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out
       
   179   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out
       
   180   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out
       
   181   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out
       
   182   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out
       
   183   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out
       
   184   echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" | tee -a $out
       
   185   echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" | tee -a $out
       
   186   echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" | tee -a $out
       
   187   echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" | tee -a $out
       
   188   
       
   189   if (scala_assert "postfix2.scala" "postfix_test4.scala")
       
   190   then
       
   191       echo -e "  --> success" | tee -a $out
       
   192       marks=$(( marks + 0.5 ))
       
   193   else
       
   194       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   195   fi
       
   196 fi
       
   197 
       
   198 ## final marks
       
   199 echo -e "Overall mark for the Core Part 3 (Scala)" | tee -a $out
       
   200 printf " %0.1f\n" $marks | tee -a $out
       
   201