testing1/collatz_test.sh
changeset 199 54befaf23648
parent 144 716042628398
child 206 bbe00108a6f3
equal deleted inserted replaced
198:d59c7995bcb2 199:54befaf23648
    13 
    13 
    14 
    14 
    15 # compilation tests
    15 # compilation tests
    16 
    16 
    17 function scala_compile {
    17 function scala_compile {
    18   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
    18   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    19 }
    19 }
    20 
    20 
    21 # functional tests
    21 # functional tests
    22 
    22 
    23 function scala_assert {
    23 function scala_assert {
    24   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    24   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    25 }
    25 }
    26 
    26 
    27 # purity test
    27 # purity test
    28 
    28 
    29 function scala_vars {
    29 function scala_vars {
    35 #
    35 #
    36 echo "collatz.scala does not contain vars, returns etc?" >> $out
    36 echo "collatz.scala does not contain vars, returns etc?" >> $out
    37 
    37 
    38 if (scala_vars collatz.scala)
    38 if (scala_vars collatz.scala)
    39 then
    39 then
    40   echo "  --> fail" >> $out
    40   echo "  --> fail (make tripply-sure your program conforms to the required format)" >> $out
    41   tsts0=$(( 1 ))
    41   tsts0=$(( 0 ))
    42 else
    42 else
    43   echo "  --> success" >> $out
    43   echo "  --> success" >> $out
    44   tsts0=$(( 0 )) 
    44   tsts0=$(( 0 )) 
    45 fi
    45 fi
    46 
    46 
    66 ### collatz tests
    66 ### collatz tests
    67 
    67 
    68 if [ $tsts -eq 0 ]
    68 if [ $tsts -eq 0 ]
    69 then
    69 then
    70   echo "collatz.scala tests:" >> $out
    70   echo "collatz.scala tests:" >> $out
    71   echo "  collatz(1) == 0,1 or 4" >> $out
    71   echo "  collatz(1) == 0" >> $out
    72   echo "  collatz(6) == 9" >> $out
    72   echo "  collatz(6) == 8" >> $out
    73   echo "  collatz(9) == 20" >> $out
    73   echo "  collatz(9) == 19" >> $out
    74 
    74 
    75   if (scala_assert "collatz.scala" "collatz_test1.scala")
    75   if (scala_assert "collatz.scala" "collatz_test1.scala")
    76   then
    76   then
    77     echo "  --> success" >> $out
    77     echo "  --> success" >> $out
    78   else
    78   else
    82 
    82 
    83 ### collatz-max tests
    83 ### collatz-max tests
    84 
    84 
    85 if [ $tsts -eq 0 ]
    85 if [ $tsts -eq 0 ]
    86 then
    86 then
    87   echo "  collatz_max(10) == (20, 9)" >> $out
    87   echo "  collatz_max(10) == (19, 9)" >> $out
    88   echo "  collatz_max(100) == (119, 97)" >> $out
    88   echo "  collatz_max(100) == (118, 97)" >> $out
    89   echo "  collatz_max(1000) == (179, 871)" >> $out
    89   echo "  collatz_max(1000) == (178, 871)" >> $out
    90   echo "  collatz_max(10000) == (262, 6171)" >> $out
    90   echo "  collatz_max(10000) == (261, 6171)" >> $out
    91   echo "  collatz_max(100000) == (351, 77031)" >> $out
    91   echo "  collatz_max(100000) == (350, 77031)" >> $out
    92   echo "  collatz_max(1000000) == (525, 837799)" >> $out
    92   echo "  collatz_max(1000000) == (524, 837799)" >> $out
    93 
    93 
    94   if (scala_assert "collatz.scala" "collatz_test2.scala") 
    94   if (scala_assert "collatz.scala" "collatz_test2.scala") 
    95   then
    95   then
    96     echo "  --> success" >> $out
    96     echo "  --> success" >> $out
    97   else
    97   else