testing1/collatz_test.sh
changeset 302 067afe8af35b
parent 281 87b9e3e2c1a7
child 329 8a34b2ebc8cc
equal deleted inserted replaced
301:c3b33c709696 302:067afe8af35b
     4 set -euo pipefail
     4 set -euo pipefail
     5 
     5 
     6 
     6 
     7 out=${1:-output}
     7 out=${1:-output}
     8 
     8 
     9 echo "" > $out
     9 echo -e "" > $out
    10 
    10 
    11 echo "Below is the feedback for your submission collatz.scala" >> $out
    11 echo -e "Below is the feedback for your submission collatz.scala" >> $out
    12 echo "" >> $out
    12 echo -e "" >> $out
    13 
    13 
    14 
    14 
    15 # compilation tests
    15 # compilation tests
    16 
    16 
    17 function scala_compile {
    17 function scala_compile {
    31 }
    31 }
    32 
    32 
    33 
    33 
    34 # var, .par return, ListBuffer test
    34 # var, .par return, ListBuffer test
    35 #
    35 #
    36 echo "collatz.scala does not contain vars, returns etc?" >> $out
    36 echo -e "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 (make triple-sure your program conforms to the required format)\n" >> $out
    40   echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" >> $out
    41   tsts0=$(( 0 ))
    41   tsts0=$(( 0 ))
    42 else
    42 else
    43   echo "  --> success" >> $out
    43   echo -e "  --> success" >> $out
    44   tsts0=$(( 0 )) 
    44   tsts0=$(( 0 )) 
    45 fi
    45 fi
    46 
    46 
    47 ### compilation test
    47 ### compilation test
    48 
    48 
    49 
    49 
    50 if  [ $tsts0 -eq 0 ]
    50 if  [ $tsts0 -eq 0 ]
    51 then 
    51 then 
    52   echo "collatz.scala runs?" >> $out
    52   echo -e "collatz.scala runs?" >> $out
    53 
    53 
    54   if (scala_compile collatz.scala)
    54   if (scala_compile collatz.scala)
    55   then
    55   then
    56     echo "  --> success" >> $out
    56     echo -e "  --> success" >> $out
    57     tsts=$(( 0 ))
    57     tsts=$(( 0 ))
    58   else
    58   else
    59     echo "  --> SCALA DID NOT RUN COLLATZ.SCALA\n" >> $out
    59     echo -e "  --> SCALA DID NOT RUN COLLATZ.SCALA\n" >> $out
    60     tsts=$(( 1 )) 
    60     tsts=$(( 1 )) 
    61   fi
    61   fi
    62 else
    62 else
    63   tsts=$(( 1 ))     
    63   tsts=$(( 1 ))     
    64 fi
    64 fi
    65 
    65 
    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 -e "collatz.scala tests:" >> $out
    71   echo "  collatz(1) == 0" >> $out
    71   echo -e "  collatz(1) == 0" >> $out
    72   echo "  collatz(6) == 8" >> $out
    72   echo -e "  collatz(6) == 8" >> $out
    73   echo "  collatz(9) == 19" >> $out
    73   echo -e "  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 -e "  --> success" >> $out
    78   else
    78   else
    79     echo "  --> ONE OF THE TESTS FAILED\n" >> $out
    79     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
    80   fi
    80   fi
    81 fi
    81 fi
    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) == (19, 9)" >> $out
    87   echo -e "  collatz_max(10) == (19, 9)" >> $out
    88   echo "  collatz_max(100) == (118, 97)" >> $out
    88   echo -e "  collatz_max(100) == (118, 97)" >> $out
    89   echo "  collatz_max(1000) == (178, 871)" >> $out
    89   echo -e "  collatz_max(1000) == (178, 871)" >> $out
    90   echo "  collatz_max(10000) == (261, 6171)" >> $out
    90   echo -e "  collatz_max(10000) == (261, 6171)" >> $out
    91   echo "  collatz_max(100000) == (350, 77031)" >> $out
    91   echo -e "  collatz_max(100000) == (350, 77031)" >> $out
    92   echo "  collatz_max(1000000) == (524, 837799)" >> $out
    92   echo -e "  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 -e "  --> success" >> $out
    97   else
    97   else
    98     echo "  --> ONE OF THE TESTS FAILED\n" >> $out
    98     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
    99   fi
    99   fi
   100 fi
   100 fi
   101 
   101 
   102 
   102