marking/mark02
changeset 281 87b9e3e2c1a7
parent 280 a057dc4457fc
child 282 ec9773fe1dc0
equal deleted inserted replaced
280:a057dc4457fc 281:87b9e3e2c1a7
     1 #!/bin/bash
       
     2 set -e
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo "" > $out
       
     7 
       
     8 echo "Below is the feedback and provisional mark for your submission" >> $out
       
     9 echo "for CW 7, Part 1.  Please note all marks are provisional until" >> $out
       
    10 echo "ratified by the assessment board -- this is not an official" >> $out
       
    11 echo "results transcript." >> $out
       
    12 echo "" >> $out
       
    13 
       
    14 function scala_vars {
       
    15    (egrep 'var|return|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
       
    16 }
       
    17 
       
    18 
       
    19 # compilation tests
       
    20 
       
    21 function scala_compile {
       
    22   (scala "$1" 2> /dev/null 1> /dev/null) 
       
    23 }
       
    24 
       
    25 
       
    26 # functional tests
       
    27 
       
    28 function scala_assert {
       
    29   (scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    30 }
       
    31 
       
    32 
       
    33 # marks for CW2
       
    34 marks=$(( 0 ))
       
    35 
       
    36 # knights1: var, comments test
       
    37 
       
    38 echo "knight1.scala does not contain vars, returns etc?" | tee -a $out
       
    39 
       
    40 if (scala_vars knight1.scala)
       
    41 then
       
    42   echo "  --> fail" | tee -a $out
       
    43   tsts0=$(( 1 ))
       
    44 else
       
    45   echo "  --> yes" | tee -a $out
       
    46   tsts0=$(( 0 )) 
       
    47 fi
       
    48 
       
    49 
       
    50 # compilation test
       
    51 
       
    52 if [ $tsts0 -eq 0 ]
       
    53 then    
       
    54   echo "knight1.scala runs?" | tee -a $out
       
    55 
       
    56   if (scala_compile knight1.scala.bak)
       
    57   then
       
    58     echo "  --> yes" | tee -a $out
       
    59     tsts1=$(( 0 ))
       
    60   else
       
    61     echo "  --> scala did not run knight1.scala" | tee -a $out
       
    62     tsts1=$(( 1 )) 
       
    63   fi
       
    64 else
       
    65   tsts1=$(( 1 ))   
       
    66 fi
       
    67 
       
    68 ### knight1a test
       
    69 
       
    70 if [ $tsts1 -eq 0 ]
       
    71 then
       
    72     echo " is_legal(8, Nil) (3,4) == true " | tee -a $out
       
    73     echo " is_legal(8, (4,1) (1,0)) (4,1) == false " | tee -a $out
       
    74     echo " is_legal(2, Nil) (0,0) == true" | tee -a $out                          
       
    75 
       
    76     if (scala_assert "knight1.scala.bak" "../../../marking/knight1c_test.scala")
       
    77     then
       
    78         echo "  --> success" | tee -a $out
       
    79         marks=$(( marks + 1 ))
       
    80     else
       
    81         echo "  --> test failed" | tee -a $out
       
    82     fi
       
    83 fi
       
    84 
       
    85 if [ $tsts1 -eq 0 ]
       
    86 then
       
    87   echo " legal_moves(8, Nil, (2,2)) = (3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)" | tee -a $out
       
    88   echo " legal_moves(8, Nil, (7,7)) = (6,5), (5,6)" | tee -a $out
       
    89   echo " legal_moves(8, (4,1), (1,0), (2,2)) = (3,4), (4,3), (3,0), (0,1), (0,3), (1,4)" | tee -a $out
       
    90   echo " legal_moves(8, (6,6), (7,7)) = (6,5), (5,6)" | tee -a $out
       
    91   echo " legal_moves(1, Nil, (0,0)) = Nil" | tee -a $out
       
    92   echo " legal_moves(2, Nil, (0,0)) = Nil" | tee -a $out
       
    93   echo " legal_moves(3, Nil, (0,0)) = (1,2), (2,1)" | tee -a $out
       
    94   
       
    95   if (scala_assert "knight1.scala.bak" "../../../marking/knight1_test.scala")
       
    96   then
       
    97     echo "  --> success" | tee -a $out
       
    98     marks=$(( marks + 1 ))
       
    99   else
       
   100     echo "  --> test failed" | tee -a $out
       
   101   fi
       
   102 fi
       
   103 
       
   104 ### knight1b test
       
   105 
       
   106 if [ $tsts1 -eq 0 ]
       
   107 then
       
   108   echo " all_tours from every position on the board" | tee -a $out
       
   109   echo " dim = 1: 1" | tee -a $out
       
   110   echo "       2: 0,0,0,0" | tee -a $out
       
   111   echo "       3: 0,0,0,0,0,0,0,0,0" | tee -a $out
       
   112   echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
       
   113   echo "       5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56,0,56,0,56,0,304,0,56,0,304" | tee -a $out
       
   114   echo " enum_tours(5, (0,2) ) = 56 and all correct?" | tee -a $out
       
   115   
       
   116   if (scala_assert "knight1.scala.bak" "../../../marking/knight1b_test.scala") 
       
   117   then
       
   118     echo "  --> success" | tee -a $out
       
   119     marks=$(( marks + 2 ))
       
   120   else
       
   121     echo "  --> test failed" | tee -a $out
       
   122   fi
       
   123 fi
       
   124 
       
   125 
       
   126 
       
   127 # knights2: var, comments test
       
   128 
       
   129 echo "knight2.scala does not contain vars, returns etc?" | tee -a $out
       
   130 
       
   131 if (scala_vars knight2.scala)
       
   132 then
       
   133   echo "  --> fail" | tee -a $out
       
   134   tsts0=$(( 1 ))
       
   135 else
       
   136   echo "  --> yes" | tee -a $out
       
   137   tsts0=$(( 0 )) 
       
   138 fi
       
   139 
       
   140 
       
   141 # compilation test
       
   142 if  [ $tsts0 -eq 0 ]
       
   143 then    
       
   144   echo "knight2.scala runs?" | tee -a $out
       
   145 
       
   146   if (scala_compile knight2.scala.bak)
       
   147   then
       
   148     echo "  --> yes" | tee -a $out
       
   149     tsts1=$(( 0 ))
       
   150   else
       
   151     echo "  --> scala did not run knight2.scala" | tee -a $out
       
   152     tsts1=$(( 1 )) 
       
   153   fi
       
   154 else
       
   155   tsts1=$(( 1 ))     
       
   156 fi
       
   157 
       
   158 ### knight2 test
       
   159 
       
   160 if [ $tsts1 -eq 0 ]
       
   161 then
       
   162   echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out
       
   163   echo "  first((1,0),(2,0),(3,0),(4,0), f) == Some(List((4,0)))" | tee -a $out
       
   164   echo "  first((1,0),(2,0),(3,0), f) == None" | tee -a $out
       
   165 
       
   166   if (scala_assert "knight2.scala.bak" "../../../marking/knight2_test.scala") 
       
   167   then
       
   168     echo "  --> success" | tee -a $out
       
   169     marks=$(( marks + 1 ))
       
   170   else
       
   171     echo "  --> test failed" | tee -a $out
       
   172   fi
       
   173 fi
       
   174 
       
   175 ### knight2b test
       
   176 
       
   177 if [ $tsts1 -eq 0 ]
       
   178 then
       
   179   echo " is first_tour(8,  (0, 0)) ok? " | tee -a $out
       
   180   echo " is first_tour(4,  (0, 0)) == None " | tee -a $out
       
   181 
       
   182   if (scala_assert "knight2.scala.bak" "../../../marking/knight2b_test.scala") 
       
   183   then
       
   184     echo "  --> success" | tee -a $out
       
   185     marks=$(( marks + 2 ))
       
   186   else
       
   187     echo "  --> test failed" | tee -a $out
       
   188   fi
       
   189 fi
       
   190 
       
   191 
       
   192 # knights3: var, comments test
       
   193 #
       
   194 #echo "knight3.scala does not contain vars, returns etc?" | tee -a $out
       
   195 
       
   196 #if (scala_vars knight3.scala)
       
   197 #then
       
   198 #  echo "  --> fail" | tee -a $out
       
   199 #  tsts0=$(( 1 ))
       
   200 #else
       
   201 #  echo "  --> success" | tee -a $out
       
   202 #  tsts0=$(( 0 )) 
       
   203 #fi
       
   204 
       
   205 
       
   206 # compilation test
       
   207 #if  [ $tsts0 -eq 0 ]
       
   208 #then    
       
   209 #  echo "knight3.scala runs?" | tee -a $out
       
   210 #
       
   211 #  if (scala_compile knight3.scala.bak)
       
   212 #  then
       
   213 #    echo "  --> success" | tee -a $out
       
   214 #    tsts1=$(( 0 ))
       
   215 #  else
       
   216 #    echo "  --> scala did not run knight3.scala" | tee -a $out
       
   217 #    tsts1=$(( 1 )) 
       
   218 #  fi
       
   219 #else
       
   220 #  tsts1=$(( 1 ))     
       
   221 #fi
       
   222 
       
   223 
       
   224 ## final marks
       
   225 echo "Overall mark for CW 2, Part 1 " | tee -a $out
       
   226 echo "$marks" | tee -a $out