testing2/knight1_test.sh
changeset 153 4383809c176a
parent 152 114a89518aea
equal deleted inserted replaced
152:114a89518aea 153:4383809c176a
    10 
    10 
    11 
    11 
    12 # compilation tests
    12 # compilation tests
    13 
    13 
    14 function scala_compile {
    14 function scala_compile {
    15   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
    15   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    16 }
    16 }
    17 
    17 
    18 # functional tests
    18 # functional tests
    19 
    19 
    20 function scala_assert {
    20 function scala_assert_slow {
    21   (ulimit -t 300 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    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)
    22 }
    30 }
    23 
    31 
    24 # purity test
    32 # purity test
    25 
    33 
    26 function scala_vars {
    34 function scala_vars {
    27    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
    35    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
    28 }
    36 }
    29 
    37 
    30 
    38 
    31 # knights1: purity test
    39 # knights1: purity test
    32 
    40 
    33 echo "knight1.scala does not contain vars, returns etc?" >> $out
    41 echo "knight1.scala does not contain vars, returns etc?" >> $out
    34 
    42 
    35 if (scala_vars knight1.scala)
    43 if (scala_vars knight1.scala)
    36 then
    44 then
    37   echo "  --> fail" >> $out
    45   echo "  --> fail: if you do not fix this, you will receive a mark of zero" >> $out
    38   tsts0=$(( 1 ))
    46   tsts0=$(( 1 ))
    39 else
    47 else
    40   echo "  --> success" >> $out
    48   echo "  --> success" >> $out
    41   tsts0=$(( 0 )) 
    49   tsts0=$(( 0 )) 
    42 fi
    50 fi
    62 
    70 
    63 ### knight1a test
    71 ### knight1a test
    64 
    72 
    65 if [ $tsts1 -eq 0 ]
    73 if [ $tsts1 -eq 0 ]
    66 then
    74 then
    67     echo " is_legal(8, Nil) (3, 4) == true " >> $out
    75     echo "Takes 10 seconds or less to execute: " >> $out
    68     echo " is_legal(8, List((4, 1), (1, 0))) (4, 1) == false " >> $out
    76     echo " is_legal(8, Nil)(3, 4) == true " >> $out
    69     echo " is_legal(2, Nil) (0, 0) == 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                          
    70 
    79 
    71     if (scala_assert "knight1.scala" "knight1a_test.scala")
    80     if (scala_assert_quick "knight1.scala" "knight1a_test.scala")
    72     then
    81     then
    73         echo "  --> success" >> $out
    82         echo "  --> success" >> $out
    74     else
    83     else
    75         echo "  --> test failed" >> $out
    84         echo "  --> test failed" >> $out
    76     fi
    85     fi
    78 
    87 
    79 ### knight1b test
    88 ### knight1b test
    80 
    89 
    81 if [ $tsts1 -eq 0 ]
    90 if [ $tsts1 -eq 0 ]
    82 then
    91 then
       
    92   echo "Takes 10 seconds or less to execute: " >> $out
    83   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
    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
    84   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
    94   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
    85   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
    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
    86   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
    96   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
    87   echo " legal_moves(1, Nil, (0,0)) == Nil" >> $out
    97   echo " legal_moves(1, Nil, (0,0)) == Nil" >> $out
    88   echo " legal_moves(2, Nil, (0,0)) == Nil" >> $out
    98   echo " legal_moves(2, Nil, (0,0)) == Nil" >> $out
    89   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
    99   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
    90   
   100   
    91   if (scala_assert "knight1.scala" "knight1b_test.scala")
   101   if (scala_assert_quick "knight1.scala" "knight1b_test.scala")
    92   then
   102   then
    93     echo "  --> success" >> $out
   103     echo "  --> success" >> $out
    94   else
   104   else
    95     echo "  --> test failed" >> $out
   105     echo "  --> test failed" >> $out
    96   fi
   106   fi
    99 
   109 
   100 ### knight1c test
   110 ### knight1c test
   101 
   111 
   102 if [ $tsts1 -eq 0 ]
   112 if [ $tsts1 -eq 0 ]
   103 then
   113 then
   104   echo " all_tours from every position on the board" >> $out
   114   echo " all_tours from every position on the board, in 2 minutes or less" >> $out
   105   echo " dim = 1: 1" >> $out
   115   echo " dim = 1: 1" >> $out
   106   echo "       2: 0,0,0,0" >>  $out
   116   echo "       2: 0,0,0,0" >>  $out
   107   echo "       3: 0,0,0,0,0,0,0,0,0" >>  $out
   117   echo "       3: 0,0,0,0,0,0,0,0,0" >>  $out
   108   echo "       4: 0,0,0,0,0,0,0,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
   109   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
   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
   110   echo " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
   120   echo " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
   111   
   121   
   112   if (scala_assert "knight1.scala" "knight1c_test.scala") 
   122   if (scala_assert_slow "knight1.scala" "knight1c_test.scala") 
   113   then
   123   then
   114     echo "  --> success" >> $out
   124     echo "  --> success" >> $out
   115   else
   125   else
   116     echo "  --> test failed" >> $out
   126     echo "  --> test failed" >> $out
   117   fi
   127   fi
   151 
   161 
   152 ### knight2a test
   162 ### knight2a test
   153 
   163 
   154 if [ $tsts1 -eq 0 ]
   164 if [ $tsts1 -eq 0 ]
   155 then
   165 then
       
   166   echo "Takes 10 seconds or less to execute: " >> $out
   156   echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
   167   echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
   157   echo "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
   168   echo "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
   158   echo "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
   169   echo "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
   159 
   170 
   160   if (scala_assert "knight2.scala" "knight2a_test.scala") 
   171   if (scala_assert_quick "knight2.scala" "knight2a_test.scala") 
   161   then
   172   then
   162     echo "  --> success" >> $out
   173     echo "  --> success" >> $out
   163   else
   174   else
   164     echo "  --> test failed" >> $out
   175     echo "  --> test failed" >> $out
   165   fi
   176   fi
   168 
   179 
   169 ### knight2b test
   180 ### knight2b test
   170 
   181 
   171 if [ $tsts1 -eq 0 ]
   182 if [ $tsts1 -eq 0 ]
   172 then
   183 then
       
   184   echo "Takes 30 seconds or less to execute: " >> $out
   173   echo " is first_tour(8, List((0, 0))) ok? " >> $out
   185   echo " is first_tour(8, List((0, 0))) ok? " >> $out
   174   echo " is first_tour(4, List((0, 0))) == None " >> $out
   186   echo " is first_tour(4, List((0, 0))) == None " >> $out
   175 
   187 
   176   if (scala_assert "knight2.scala" "knight2b_test.scala") 
   188   if (scala_assert_thirty "knight2.scala" "knight2b_test.scala") 
   177   then
   189   then
   178     echo "  --> success" >> $out
   190     echo "  --> success" >> $out
   179   else
   191   else
   180     echo "  --> test failed" >> $out
   192     echo "  --> test failed" >> $out
   181   fi
   193   fi