testing4/postfix_test.sh
changeset 346 663c2a9108d1
parent 345 40657f9a4e4a
child 347 4de31fdc0d67
equal deleted inserted replaced
345:40657f9a4e4a 346:663c2a9108d1
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 
       
     5 out=${1:-output}
       
     6 
       
     7 echo -e "" > $out
       
     8 
       
     9 echo -e "Below is the feedback for your submission of CW 9, Preliminary Part." >> $out
       
    10 echo -e "" >> $out
       
    11 
       
    12 
       
    13 # compilation tests
       
    14 
       
    15 function scala_compile {
       
    16   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)   
       
    17 }
       
    18 
       
    19 # functional tests
       
    20 
       
    21 function scala_assert {
       
    22   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null) 
       
    23 }
       
    24 
       
    25 # purity test
       
    26 
       
    27 function scala_vars {
       
    28    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    29 }
       
    30 
       
    31 
       
    32 # var, return, ListBuffer test
       
    33 #
       
    34 echo -e "postfix.scala does not contain vars, returns etc?" >> $out
       
    35 
       
    36 if (scala_vars postfix.scala)
       
    37 then
       
    38   echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out 
       
    39   tsts0=$(( 0 ))
       
    40 else
       
    41   echo -e "  --> success" >> $out
       
    42   tsts0=$(( 0 )) 
       
    43 fi
       
    44 
       
    45 
       
    46 # compilation test
       
    47 
       
    48 if  [ $tsts0 -eq 0 ]
       
    49 then    
       
    50   echo -e "postfix.scala runs?" >> $out
       
    51 
       
    52   if (scala_compile postfix.scala)
       
    53   then
       
    54     echo -e "  --> yes" >> $out
       
    55     tsts1=$(( 0 ))
       
    56   else
       
    57     echo -e "  --> SCALA DID NOT RUN POSTFIX.SCALA\n" >> $out
       
    58     tsts1=$(( 1 )) 
       
    59   fi
       
    60 else
       
    61   tsts1=$(( 1 ))     
       
    62 fi
       
    63 
       
    64 ### postfix tests
       
    65 
       
    66 if [ $tsts1 -eq 0 ]
       
    67 then
       
    68   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
       
    69   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
       
    70   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
       
    71   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out
       
    72   
       
    73   if (scala_assert "postfix.scala" "postfix_test7.scala")
       
    74   then
       
    75     echo -e "  --> success" >> $out
       
    76   else
       
    77     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    78   fi
       
    79 fi
       
    80 
       
    81 
       
    82 
       
    83 if [ $tsts1 -eq 0 ]
       
    84 then
       
    85   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out
       
    86   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out
       
    87   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
       
    88   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
       
    89   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
       
    90   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
       
    91   
       
    92   if (scala_assert "postfix.scala" "postfix_test8.scala")
       
    93   then
       
    94     echo -e "  --> success" >> $out
       
    95   else
       
    96     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    97   fi
       
    98 fi
       
    99 
       
   100 echo -e "" >> $out
       
   101 
       
   102 ### postfix2 tests
       
   103 
       
   104 # var, return, ListBuffer test
       
   105 #
       
   106 echo -e "\n\npostfix2.scala does not contain vars, returns etc?" >> $out
       
   107 
       
   108 if (scala_vars postfix2.scala)
       
   109 then
       
   110   echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out 
       
   111   tsts0=$(( 0 ))
       
   112 else
       
   113   echo -e "  --> success" >> $out
       
   114   tsts0=$(( 0 )) 
       
   115 fi
       
   116 
       
   117 
       
   118 # compilation test
       
   119 
       
   120 if  [ $tsts0 -eq 0 ]
       
   121 then    
       
   122   echo -e "postfix2.scala runs?" >> $out
       
   123 
       
   124   if (scala_compile postfix2.scala)
       
   125   then
       
   126     echo -e "  --> yes" >> $out
       
   127     tsts1=$(( 0 ))
       
   128   else
       
   129     echo -e "  --> SCALA DID NOT RUN POSTFIX2.SCALA\n" >> $out
       
   130     tsts1=$(( 1 )) 
       
   131   fi
       
   132 else
       
   133   tsts1=$(( 1 ))     
       
   134 fi
       
   135 
       
   136 
       
   137 if [ $tsts1 -eq 0 ]
       
   138 then
       
   139   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
       
   140   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
       
   141   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
       
   142   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out
       
   143   echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " >> $out
       
   144   echo -e "         List(\"3\", \"4\", \"8\", \"\*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" >> $out
       
   145   echo -e " " >> $out 
       
   146   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out
       
   147   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out
       
   148   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
       
   149   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
       
   150   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
       
   151   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
       
   152   echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" >> $out
       
   153   echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" >> $out
       
   154   echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out
       
   155   echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out
       
   156   
       
   157   if (scala_assert "postfix2.scala" "postfix_test9.scala")
       
   158   then
       
   159     echo -e "  --> success" >> $out
       
   160   else
       
   161     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   162   fi
       
   163 fi
       
   164