testing3/knight_test.sh
changeset 296 12dc251fc47e
parent 295 3f34da7a3094
child 329 8a34b2ebc8cc
equal deleted inserted replaced
295:3f34da7a3094 296:12dc251fc47e
     5 
     5 
     6 echo -e "" > $out
     6 echo -e "" > $out
     7 
     7 
     8 echo -e "Below is the feedback for your submission of CW 8" >> $out
     8 echo -e "Below is the feedback for your submission of CW 8" >> $out
     9 echo -e "" >> $out
     9 echo -e "" >> $out
    10 
    10 echo -e "!! Important: !!" >> $out
       
    11 echo -e "Because of limitations with our testing infrastructure, we can only" >> $out
       
    12 echo -e "let code run for 10 seconds and then have to kill it. This might" >> $out
       
    13 echo -e "mean your code is correct, but still marked as Fail. Remember" >> $out
       
    14 echo -e "you can test your code on your own machine and benchmark it" >> $out
       
    15 echo -e "against the reference implementation." >> $out
       
    16 echo -e "" >> $out
    11 
    17 
    12 # compilation tests
    18 # compilation tests
    13 
    19 
    14 function scala_compile {
    20 function scala_compile {
    15   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    21   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    24 function scala_assert_thirty {
    30 function scala_assert_thirty {
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
    31   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
    26 }
    32 }
    27 
    33 
    28 function scala_assert_quick {
    34 function scala_assert_quick {
    29   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2"  2> /dev/null 1> /dev/null)
    35   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
    30 }
    36 }
    31 
    37 
    32 # purity test
    38 # purity test
    33 
    39 
    34 function scala_vars {
    40 function scala_vars {
   132 
   138 
   133 ### knight4 test
   139 ### knight4 test
   134 
   140 
   135 if [ $tsts1 -eq 0 ]
   141 if [ $tsts1 -eq 0 ]
   136 then
   142 then
   137   echo -e "Takes 10 seconds or less to execute: " >> $out
   143   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
   138   echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
   144   echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
   139   echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
   145   echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
   140   echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
   146   echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
   141 
   147 
   142   if (scala_assert_quick "knight1.scala" "knight_test4.scala") 
   148   if (scala_assert_quick "knight1.scala" "knight_test4.scala") 
   150 
   156 
   151 ### knight5 test
   157 ### knight5 test
   152 
   158 
   153 if [ $tsts1 -eq 0 ]
   159 if [ $tsts1 -eq 0 ]
   154 then
   160 then
   155   echo -e "Takes 10 seconds or less to execute: " >> $out
   161   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
   156   echo -e " is first_tour(6, List((0, 0))) ok? " >> $out
   162   echo -e " is first_tour(6, List((0, 0))) ok? " >> $out
   157   echo -e " is first_tour(4, List((0, 0))) == None " >> $out
   163   echo -e " is first_tour(4, List((0, 0))) == None " >> $out
   158 
   164 
   159   if (scala_assert_quick "knight1.scala" "knight_test5.scala") 
   165   if (scala_assert_quick "knight1.scala" "knight_test5.scala") 
   160   then
   166   then
   162   else
   168   else
   163     echo -e "  --> \n ONE TEST FAILED\n" >> $out
   169     echo -e "  --> \n ONE TEST FAILED\n" >> $out
   164   fi
   170   fi
   165 fi
   171 fi
   166 
   172 
       
   173 
       
   174 echo -e "" >> $out
       
   175 echo -e "" >> $out
       
   176 
       
   177 
       
   178 # knights2: purity test
       
   179 #
       
   180 echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
       
   181 
       
   182 if (scala_vars knight2.scala)
       
   183 then
       
   184   echo -e "  --> Fail (make triple-sure your program conforms to the required format)" >> $out    
       
   185   tsts0=$(( 0 ))
       
   186 else
       
   187   echo -e "  --> success" >> $out
       
   188   tsts0=$(( 0 )) 
       
   189 fi
       
   190 
       
   191 
       
   192 # compilation test
       
   193 if  [ $tsts0 -eq 0 ]
       
   194 then    
       
   195   echo -e "knight2.scala runs?" >> $out
       
   196 
       
   197   if (scala_compile knight2.scala)
       
   198   then
       
   199     echo -e "  --> success" >> $out
       
   200     tsts1=$(( 0 ))
       
   201   else
       
   202     echo -e "  --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out  
       
   203     tsts1=$(( 1 )) 
       
   204   fi
       
   205 else
       
   206   tsts1=$(( 1 ))     
       
   207 fi
       
   208 
       
   209 
       
   210 # ordered move test
       
   211 
       
   212 if [ $tsts1 -eq 0 ]
       
   213 then
       
   214   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out  
       
   215   echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
       
   216   echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
       
   217   echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
       
   218   
       
   219   if (scala_assert_quick "knight2.scala" "knight_test6.scala")
       
   220   then
       
   221       echo -e "  --> success" >> $out
       
   222   else
       
   223       echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
   224   fi
       
   225 fi
       
   226 
       
   227 
       
   228 # first-closed-tour test
       
   229 
       
   230 if [ $tsts1 -eq 0 ]
       
   231 then
       
   232   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out  
       
   233   echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" >> $out
       
   234   
       
   235   if (scala_assert_quick "knight2.scala" "knight_test7.scala")
       
   236   then
       
   237       echo -e "  --> success" >> $out
       
   238   else
       
   239       echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
   240   fi
       
   241 fi
       
   242 
       
   243 
       
   244 
       
   245 if [ $tsts1 -eq 0 ]
       
   246 then
       
   247   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out   
       
   248   echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" >> $out
       
   249   echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" >> $out
       
   250   
       
   251   if (scala_assert_quick "knight2.scala" "knight_test8.scala")
       
   252   then
       
   253       echo -e "  --> success" >> $out
       
   254   else
       
   255       echo -e "  --> \n ONE TEST FAILED\n" >> $out 
       
   256   fi
       
   257 fi
       
   258 
       
   259 
       
   260 echo -e "" >> $out
       
   261 echo -e "" >> $out
       
   262 
       
   263 # knights3: purity test
       
   264 #
       
   265 echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
       
   266 
       
   267 
       
   268 if (scala_vars knight3.scala)
       
   269 then
       
   270   echo "  --> Fail (make triple-sure your program conforms to the required format)xsxs" >> $out
       
   271   tsts0=$(( 0 ))
       
   272 else
       
   273   echo "  --> success" >> $out
       
   274   tsts0=$(( 0 )) 
       
   275 fi
       
   276 
       
   277 
       
   278 # compilation test
       
   279 if  [ $tsts0 -eq 0 ]
       
   280 then    
       
   281   echo "knight3.scala runs?" >> $out
       
   282 
       
   283   if (scala_compile knight3.scala)
       
   284   then
       
   285     echo "  --> success" >> $out
       
   286     tsts1=$(( 0 ))
       
   287   else
       
   288     echo -e "  --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out  
       
   289     tsts1=$(( 1 )) 
       
   290   fi
       
   291 else
       
   292   tsts1=$(( 1 ))     
       
   293 fi
       
   294 
       
   295 
       
   296 if [ $tsts1 -eq 0 ]
       
   297 then
       
   298   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out  
       
   299   echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" >> $out
       
   300   
       
   301   if (scala_assert_quick "knight3.scala" "knight_test9.scala")
       
   302   then
       
   303       echo -e "  --> success" >> $out
       
   304   else
       
   305       echo -e "  --> \n ONE TEST FAILED\n" >> $out 
       
   306   fi
       
   307 fi
       
   308