core_marking2/docdiff_test.sh
changeset 424 daf561a83ba6
parent 382 1bd800376e0c
child 463 0315d9983cd0
equal deleted inserted replaced
423:e9d14d58be3c 424:daf561a83ba6
       
     1 #!/bin/zsh
       
     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 -e "Below is the feedback and provisional marks for your submission" >> $out
       
    13 echo -e "for the Core Part 2 (Scala).  Please note all marks are provisional until" >> $out
       
    14 echo -e "ratified by the assessment board -- this is not an official" >> $out
       
    15 echo -e "results transcript." >> $out
       
    16 echo -e "" >> $out
       
    17 
       
    18 echo -e "Below is the feedback for your submission docdiff.scala" >> $out
       
    19 echo -e "" >> $out
       
    20 
       
    21 # marks for C2 core part
       
    22 marks=$(( 0.0 ))
       
    23 
       
    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 function scala_vars {
       
    39    (sed 's/immutable/ok/g' c$out > cb$out;
       
    40     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
       
    41 }
       
    42 
       
    43 
       
    44 
       
    45 ### compilation test
       
    46 
       
    47 echo -e "docdiff.scala runs?" |  tee -a $out
       
    48 
       
    49 if (scala_compile docdiff.scala)
       
    50 then
       
    51     echo -e "  --> success" |  tee -a $out
       
    52     tsts=$(( 0 ))
       
    53 else
       
    54     echo -e "  --> SCALA DID NOT RUN docdiff.scala\n" |  tee -a $out
       
    55     tsts=$(( 1 )) 
       
    56 fi
       
    57 
       
    58 
       
    59 # var, .par return, ListBuffer test
       
    60 #
       
    61 
       
    62 if  [ $tsts -eq 0 ]
       
    63 then     
       
    64    echo -e "docdiff.scala does not contain VARS, RETURNS etc?" |  tee -a $out
       
    65 
       
    66    if (scala_vars docdiff.scala)
       
    67    then
       
    68       echo -e "  --> test failed\n" | tee -a $out  
       
    69       tsts=$(( 1 ))
       
    70    else
       
    71       echo -e "  --> success" |  tee -a $out
       
    72       tsts=$(( 0 )) 
       
    73    fi
       
    74 else
       
    75    tsts=$(( 1 ))  
       
    76 fi 
       
    77 
       
    78 echo >> $out
       
    79 
       
    80 
       
    81 ### docdiff clean tests
       
    82 
       
    83 if [ $tsts -eq 0 ]
       
    84 then
       
    85   echo -e "docdiff.scala tests:" |  tee -a $out
       
    86   echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
       
    87   echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
       
    88 
       
    89   if (scala_assert "docdiff.scala" "docdiff_test1.scala")
       
    90   then
       
    91       echo -e "  --> success" |  tee -a $out
       
    92       marks=$(( marks + 0.5 ))
       
    93   else
       
    94       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
       
    95   fi
       
    96 fi
       
    97 
       
    98 ### docdiff occurrences tests
       
    99 
       
   100 if [ $tsts -eq 0 ]
       
   101 then
       
   102   echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
       
   103   echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)"  |  tee -a $out
       
   104   echo -e "  " |  tee -a $out
       
   105   echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
       
   106   echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
       
   107   echo -e "  " |  tee -a $out
       
   108   echo -e "  occurrences(Nil) == Map() " |  tee -a $out
       
   109   echo -e "  " |  tee -a $out
       
   110   echo -e "  occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" |  tee -a $out
       
   111 
       
   112   if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
       
   113   then
       
   114       echo -e "  --> success" |  tee -a $out
       
   115       marks=$(( marks + 1.0 ))
       
   116   else
       
   117       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
       
   118   fi
       
   119 fi
       
   120 
       
   121 ### docdiff prod tests
       
   122 
       
   123 if [ $tsts -eq 0 ]
       
   124 then
       
   125   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
       
   126   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
       
   127   echo -e "  " |  tee -a $out
       
   128   echo -e "  prod(l1, l2) == 7 " |  tee -a $out
       
   129   echo -e "  prod(l1, l1) == 7 " |  tee -a $out
       
   130   echo -e "  prod(l2, l2) == 13 " |  tee -a $out
       
   131   echo -e "  " |  tee -a $out
       
   132   echo -e "  val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" |  tee -a $out
       
   133   echo -e "  prod(l1, l3) == 0 " |  tee -a $out
       
   134 
       
   135   if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
       
   136   then
       
   137       echo -e "  --> success" |  tee -a $out
       
   138       marks=$(( marks + 1.0 ))
       
   139   else
       
   140       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
       
   141   fi
       
   142 fi
       
   143 
       
   144 ### docdiff overlap tests
       
   145 
       
   146 if [ $tsts -eq 0 ]
       
   147 then
       
   148   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
       
   149   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
       
   150   echo -e "  " |  tee -a $out
       
   151   echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
       
   152   echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
       
   153   echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
       
   154 
       
   155   if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
       
   156   then
       
   157       echo -e "  --> success" |  tee -a $out
       
   158       marks=$(( marks + 0.5 ))
       
   159   else
       
   160       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
       
   161   fi
       
   162 fi
       
   163 
       
   164 
       
   165 ## final marks
       
   166 echo -e "Overall mark for the Core Part 2 (Scala)" | tee -a $out
       
   167 printf " %0.1f\n" $marks | tee -a $out
       
   168 
       
   169 
       
   170 #echo -e " $marks" | tee -a $out
       
   171