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