main_testing4/knight_test.sh
changeset 347 4de31fdc0d67
parent 329 8a34b2ebc8cc
child 352 97bcf8efe4e0
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 
       
    19 # compilation tests
       
    20 
       
    21 function scala_compile {
       
    22   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    23 }
       
    24 
       
    25 # functional tests
       
    26 
       
    27 function scala_assert {
       
    28   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    29 }
       
    30 
       
    31 # purity test
       
    32 
       
    33 function scala_vars {
       
    34    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    35 }
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 
       
    41 # compilation test
       
    42 
       
    43   
       
    44 echo -e "knight1.scala runs?" >> $out
       
    45 
       
    46 if (scala_compile knight1.scala)
       
    47 then
       
    48     echo -e "  --> success " >> $out
       
    49     tsts1=$(( 0 ))
       
    50   else
       
    51     echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" >> $out
       
    52     tsts1=$(( 1 )) 
       
    53 fi
       
    54 
       
    55 
       
    56 # knights1: purity test
       
    57 
       
    58 if [ $tsts1 -eq 0 ]
       
    59 then  
       
    60     echo -e "knight1.scala does not contain vars, returns etc?" >> $out
       
    61 
       
    62     if (scala_vars knight1.scala)
       
    63     then
       
    64 	echo -e "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
       
    65 	tsts1=$(( 1 ))
       
    66     else
       
    67 	echo -e "  --> success" >> $out
       
    68 	tsts1=$(( 0 )) 
       
    69     fi
       
    70 fi    
       
    71 
       
    72 
       
    73 ### knight1 test
       
    74 
       
    75 if [ $tsts1 -eq 0 ]
       
    76 then
       
    77     #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
    78     echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out
       
    79     echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out
       
    80     echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out                          
       
    81 
       
    82     if (scala_assert "knight1.scala" "knight_test1.scala")
       
    83     then
       
    84         echo -e "  --> success" >> $out
       
    85     else
       
    86         echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    87     fi
       
    88 fi
       
    89 
       
    90 ### knight2 test
       
    91 
       
    92 if [ $tsts1 -eq 0 ]
       
    93 then
       
    94   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
    95   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
       
    96   echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
       
    97   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
       
    98   echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
       
    99   echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out
       
   100   echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out
       
   101   echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
       
   102   
       
   103   if (scala_assert "knight1.scala" "knight_test2.scala")
       
   104   then
       
   105     echo -e "  --> success" >> $out
       
   106   else
       
   107     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   108   fi
       
   109 fi
       
   110 
       
   111 
       
   112 ### knight3 test
       
   113 
       
   114 if [ $tsts1 -eq 0 ]
       
   115 then
       
   116   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   117   echo -e " count_tours from every position on the board" >> $out
       
   118   echo -e " dim = 1: 1" >> $out
       
   119   echo -e "       2: 0,0,0,0" >>  $out
       
   120   echo -e "       3: 0,0,0,0,0,0,0,0,0" >>  $out
       
   121   echo -e "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
       
   122   #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
       
   123   echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out
       
   124   echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out
       
   125   echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
       
   126   
       
   127   if (scala_assert "knight1.scala" "knight_test3.scala") 
       
   128   then
       
   129     echo -e "  --> success" >> $out
       
   130   else
       
   131     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   132   fi
       
   133 fi
       
   134 
       
   135 ### knight4 test
       
   136 
       
   137 if [ $tsts1 -eq 0 ]
       
   138 then
       
   139   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   140   echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
       
   141   echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
       
   142   echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
       
   143 
       
   144   if (scala_assert "knight1.scala" "knight_test4.scala") 
       
   145   then
       
   146     echo -e "  --> success" >> $out
       
   147   else
       
   148     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   149   fi
       
   150 fi
       
   151 
       
   152 
       
   153 ### knight5 test
       
   154 
       
   155 if [ $tsts1 -eq 0 ]
       
   156 then
       
   157   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   158   echo -e " is first_tour(6, List((0, 0))) ok? " >> $out
       
   159   echo -e " is first_tour(4, List((0, 0))) == None " >> $out
       
   160 
       
   161   if (scala_assert "knight1.scala" "knight_test5.scala") 
       
   162   then
       
   163     echo -e "  --> success" >> $out
       
   164   else
       
   165     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   166   fi
       
   167 fi
       
   168 
       
   169 
       
   170 echo -e "" >> $out
       
   171 echo -e "" >> $out
       
   172 
       
   173 
       
   174 # compilation test
       
   175 echo -e "knight2.scala runs?" >> $out
       
   176 
       
   177 if (scala_compile knight2.scala)
       
   178 then
       
   179     echo -e "  --> success" >> $out
       
   180     tsts2=$(( 0 ))
       
   181 else
       
   182     echo -e "  --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out  
       
   183     tsts2=$(( 1 )) 
       
   184 fi
       
   185 
       
   186 
       
   187 # knights2: purity test
       
   188 #
       
   189 
       
   190 if [ $tsts2 -eq 0 ]
       
   191 then
       
   192     echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
       
   193 
       
   194     if (scala_vars knight2.scala)
       
   195     then
       
   196 	echo -e "  --> Fail (make triple-sure your program conforms to the required format)" >> $out    
       
   197 	tsts2=$(( 1 ))
       
   198     else
       
   199 	echo -e "  --> success" >> $out
       
   200 	tsts2=$(( 0 )) 
       
   201     fi
       
   202 fi
       
   203 
       
   204 
       
   205 # ordered move test
       
   206 
       
   207 if [ $tsts2 -eq 0 ]
       
   208 then
       
   209   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out  
       
   210   echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
       
   211   echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
       
   212   echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
       
   213   
       
   214   if (scala_assert "knight2.scala" "knight_test6.scala")
       
   215   then
       
   216       echo -e "  --> success" >> $out
       
   217   else
       
   218       echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
   219   fi
       
   220 fi
       
   221 
       
   222 
       
   223 # first-closed-tour test
       
   224 
       
   225 if [ $tsts2 -eq 0 ]
       
   226 then
       
   227   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out  
       
   228   echo -e " first_closed_tour_heuristics(6, List((3,3))) found and correct?" >> $out
       
   229   
       
   230   if (scala_assert "knight2.scala" "knight_test7.scala")
       
   231   then
       
   232       echo -e "  --> success" >> $out
       
   233   else
       
   234       echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
   235   fi
       
   236 fi
       
   237 
       
   238 
       
   239 
       
   240 if [ $tsts2 -eq 0 ]
       
   241 then
       
   242   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out   
       
   243   echo -e " first_tour_heuristics(8, List((0,0))) found and correct?" >> $out
       
   244   echo -e " first_tour_heuristics(30, List((0,0))) found and correct?" >> $out
       
   245   
       
   246   if (scala_assert "knight2.scala" "knight_test8.scala")
       
   247   then
       
   248       echo -e "  --> success" >> $out
       
   249   else
       
   250       echo -e "  --> \n ONE TEST FAILED\n" >> $out 
       
   251   fi
       
   252 fi
       
   253 
       
   254 
       
   255 echo -e "" >> $out
       
   256 echo -e "" >> $out
       
   257 
       
   258 
       
   259 
       
   260 # compilation test
       
   261    
       
   262 echo "knight3.scala runs?" >> $out
       
   263 
       
   264 if (scala_compile knight3.scala)
       
   265 then
       
   266     echo "  --> success" >> $out
       
   267     tsts3=$(( 0 ))
       
   268 else
       
   269     echo -e "  --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out  
       
   270     tsts3=$(( 1 )) 
       
   271 fi
       
   272 
       
   273 # knights3: purity test
       
   274 #
       
   275 if  [ $tsts3 -eq 0 ]
       
   276 then 
       
   277     echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
       
   278 
       
   279     if (scala_vars knight3.scala)
       
   280     then
       
   281 	echo "  --> Fail (make triple-sure your program conforms to the required format)xsxs" >> $out
       
   282 	tsts3=$(( 1 ))
       
   283     else
       
   284 	echo "  --> success" >> $out
       
   285 	tsts3=$(( 0 )) 
       
   286     fi
       
   287 fi
       
   288 
       
   289 
       
   290 if [ $tsts3 -eq 0 ]
       
   291 then
       
   292   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out  
       
   293   echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" >> $out
       
   294   
       
   295   if (scala_assert "knight3.scala" "knight_test9.scala")
       
   296   then
       
   297       echo -e "  --> success" >> $out
       
   298   else
       
   299       echo -e "  --> \n ONE TEST FAILED\n" >> $out 
       
   300   fi
       
   301 fi
       
   302