core_testing3/postfix_test.sh
changeset 474 b528d1d3d3c3
parent 401 9471c3b7ea02
child 477 a4e1f63157d8
equal deleted inserted replaced
473:ac79c2e534bd 474:b528d1d3d3c3
     7 echo -e "" > $out
     7 echo -e "" > $out
     8 
     8 
     9 echo -e "Below is the feedback for your submission postfix.scala and postfix2.scala" >> $out
     9 echo -e "Below is the feedback for your submission postfix.scala and postfix2.scala" >> $out
    10 echo -e "" >> $out
    10 echo -e "" >> $out
    11 
    11 
       
    12 
    12 # compilation tests
    13 # compilation tests
    13 
    14 
    14 function scala_compile {
    15 function scala_compile {
    15   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    16   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$1" 2> c$out 1> c$out)
    16 }
    17 }
    17 
    18 
    18 # functional tests
    19 # functional tests
    19 
    20 
    20 function scala_assert {
    21 function scala_assert {
    21   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
    22   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null)
    22 }
    23 }
    23 
    24 
    24 # purity test
    25 # purity test
    25 
       
    26 function scala_vars {
    26 function scala_vars {
    27    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
    27    (sed 's/immutable/ok/g' c$out > cb$out;
       
    28     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
    28 }
    29 }
    29 
       
    30 
    30 
    31 
    31 
    32 # compilation test
    32 # compilation test
    33 
    33 
    34 echo -e "postfix.scala runs?" >> $out
    34 echo -e "postfix.scala runs?" >> $out
    36 if (scala_compile postfix.scala)
    36 if (scala_compile postfix.scala)
    37 then
    37 then
    38     echo -e "  --> passed" >> $out
    38     echo -e "  --> passed" >> $out
    39     tsts=$(( 0 ))
    39     tsts=$(( 0 ))
    40   else
    40   else
    41     echo -e "  --> SCALA DID NOT RUN postfix.scala\n" >> $out
    41       echo -e "  --> SCALA DID NOT RUN postfix.scala\n" >> $out
       
    42       echo -e "  --> try running scala-cli compile postfix.scala on your own computer\n" >> $out
    42     tsts=$(( 1 )) 
    43     tsts=$(( 1 )) 
    43 fi
    44 fi
    44 
    45 
    45 
    46 
    46 # var, return, ListBuffer test
    47 # var, return, ListBuffer test
    67   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
    68   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
    68   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
    69   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
    69   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
    70   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $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
    71   
    72   
    72   if (scala_assert "postfix.scala" "postfix_test7.scala")
    73   if (scala_assert "postfix.scala" "postfix_test1.scala")
    73   then
    74   then
    74     echo -e "  --> success" >> $out
    75     echo -e "  --> success" >> $out
    75   else
    76   else
    76     echo -e "  --> \n ONE TEST FAILED\n" >> $out
    77     echo -e "  --> \n ONE TEST FAILED\n" >> $out
    77   fi
    78   fi
    86   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
    87   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
    87   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
    88   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
    88   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
    89   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
    89   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
    90   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
    90   
    91   
    91   if (scala_assert "postfix.scala" "postfix_test8.scala")
    92   if (scala_assert "postfix.scala" "postfix_test2.scala")
    92   then
    93   then
    93     echo -e "  --> success" >> $out
    94     echo -e "  --> success" >> $out
    94   else
    95   else
    95     echo -e "  --> \n ONE TEST FAILED\n" >> $out
    96     echo -e "  --> \n ONE TEST FAILED\n" >> $out
    96   fi
    97   fi
   109 then
   110 then
   110     echo -e "  --> passed" >> $out
   111     echo -e "  --> passed" >> $out
   111     tsts1=$(( 0 ))
   112     tsts1=$(( 0 ))
   112 else
   113 else
   113     echo -e "  --> SCALA DID NOT RUN postfix2.scala\n" >> $out
   114     echo -e "  --> SCALA DID NOT RUN postfix2.scala\n" >> $out
       
   115     echo -e "  --> try running scala-cli compile postfix2.scala on your own computer\n" >> $out
   114     tsts1=$(( 1 )) 
   116     tsts1=$(( 1 )) 
   115 fi
   117 fi
   116 
   118 
   117 
   119 
   118 # var, return, ListBuffer test
   120 # var, return, ListBuffer test
   150   echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" >> $out
   152   echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" >> $out
   151   echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" >> $out
   153   echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" >> $out
   152   echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out
   154   echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out
   153   echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out
   155   echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out
   154   
   156   
   155   if (scala_assert "postfix2.scala" "postfix_test9.scala")
   157   if (scala_assert "postfix2.scala" "postfix_test3.scala")
   156   then
   158   then
   157     echo -e "  --> success" >> $out
   159     echo -e "  --> success" >> $out
   158   else
   160   else
   159     echo -e "  --> \n ONE TEST FAILED\n" >> $out
   161     echo -e "  --> \n ONE TEST FAILED\n" >> $out
   160   fi
   162   fi