core_marking1/collatz_test.sh
changeset 463 0315d9983cd0
parent 424 daf561a83ba6
equal deleted inserted replaced
462:34feeb53c0ba 463:0315d9983cd0
    23 marks=$(( 0 ))
    23 marks=$(( 0 ))
    24 
    24 
    25 # compilation tests
    25 # compilation tests
    26 
    26 
    27 function scala_compile {
    27 function scala_compile {
    28   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    28   (JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
    29 }
    29 }
    30 
    30 
    31 # functional tests
    31 # functional tests
    32 
    32 
    33 function scala_assert {
    33 function scala_assert {
    34   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
    34   (JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
    35 }
    35 }
    36  
    36  
    37 # purity test
    37 # purity test
    38 function scala_vars {
    38 function scala_vars {
    39    (sed 's/immutable/ok/g' c$out > cb$out;
    39    (sed 's/immutable/ok/g' c$out > cb$out;
    86   echo "  collatz(9) == 19"    | tee -a $out
    86   echo "  collatz(9) == 19"    | tee -a $out
    87   echo "  collatz(9000) == 47" | tee -a $out
    87   echo "  collatz(9000) == 47" | tee -a $out
    88 
    88 
    89   if (scala_assert "collatz.scala" "collatz_test1.scala")
    89   if (scala_assert "collatz.scala" "collatz_test1.scala")
    90   then
    90   then
    91       echo "  --> success" | tee -a $out
    91       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
    92       marks=$(( marks + 1 ))
    92       marks=$(( marks + 1 ))
    93   else
    93   else
    94     echo "  --> one of the tests failed" | tee -a $out
    94       echo -e "  --> one of the tests failed\n" | tee -a $out
    95   fi
    95   fi
    96 fi
    96 fi
    97 
    97 
    98 ### collatz-max tests
    98 ### collatz-max tests
    99 
    99 
   109   echo "  collatz_max(2) == (1, 2)" | tee -a $out
   109   echo "  collatz_max(2) == (1, 2)" | tee -a $out
   110   echo "  collatz_max(77000) == (339, 52527)" | tee -a $out
   110   echo "  collatz_max(77000) == (339, 52527)" | tee -a $out
   111 
   111 
   112   if (scala_assert "collatz.scala" "collatz_test2.scala") 
   112   if (scala_assert "collatz.scala" "collatz_test2.scala") 
   113   then
   113   then
   114       echo "  --> success" | tee -a $out
   114       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
   115       marks=$(( marks + 1 ))
   115       marks=$(( marks + 1 ))
   116   else
   116   else
   117     echo "  --> one of the tests failed" | tee -a $out
   117       echo -e "  --> one of the tests failed\n" | tee -a $out
   118   fi
   118   fi
   119 fi
   119 fi
   120 
   120 
   121 ### last-odd tests
   121 ### last-odd tests
   122 
   122 
   123 if [ $tsts -eq 0 ]
   123 if [ $tsts -eq 0 ]
   124 then
   124 then
   125   echo "  last_odd(113) == 85" | tee -a $out
   125   echo "  last_odd(113) == 85" | tee -a $out
   126   echo "  last_odd(84) == 21" | tee -a $out
   126   echo "  last_odd(84) == 21" | tee -a $out
   127   echo "  last_odd(605) == 341" | tee -a $out
   127   echo "  last_odd(605) == 341" | tee -a $out
   128 
   128   START=$(date +%s)
       
   129   
   129   if (scala_assert "collatz.scala" "collatz_test3.scala") 
   130   if (scala_assert "collatz.scala" "collatz_test3.scala") 
   130   then
   131   then
   131       echo "  --> success" | tee -a $out
   132       END=$(date +%s)
       
   133       DIFF=$(( $END - $START ))
       
   134       echo -e "  --> success (+ 1 Mark)\n" | tee -a $out
   132       marks=$(( marks + 1 ))
   135       marks=$(( marks + 1 ))
   133   else
   136   else
   134     echo "  --> one of the tests failed" | tee -a $out
   137       END=$(date +%s)
       
   138       DIFF=$(( $END - $START ))
       
   139       echo -e "  This test ran for $DIFF seconds" | tee -a $out  
       
   140       echo -e "  --> one of the tests failed\n" | tee -a $out
   135   fi
   141   fi
   136 fi
   142 fi
   137 
   143 
   138 
   144 
   139 
   145