marking2/docdiff_test.sh
changeset 283 ef5f62bf5987
parent 228 33c2655be47d
child 323 1f8005b4cdf6
equal deleted inserted replaced
282:ec9773fe1dc0 283:ef5f62bf5987
     6 
     6 
     7 out=${1:-output}
     7 out=${1:-output}
     8 
     8 
     9 echo "" > $out
     9 echo "" > $out
    10 
    10 
    11 echo "Below is the feedback and provisional marks for your submission" >> $out
    11 echo -e "Below is the feedback and provisional marks for your submission" >> $out
    12 echo "for assignment 7 Part 1 + 2.  Please note all marks are provisional until" >> $out
    12 echo -e "for the Preliminary Part of Assignemnt 7.  Please note all marks are provisional until" >> $out
    13 echo "ratified by the assessment board -- this is not an official" >> $out
    13 echo -e "ratified by the assessment board -- this is not an official" >> $out
    14 echo "results transcript." >> $out
    14 echo -e "results transcript." >> $out
    15 echo "" >> $out
    15 echo -e "" >> $out
    16 
    16 
    17 echo "Below is the feedback for your submission docdiff.scala" >> $out
    17 echo -e "Below is the feedback for your submission docdiff.scala" >> $out
    18 echo "" >> $out
    18 echo -e "" >> $out
    19 
    19 
    20 # marks for CW7 parts 1 + 2
    20 # marks for CW7 parts 1 + 2
    21 marks=$(( 0 ))
    21 marks=$(( 0 ))
    22 
    22 
    23 
    23 
    24 # compilation tests
    24 # compilation tests
    25 
    25 
    26 function scala_compile {
    26 function scala_compile {
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) 
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    28 }
    28 }
    29 
    29 
    30 # functional tests
    30 # functional tests
    31 
    31 
    32 function scala_assert {
    32 function scala_assert {
    33   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    33   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
    34 }
    34 }
    35 
    35 
    36 # purity test
    36 # purity test
    37 
    37 
    38 function scala_vars {
    38 function scala_vars {
    40 }
    40 }
    41 
    41 
    42 
    42 
    43 # var, .par return, ListBuffer test
    43 # var, .par return, ListBuffer test
    44 #
    44 #
    45 echo "docdiff.scala does not contain vars, returns etc?" |  tee -a $out
    45 echo -e "docdiff.scala does not contain vars, returns etc?" |  tee -a $out
    46 
    46 
    47 if (scala_vars docdiff.scala)
    47 if (scala_vars docdiff.scala)
    48 then
    48 then
    49   echo "  --> test failed" | tee -a $out  
    49   echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" | tee -a $out  
    50   tsts0=$(( 1 ))
    50   tsts0=$(( 1 ))
    51 else
    51 else
    52   echo "  --> success" |  tee -a $out
    52   echo -e "  --> success" |  tee -a $out
    53   tsts0=$(( 0 )) 
    53   tsts0=$(( 0 )) 
    54 fi
    54 fi
    55 
    55 
    56 ### compilation test
    56 ### compilation test
    57 
    57 
    58 
    58 
    59 if  [ $tsts0 -eq 0 ]
    59 if  [ $tsts0 -eq 0 ]
    60 then 
    60 then 
    61   echo "docdiff.scala runs?" |  tee -a $out
    61   echo -e "docdiff.scala runs?" |  tee -a $out
    62 
    62 
    63   if (scala_compile docdiff.scala)
    63   if (scala_compile docdiff.scala)
    64   then
    64   then
    65     echo "  --> success" |  tee -a $out
    65     echo -e "  --> success" |  tee -a $out
    66     tsts=$(( 0 ))
    66     tsts=$(( 0 ))
    67   else
    67   else
    68     echo "  --> scala did not run docdiff.scala" |  tee -a $out
    68     echo -e "  --> scala did not run docdiff.scala" |  tee -a $out
    69     tsts=$(( 1 )) 
    69     tsts=$(( 1 )) 
    70   fi
    70   fi
    71 else
    71 else
    72   tsts=$(( 1 ))     
    72   tsts=$(( 1 ))     
    73 fi
    73 fi
    74 
    74 
    75 ### docdiff clean tests
    75 ### docdiff clean tests
    76 
    76 
    77 if [ $tsts -eq 0 ]
    77 if [ $tsts -eq 0 ]
    78 then
    78 then
    79   echo "docdiff.scala tests:" |  tee -a $out
    79   echo -e "docdiff.scala tests:" |  tee -a $out
    80   echo "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
    80   echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
    81   echo "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
    81   echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
    82 
    82 
    83   if (scala_assert "docdiff.scala" "docdiff_test1.scala")
    83   if (scala_assert "docdiff.scala" "docdiff_test1.scala")
    84   then
    84   then
    85       echo "  --> success" |  tee -a $out
    85       echo -e "  --> success" |  tee -a $out
    86       marks=$(( marks + 1 ))
    86       marks=$(( marks + 1 ))
    87   else
    87   else
    88     echo "  --> one of the tests failed" |  tee -a $out
    88       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
    89   fi
    89   fi
    90 fi
    90 fi
    91 
    91 
    92 ### docdiff occurrences tests
    92 ### docdiff occurrences tests
    93 
    93 
    94 if [ $tsts -eq 0 ]
    94 if [ $tsts -eq 0 ]
    95 then
    95 then
    96   echo "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
    96   echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
    97   echo "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out
    97   echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out
    98   echo "  " |  tee -a $out
    98   echo -e "  " |  tee -a $out
    99   echo "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
    99   echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
   100   echo "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
   100   echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
   101 
   101 
   102   if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
   102   if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
   103   then
   103   then
   104       echo "  --> success" |  tee -a $out
   104       echo -e "  --> success" |  tee -a $out
   105       marks=$(( marks + 1 ))
   105       marks=$(( marks + 1 ))
   106   else
   106   else
   107     echo "  --> one of the tests failed" |  tee -a $out
   107     echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
   108   fi
   108   fi
   109 fi
   109 fi
   110 
   110 
   111 ### docdiff prod tests
   111 ### docdiff prod tests
   112 
   112 
   113 if [ $tsts -eq 0 ]
   113 if [ $tsts -eq 0 ]
   114 then
   114 then
   115   echo "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
   115   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
   116   echo "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
   116   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
   117   echo "  " |  tee -a $out
   117   echo -e "  " |  tee -a $out
   118   echo "  prod(l1, l2) == 7 " |  tee -a $out
   118   echo -e "  prod(l1, l2) == 7 " |  tee -a $out
   119   echo "  prod(l1, l1) == 7 " |  tee -a $out
   119   echo -e "  prod(l1, l1) == 7 " |  tee -a $out
   120   echo "  prod(l2, l2) == 13 " |  tee -a $out
   120   echo -e "  prod(l2, l2) == 13 " |  tee -a $out
   121 
   121 
   122   if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
   122   if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
   123   then
   123   then
   124       echo "  --> success" |  tee -a $out
   124       echo -e "  --> success" |  tee -a $out
   125       marks=$(( marks + 1 ))
   125       marks=$(( marks + 1 ))
   126   else
   126   else
   127     echo "  --> one of the tests failed" |  tee -a $out
   127     echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
   128   fi
   128   fi
   129 fi
   129 fi
   130 
   130 
   131 ### docdiff overlap tests
   131 ### docdiff overlap tests
   132 
   132 
   133 if [ $tsts -eq 0 ]
   133 if [ $tsts -eq 0 ]
   134 then
   134 then
   135   echo "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
   135   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
   136   echo "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
   136   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
   137   echo "  " |  tee -a $out
   137   echo -e "  " |  tee -a $out
   138   echo "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
   138   echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
   139   echo "  overlap(l1, l1) == 1.0 " |  tee -a $out
   139   echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
   140   echo "  overlap(l2, l2) == 1.0 " |  tee -a $out
   140   echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
   141 
   141 
   142   if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
   142   if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
   143   then
   143   then
   144       echo "  --> success" |  tee -a $out
   144       echo -e "  --> success" |  tee -a $out
   145       marks=$(( marks + 1 ))
   145       marks=$(( marks + 1 ))
   146   else
   146   else
   147     echo "  --> one of the tests failed" |  tee -a $out
   147       echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
   148   fi
   148   fi
   149 fi
   149 fi
   150 
   150 
   151 
   151 
   152 ## final marks
   152 ## final marks
   153 echo "Overall mark for Part 1" | tee -a $out
   153 echo -e "Overall mark for the Preliminary Part" | tee -a $out
   154 echo " $marks" | tee -a $out
   154 echo -e " $marks" | tee -a $out
   155 
   155