testing3/knight_test.sh
changeset 347 4de31fdc0d67
parent 346 663c2a9108d1
child 348 b5b6ed38c2f2
equal deleted inserted replaced
346:663c2a9108d1 347:4de31fdc0d67
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo -e "" > $out
       
     7 
       
     8 echo -e "Below is the feedback for your submission of CW 8" >> $out
       
     9 echo -e "" >> $out
       
    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
       
    17 
       
    18 # compilation tests
       
    19 
       
    20 function scala_compile {
       
    21   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
       
    22 }
       
    23 
       
    24 # functional tests
       
    25 
       
    26 function scala_assert_slow {
       
    27   (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "-- $2" 2> /dev/null 1> /dev/null)
       
    28 }
       
    29 
       
    30 function scala_assert_thirty {
       
    31   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    32 }
       
    33 
       
    34 function scala_assert_quick {
       
    35   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    36 }
       
    37 
       
    38 # purity test
       
    39 
       
    40 function scala_vars {
       
    41    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    42 }
       
    43 
       
    44 
       
    45 # knights1: purity test
       
    46 
       
    47 echo -e "knight1.scala does not contain vars, returns etc?" >> $out
       
    48 
       
    49 if (scala_vars knight1.scala)
       
    50 then
       
    51   echo -e "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
       
    52   tsts0=$(( 0 ))
       
    53 else
       
    54   echo -e "  --> success" >> $out
       
    55   tsts0=$(( 0 )) 
       
    56 fi
       
    57 
       
    58 
       
    59 # compilation test
       
    60 
       
    61 if [ $tsts0 -eq 0 ]
       
    62 then    
       
    63   echo -e "knight1.scala runs?" >> $out
       
    64 
       
    65   if (scala_compile knight1.scala)
       
    66   then
       
    67     echo -e "  --> success " >> $out
       
    68     tsts1=$(( 0 ))
       
    69   else
       
    70     echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" >> $out
       
    71     tsts1=$(( 1 )) 
       
    72   fi
       
    73 else
       
    74   tsts1=$(( 1 ))   
       
    75 fi
       
    76 
       
    77 ### knight1 test
       
    78 
       
    79 if [ $tsts1 -eq 0 ]
       
    80 then
       
    81     echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
    82     echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out
       
    83     echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out
       
    84     echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out                          
       
    85 
       
    86     if (scala_assert_quick "knight1.scala" "knight_test1.scala")
       
    87     then
       
    88         echo -e "  --> success" >> $out
       
    89     else
       
    90         echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    91     fi
       
    92 fi
       
    93 
       
    94 ### knight2 test
       
    95 
       
    96 if [ $tsts1 -eq 0 ]
       
    97 then
       
    98   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
    99   echo -e " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
       
   100   echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
       
   101   echo -e " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
       
   102   echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
       
   103   echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out
       
   104   echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out
       
   105   echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
       
   106   
       
   107   if (scala_assert_quick "knight1.scala" "knight_test2.scala")
       
   108   then
       
   109     echo -e "  --> success" >> $out
       
   110   else
       
   111     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   112   fi
       
   113 fi
       
   114 
       
   115 
       
   116 ### knight3 test
       
   117 
       
   118 if [ $tsts1 -eq 0 ]
       
   119 then
       
   120   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   121   echo -e " count_tours from every position on the board" >> $out
       
   122   echo -e " dim = 1: 1" >> $out
       
   123   echo -e "       2: 0,0,0,0" >>  $out
       
   124   echo -e "       3: 0,0,0,0,0,0,0,0,0" >>  $out
       
   125   echo -e "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
       
   126   #echo -e "       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" >> $out
       
   127   echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out
       
   128   echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out
       
   129   echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
       
   130   
       
   131   if (scala_assert_quick "knight1.scala" "knight_test3.scala") 
       
   132   then
       
   133     echo -e "  --> success" >> $out
       
   134   else
       
   135     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   136   fi
       
   137 fi
       
   138 
       
   139 ### knight4 test
       
   140 
       
   141 if [ $tsts1 -eq 0 ]
       
   142 then
       
   143   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   144   echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
       
   145   echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
       
   146   echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
       
   147 
       
   148   if (scala_assert_quick "knight1.scala" "knight_test4.scala") 
       
   149   then
       
   150     echo -e "  --> success" >> $out
       
   151   else
       
   152     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   153   fi
       
   154 fi
       
   155 
       
   156 
       
   157 ### knight5 test
       
   158 
       
   159 if [ $tsts1 -eq 0 ]
       
   160 then
       
   161   echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   162   echo -e " is first_tour(6, List((0, 0))) ok? " >> $out
       
   163   echo -e " is first_tour(4, List((0, 0))) == None " >> $out
       
   164 
       
   165   if (scala_assert_quick "knight1.scala" "knight_test5.scala") 
       
   166   then
       
   167     echo -e "  --> success" >> $out
       
   168   else
       
   169     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   170   fi
       
   171 fi
       
   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_heuristics(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_heuristics(8, List((0,0))) found and correct?" >> $out
       
   249   echo -e " first_tour_heuristics(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_slow "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