testing3-bak/knight1_test.sh
changeset 245 975d34506e88
parent 244 a359976a6f3e
child 246 178438912e5f
equal deleted inserted replaced
244:a359976a6f3e 245:975d34506e88
     1 #!/bin/bash
       
     2 set -e
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo "" > $out
       
     7 
       
     8 echo "Below is the feedback for your submission of CW 7, Part 1 and 2." >> $out
       
     9 echo "" >> $out
       
    10 
       
    11 
       
    12 # compilation tests
       
    13 
       
    14 function scala_compile {
       
    15   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
       
    16 }
       
    17 
       
    18 # functional tests
       
    19 
       
    20 function scala_assert_slow {
       
    21   (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    22 }
       
    23 
       
    24 function scala_assert_thirty {
       
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    26 }
       
    27 
       
    28 function scala_assert_quick {
       
    29   (ulimit -t 10; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    30 }
       
    31 
       
    32 # purity test
       
    33 
       
    34 function scala_vars {
       
    35    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    36 }
       
    37 
       
    38 
       
    39 # knights1: purity test
       
    40 
       
    41 echo "knight1.scala does not contain vars, returns etc?" >> $out
       
    42 
       
    43 if (scala_vars knight1.scala)
       
    44 then
       
    45   echo "  --> fail: if you do not fix this, you will receive a mark of zero" >> $out
       
    46   tsts0=$(( 1 ))
       
    47 else
       
    48   echo "  --> success" >> $out
       
    49   tsts0=$(( 0 )) 
       
    50 fi
       
    51 
       
    52 
       
    53 # compilation test
       
    54 
       
    55 if [ $tsts0 -eq 0 ]
       
    56 then    
       
    57   echo "knight1.scala runs?" >> $out
       
    58 
       
    59   if (scala_compile knight1.scala)
       
    60   then
       
    61     echo "  --> success " >> $out
       
    62     tsts1=$(( 0 ))
       
    63   else
       
    64     echo "  --> scala did not run knight1.scala" >> $out
       
    65     tsts1=$(( 1 )) 
       
    66   fi
       
    67 else
       
    68   tsts1=$(( 1 ))   
       
    69 fi
       
    70 
       
    71 ### knight1a test
       
    72 
       
    73 if [ $tsts1 -eq 0 ]
       
    74 then
       
    75     echo "Takes 10 seconds or less to execute: " >> $out
       
    76     echo " is_legal(8, Nil)(3, 4) == true " >> $out
       
    77     echo " is_legal(8, List((4, 1), (1, 0)))(4, 1) == false " >> $out
       
    78     echo " is_legal(2, Nil)(0, 0) == true" >> $out                          
       
    79 
       
    80     if (scala_assert_quick "knight1.scala" "knight1a_test.scala")
       
    81     then
       
    82         echo "  --> success" >> $out
       
    83     else
       
    84         echo "  --> test failed" >> $out
       
    85     fi
       
    86 fi
       
    87 
       
    88 ### knight1b test
       
    89 
       
    90 if [ $tsts1 -eq 0 ]
       
    91 then
       
    92   echo "Takes 10 seconds or less to execute: " >> $out
       
    93   echo " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
       
    94   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
       
    95   echo " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
       
    96   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
       
    97   echo " legal_moves(1, Nil, (0,0)) == Nil" >> $out
       
    98   echo " legal_moves(2, Nil, (0,0)) == Nil" >> $out
       
    99   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
       
   100   
       
   101   if (scala_assert_quick "knight1.scala" "knight1b_test.scala")
       
   102   then
       
   103     echo "  --> success" >> $out
       
   104   else
       
   105     echo "  --> test failed" >> $out
       
   106   fi
       
   107 fi
       
   108 
       
   109 
       
   110 ### knight1c test
       
   111 
       
   112 if [ $tsts1 -eq 0 ]
       
   113 then
       
   114   echo " all_tours from every position on the board, in 2 minutes or less" >> $out
       
   115   echo " dim = 1: 1" >> $out
       
   116   echo "       2: 0,0,0,0" >>  $out
       
   117   echo "       3: 0,0,0,0,0,0,0,0,0" >>  $out
       
   118   echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
       
   119   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" >> $out
       
   120   echo " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
       
   121   
       
   122   if (scala_assert_slow "knight1.scala" "knight1c_test.scala") 
       
   123   then
       
   124     echo "  --> success" >> $out
       
   125   else
       
   126     echo "  --> test failed" >> $out
       
   127   fi
       
   128 fi
       
   129 
       
   130 
       
   131 # knights2: var test
       
   132 
       
   133 echo "knight2.scala does not contain vars, returns etc?" >> $out
       
   134 
       
   135 if (scala_vars knight2.scala)
       
   136 then
       
   137   echo "  --> fail" >> $out
       
   138   tsts0=$(( 1 ))
       
   139 else
       
   140   echo "  --> success" >> $out
       
   141   tsts0=$(( 0 )) 
       
   142 fi
       
   143 
       
   144 
       
   145 # compilation test
       
   146 if  [ $tsts0 -eq 0 ]
       
   147 then    
       
   148   echo "knight2.scala runs?" >> $out
       
   149 
       
   150   if (scala_compile knight2.scala)
       
   151   then
       
   152     echo "  --> success" >> $out
       
   153     tsts1=$(( 0 ))
       
   154   else
       
   155     echo "  --> scala did not run knight2.scala" >> $out
       
   156     tsts1=$(( 1 )) 
       
   157   fi
       
   158 else
       
   159   tsts1=$(( 1 ))     
       
   160 fi
       
   161 
       
   162 ### knight2a test
       
   163 
       
   164 if [ $tsts1 -eq 0 ]
       
   165 then
       
   166   echo "Takes 10 seconds or less to execute: " >> $out
       
   167   echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
       
   168   echo "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
       
   169   echo "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
       
   170 
       
   171   if (scala_assert_quick "knight2.scala" "knight2a_test.scala") 
       
   172   then
       
   173     echo "  --> success" >> $out
       
   174   else
       
   175     echo "  --> test failed" >> $out
       
   176   fi
       
   177 fi
       
   178 
       
   179 
       
   180 ### knight2b test
       
   181 
       
   182 if [ $tsts1 -eq 0 ]
       
   183 then
       
   184   echo "Takes 30 seconds or less to execute: " >> $out
       
   185   echo " is first_tour(8, List((0, 0))) ok? " >> $out
       
   186   echo " is first_tour(4, List((0, 0))) == None " >> $out
       
   187 
       
   188   if (scala_assert_thirty "knight2.scala" "knight2b_test.scala") 
       
   189   then
       
   190     echo "  --> success" >> $out
       
   191   else
       
   192     echo "  --> test failed" >> $out
       
   193   fi
       
   194 fi
       
   195