pre_marking1/collatz_test.sh
changeset 373 d29cd5883c7b
child 375 ddda2e76a40f
equal deleted inserted replaced
372:e87462c9b895 373:d29cd5883c7b
       
     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 `date` >> $out
       
    12 echo >> $out
       
    13 echo "Below is the feedback and provisional marks for your submission" >> $out
       
    14 echo "for the Preliminary Part of Part 1 (Scala).  Please note all marks are provisional until" >> $out
       
    15 echo "ratified by the assessment board -- this is not an official" >> $out
       
    16 echo "results transcript." >> $out
       
    17 echo "" >> $out
       
    18 
       
    19 echo "The feedback for your submission for collatz.scala" >> $out
       
    20 echo "" >> $out
       
    21 
       
    22 # marks for CW6 basic part 
       
    23 marks=$(( 0 ))
       
    24 
       
    25 # compilation tests
       
    26 
       
    27 function scala_compile {
       
    28   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    29 }
       
    30 
       
    31 # functional tests
       
    32 
       
    33 function scala_assert {
       
    34   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    35 }
       
    36 
       
    37 # purity test
       
    38 
       
    39 function scala_vars {
       
    40    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    41 }
       
    42 
       
    43 
       
    44 ### compilation test
       
    45 
       
    46 echo -e "collatz.scala runs?" >> $out
       
    47 
       
    48 if (scala_compile collatz.scala)
       
    49 then
       
    50     echo -e "  --> success" >> $out
       
    51     tsts0=$(( 0 ))
       
    52 else
       
    53     echo -e "  --> SCALA DID NOT RUN collatz.scala\n" >> $out
       
    54     tsts0=$(( 1 )) 
       
    55 fi
       
    56 
       
    57 # var, .par return, ListBuffer test
       
    58 #
       
    59 
       
    60 if  [ $tsts0 -eq 0 ]
       
    61 then
       
    62    echo -e "collatz.scala does not contain VARS, RETURNS etc?" >> $out
       
    63     
       
    64    if (scala_vars collatz.scala)
       
    65    then
       
    66       echo -e "  --> test failed\n" >> $out
       
    67       tsts=$(( 1 ))
       
    68    else
       
    69       echo -e "  --> success" >> $out
       
    70       tsts=$(( 0 )) 
       
    71    fi
       
    72 fi    
       
    73 
       
    74 
       
    75 echo >> $out
       
    76 
       
    77 ### collatz tests
       
    78 
       
    79 if [ $tsts -eq 0 ]
       
    80 then
       
    81   echo "collatz.scala tests:" | tee -a $out
       
    82   echo "  collatz(1) == 0" | tee -a $out
       
    83   echo "  collatz(6) == 8" | tee -a $out
       
    84   echo "  collatz(9) == 19" | tee -a $out
       
    85   echo "  collatz(9000) == 47" | tee -a $out
       
    86 
       
    87   if (scala_assert "collatz.scala" "collatz_test1.scala")
       
    88   then
       
    89       echo "  --> success" | tee -a $out
       
    90       marks=$(( marks + 1 ))
       
    91   else
       
    92     echo "  --> one of the tests failed" | tee -a $out
       
    93   fi
       
    94 fi
       
    95 
       
    96 ### collatz-max tests
       
    97 
       
    98 if [ $tsts -eq 0 ]
       
    99 then
       
   100   echo "  collatz_max(10) == (19, 9)" | tee -a $out
       
   101   echo "  collatz_max(100) == (118, 97)" | tee -a $out
       
   102   echo "  collatz_max(1000) == (178, 871)" | tee -a $out
       
   103   echo "  collatz_max(10000) == (261, 6171)" | tee -a $out
       
   104   echo "  collatz_max(100000) == (350, 77031)" | tee -a $out
       
   105   echo "  collatz_max(1000000) == (524, 837799)" | tee -a $out
       
   106   #  echo "  collatz_max(2) == (1, 2) || collatz_max(2) == (0, 1)" | tee -a $out
       
   107   echo "  collatz_max(2) == (1, 2)" | tee -a $out
       
   108   echo "  collatz_max(77000) == (339, 52527)" | tee -a $out
       
   109 
       
   110   if (scala_assert "collatz.scala" "collatz_test2.scala") 
       
   111   then
       
   112       echo "  --> success" | tee -a $out
       
   113       marks=$(( marks + 1 ))
       
   114   else
       
   115     echo "  --> one of the tests failed" | tee -a $out
       
   116   fi
       
   117 fi
       
   118 
       
   119 ### last-odd tests
       
   120 
       
   121 if [ $tsts -eq 0 ]
       
   122 then
       
   123   echo "  last_odd(113) == 85" | tee -a $out
       
   124   echo "  last_odd(84) == 21" | tee -a $out
       
   125   echo "  last_odd(605) == 341" | tee -a $out
       
   126 
       
   127   if (scala_assert "collatz.scala" "collatz_test3.scala") 
       
   128   then
       
   129       echo "  --> success" | tee -a $out
       
   130       marks=$(( marks + 1 ))
       
   131   else
       
   132     echo "  --> one of the tests failed" | tee -a $out
       
   133   fi
       
   134 fi
       
   135 
       
   136 
       
   137 
       
   138 ## final marks
       
   139 echo >> $out
       
   140 echo "Overall mark for the Preliminary Part 1 (Scala)" | tee -a $out
       
   141 echo " $marks" | tee -a $out
       
   142 
       
   143