marking1/collatz_test.sh
changeset 158 94b11ac19b41
child 210 63a1376cbebd
equal deleted inserted replaced
157:15f1fca879c5 158:94b11ac19b41
       
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo "" > $out
       
    10 
       
    11 echo "Below is the feedback and provisional marks for your submission" >> $out
       
    12 echo "for assignment 6 Part 1 + 2.  Please note all marks are provisional until" >> $out
       
    13 echo "ratified by the assessment board -- this is not an official" >> $out
       
    14 echo "results transcript." >> $out
       
    15 echo "" >> $out
       
    16 
       
    17 echo "Below is the feedback for your submission for collatz.scala" >> $out
       
    18 echo "" >> $out
       
    19 
       
    20 # marks for CW6 parts 1 + 2
       
    21 marks=$(( 0 ))
       
    22 
       
    23 # compilation tests
       
    24 
       
    25 function scala_compile {
       
    26   (ulimit -t 30 -m 1024000 ; scala "$1" 2> /dev/null 1> /dev/null)
       
    27 }
       
    28 
       
    29 # functional tests
       
    30 
       
    31 function scala_assert {
       
    32   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    33 }
       
    34 
       
    35 # purity test
       
    36 
       
    37 function scala_vars {
       
    38    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    39 }
       
    40 
       
    41 
       
    42 # var, .par return, ListBuffer test
       
    43 #
       
    44 echo "collatz.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    45 
       
    46 if (scala_vars collatz.scala)
       
    47 then
       
    48   echo "  --> fail" | tee -a $out
       
    49   tsts0=$(( 1 ))
       
    50 else
       
    51   echo "  --> success" | tee -a $out
       
    52   tsts0=$(( 0 )) 
       
    53 fi
       
    54 
       
    55 ### compilation test
       
    56 
       
    57 
       
    58 if  [ $tsts0 -eq 0 ]
       
    59 then 
       
    60   echo "collatz.scala runs?" | tee -a $out
       
    61 
       
    62   if (scala_compile collatz.scala)
       
    63   then
       
    64     echo "  --> success" | tee -a $out
       
    65     tsts=$(( 0 ))
       
    66   else
       
    67     echo "  --> scala did not run collatz.scala" | tee -a $out
       
    68     tsts=$(( 1 )) 
       
    69   fi
       
    70 else
       
    71   tsts=$(( 1 ))     
       
    72 fi
       
    73 
       
    74 ### collatz tests
       
    75 
       
    76 if [ $tsts -eq 0 ]
       
    77 then
       
    78   echo "collatz.scala tests:" | tee -a $out
       
    79   echo "  collatz(1) == 0,1 or 4" | tee -a $out
       
    80   echo "  collatz(6) == 9" | tee -a $out
       
    81   echo "  collatz(9) == 20" | tee -a $out
       
    82   echo "  collatz(9000) == 48" | tee -a $out
       
    83 
       
    84   if (scala_assert "collatz.scala" "collatz_test1.scala")
       
    85   then
       
    86       echo "  --> success" | tee -a $out
       
    87       marks=$(( marks + 2 ))
       
    88   else
       
    89     echo "  --> one of the tests failed" | tee -a $out
       
    90   fi
       
    91 fi
       
    92 
       
    93 ### collatz-max tests
       
    94 
       
    95 if [ $tsts -eq 0 ]
       
    96 then
       
    97   echo "  collatz_max(10) == (20, 9)" | tee -a $out
       
    98   echo "  collatz_max(100) == (119, 97)" | tee -a $out
       
    99   echo "  collatz_max(1000) == (179, 871)" | tee -a $out
       
   100   echo "  collatz_max(10000) == (262, 6171)" | tee -a $out
       
   101   echo "  collatz_max(100000) == (351, 77031)" | tee -a $out
       
   102   echo "  collatz_max(1000000) == (525, 837799)" | tee -a $out
       
   103   echo "  collatz_max(2) == (2, 2)" | tee -a $out
       
   104   echo "  collatz_max(77000) == (340, 52527)" | tee -a $out
       
   105 
       
   106   if (scala_assert "collatz.scala" "collatz_test2.scala") 
       
   107   then
       
   108       echo "  --> success" | tee -a $out
       
   109       marks=$(( marks + 1 ))
       
   110   else
       
   111     echo "  --> one of the tests failed" | tee -a $out
       
   112   fi
       
   113 fi
       
   114 
       
   115 
       
   116 
       
   117 ## final marks
       
   118 echo "Overall mark for Part 1" | tee -a $out
       
   119 echo " $marks" | tee -a $out
       
   120 
       
   121