marking4/postfix_test.sh
changeset 486 9c03b5e89a2a
parent 485 19b75e899d37
child 487 efad9725dfd8
equal deleted inserted replaced
485:19b75e899d37 486:9c03b5e89a2a
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 
       
     5 out=${1:-output}
       
     6 
       
     7 echo -e "" > $out
       
     8 
       
     9 
       
    10 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    11 echo -e "of Preliminar 9.  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 # marks for CW9 preliminary
       
    17 marks=$(( 0 ))
       
    18 
       
    19 
       
    20 # compilation tests
       
    21 
       
    22 function scala_compile {
       
    23   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)   
       
    24 }
       
    25 
       
    26 # functional tests
       
    27 
       
    28 function scala_assert {
       
    29   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 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     (egrep '\bvar\b|\breturn\b|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    37 }
       
    38 
       
    39 
       
    40 
       
    41 # var, return, ListBuffer test
       
    42 #
       
    43 echo -e "postfix.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    44 
       
    45 if (scala_vars postfix.scala)
       
    46 then
       
    47   echo -e "  --> FAIL\n" | tee -a $out  
       
    48   tsts0=$(( 1 ))
       
    49 else
       
    50   echo -e "  --> success" | tee -a $out  
       
    51   tsts0=$(( 0 )) 
       
    52 fi
       
    53 
       
    54 # compilation test
       
    55 if  [ $tsts0 -eq 0 ]
       
    56 then    
       
    57   echo -e "postfix.scala runs?" | tee -a $out
       
    58 
       
    59   if (scala_compile postfix.scala)
       
    60   then
       
    61     echo -e "  --> success" | tee -a $out
       
    62     tsts1=$(( 0 ))
       
    63   else
       
    64     echo -e "  --> SCALA DID NOT RUN postfix.scala" | tee -a $out
       
    65     tsts1=$(( 1 )) 
       
    66   fi
       
    67 else
       
    68   tsts1=$(( 1 ))     
       
    69 fi
       
    70 
       
    71 
       
    72 ### postfix tests
       
    73 
       
    74 if [ $tsts1 -eq 0 ]
       
    75 then
       
    76   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out
       
    77   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out
       
    78   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out
       
    79   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out
       
    80   
       
    81   if (scala_assert "postfix.scala" "postfix_test7.scala")
       
    82   then
       
    83     echo -e "  --> success" | tee -a $out
       
    84     marks=$(( marks + 1 ))
       
    85   else
       
    86     echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
    87   fi
       
    88 fi
       
    89 
       
    90 
       
    91 
       
    92 if [ $tsts1 -eq 0 ]
       
    93 then
       
    94   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out
       
    95   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out
       
    96   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out
       
    97   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out
       
    98   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out
       
    99   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out
       
   100   
       
   101   if (scala_assert "postfix.scala" "postfix_test8.scala")
       
   102   then
       
   103      echo -e "  --> success" | tee -a $out
       
   104      marks=$(( marks + 1 ))
       
   105   else
       
   106      echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   107   fi
       
   108 fi
       
   109 
       
   110 
       
   111 
       
   112 ### postfix2 tests
       
   113 
       
   114 # var, return, ListBuffer test
       
   115 #
       
   116 echo -e "postfix2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
   117 
       
   118 if (scala_vars postfix2.scala)
       
   119 then
       
   120   echo -e "  --> FAIL\n" | tee -a $out  
       
   121   tsts0=$(( 1 ))
       
   122 else
       
   123   echo -e "  --> success" | tee -a $out  
       
   124   tsts0=$(( 0 )) 
       
   125 fi
       
   126 
       
   127 
       
   128 # compilation test
       
   129 
       
   130 if  [ $tsts0 -eq 0 ]
       
   131 then    
       
   132   echo -e "postfix2.scala runs?" | tee -a $out
       
   133 
       
   134   if (scala_compile postfix2.scala)
       
   135   then
       
   136     echo -e "  --> success" | tee -a $out
       
   137     tsts1=$(( 0 ))
       
   138   else
       
   139     echo -e "  --> SCALA DID NOT RUN postfix2.scala" | tee -a $out
       
   140     tsts1=$(( 1 )) 
       
   141   fi
       
   142 else
       
   143   tsts1=$(( 1 ))     
       
   144 fi
       
   145 
       
   146 
       
   147 if [ $tsts1 -eq 0 ]
       
   148 then
       
   149   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"*\", \"+\")" | tee -a $out
       
   150   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" | tee -a $out
       
   151   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" | tee -a $out
       
   152   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"*\", \"2\", \"/\")" | tee -a $out
       
   153   echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " | tee -a $out
       
   154   echo -e "         List(\"3\", \"4\", \"8\", \"*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" | tee -a $out
       
   155   
       
   156   if (scala_assert "postfix2.scala" "postfix_test9.scala")
       
   157   then
       
   158       echo -e "  --> success" | tee -a $out
       
   159       marks=$(( marks + 1 ))
       
   160   else
       
   161       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   162   fi
       
   163 fi
       
   164 
       
   165 if [ $tsts1 -eq 0 ]
       
   166 then
       
   167   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" | tee -a $out
       
   168   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" | tee -a $out
       
   169   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" | tee -a $out
       
   170   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" | tee -a $out
       
   171   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" | tee -a $out
       
   172   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" | tee -a $out
       
   173   echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" | tee -a $out
       
   174   echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" | tee -a $out
       
   175   echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" | tee -a $out
       
   176   echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" | tee -a $out
       
   177   
       
   178   if (scala_assert "postfix2.scala" "postfix_test10.scala")
       
   179   then
       
   180       echo -e "  --> success" | tee -a $out
       
   181       marks=$(( marks + 1 ))
       
   182   else
       
   183       echo -e "  --> ONE OF THE TESTS FAILED\n" | tee -a $out
       
   184   fi
       
   185 fi
       
   186 
       
   187 ## final marks
       
   188 echo -e "Overall mark for CW 9, Preliminary Part" | tee -a $out
       
   189 echo -e "$marks" | tee -a $out