marking3/knight3_test.sh
changeset 258 ebe71908b13e
parent 243 9bb36426c781
child 259 43995ea34fe7
equal deleted inserted replaced
257:ba4d976ca88d 258:ebe71908b13e
     7 out=${1:-output}
     7 out=${1:-output}
     8 
     8 
     9 echo "" > $out
     9 echo "" > $out
    10 
    10 
    11 echo "Below is the feedback and provisional marks for your submission" >> $out
    11 echo "Below is the feedback and provisional marks for your submission" >> $out
    12 echo "for assignment 7 Part 2.  Please note all marks are provisional until" >> $out
    12 echo "for assignment 8 Advanced Part 2.  Please note all marks are provisional until" >> $out
    13 echo "ratified by the assessment board -- this is not an official" >> $out
    13 echo "ratified by the assessment board -- this is not an official" >> $out
    14 echo "results transcript." >> $out
    14 echo "results transcript." >> $out
    15 echo "" >> $out
    15 echo "" >> $out
    16 
    16 
    17 # marks for CW7 part 2
    17 # marks for CW8 part 2
    18 marks=$(( 0 ))
    18 marks=$(( 0 ))
    19 
    19 
    20 # compilation tests
    20 # compilation tests
    21 
    21 
    22 function scala_compile {
    22 function scala_compile {
    23     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
    23     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
    24 }
    24 }
    25 
    25 
    26 # functional tests
    26 # functional tests
    27 
    27 
    28 function scala_assert {
    28 function scala_assert {
    29     (ulimit -t 360; JAVA_OPTS="-Xmx4g -Xss200m" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    29     (ulimit -t 30; JAVA_OPTS="-Xmx4g -Xss200m" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    30 }
    30 }
    31 
    31 
       
    32 function scala_assert_long {
       
    33   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    34 }
       
    35 
       
    36 function scala_assert_elong {
       
    37   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    38 }
    32 
    39 
    33 # purity test
    40 # purity test
    34 
    41 
    35 function scala_vars {
    42 function scala_vars {
    36    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
    43    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
    37 }
    44 }
    38 
    45 
    39 
    46 
    40 # knights3: purity test
    47 # knights2: purity test
    41 #
    48 #
    42 echo "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
    49 echo "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
    43 
    50 
    44 
    51 
    45 if (scala_vars knight3.scala)
    52 if (scala_vars knight2.scala)
    46 then
    53 then
    47   echo "  --> test failed" | tee -a $out
    54   echo "  --> test failed" | tee -a $out
    48   tsts0=$(( 1 ))
    55   tsts0=$(( 1 ))
    49 else
    56 else
    50   echo "  --> success" | tee -a $out
    57   echo "  --> success" | tee -a $out
    53 
    60 
    54 
    61 
    55 # compilation test
    62 # compilation test
    56 if  [ $tsts0 -eq 0 ]
    63 if  [ $tsts0 -eq 0 ]
    57 then    
    64 then    
    58   echo "knight3.scala runs?" | tee -a $out
    65   echo "knight2.scala runs?" | tee -a $out
    59 
    66 
    60   if (scala_compile knight3.scala)
    67   if (scala_compile knight2.scala)
    61   then
    68   then
    62     echo "  --> success" | tee -a $out
    69     echo "  --> success" | tee -a $out
    63     tsts1=$(( 0 ))
    70     tsts1=$(( 0 ))
    64   else
    71   else
    65     echo "  --> scala knight3.scala did not run successfully" | tee -a $out
    72     echo "  --> scala knight2.scala did not run successfully" | tee -a $out
    66     tsts1=$(( 1 )) 
    73     tsts1=$(( 1 )) 
    67   fi
    74   fi
    68 else
    75 else
    69   tsts1=$(( 1 ))     
    76   tsts1=$(( 1 ))     
    70 fi
    77 fi
    75 then
    82 then
    76   echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
    83   echo " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
    77   echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
    84   echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
    78   echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
    85   echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
    79   
    86   
    80   if (scala_assert "knight3.scala" "knight3a_test.scala")
    87   if (scala_assert "knight2.scala" "knight_test6.scala")
    81   then
    88   then
    82       echo "  --> success" | tee -a $out
    89       echo "  --> success" | tee -a $out
    83       marks=$(( marks + 1 ))
    90       marks=$(( marks + 1 ))
    84   else
    91   else
    85     echo "  --> test failed" | tee -a $out
    92     echo "  --> test failed" | tee -a $out
    91 
    98 
    92 if [ $tsts1 -eq 0 ]
    99 if [ $tsts1 -eq 0 ]
    93 then
   100 then
    94   echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
   101   echo " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out
    95   
   102   
    96   if (scala_assert "knight3.scala" "knight3b_test.scala")
   103   if (scala_assert "knight2.scala" "knight_test7.scala")
    97   then
   104   then
    98       echo "  --> success" | tee -a $out
   105       echo "  --> success" | tee -a $out
    99       marks=$(( marks + 1 ))
   106       marks=$(( marks + 1 ))
   100   else
   107   else
   101       echo "  --> test failed" | tee -a $out
   108       echo "  --> test failed" | tee -a $out
   107 if [ $tsts1 -eq 0 ]
   114 if [ $tsts1 -eq 0 ]
   108 then
   115 then
   109   echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
   116   echo " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out
   110   echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
   117   echo " first_tour_heuristic(40, List((0,0))) found and correct?" | tee -a $out
   111   
   118   
   112   if (scala_assert "knight3.scala" "knight3c_test.scala")
   119   if (scala_assert "knight2.scala" "knight_test8.scala")
   113   then
   120   then
   114       echo "  --> success" | tee -a $out
   121       echo "  --> success" | tee -a $out
   115       marks=$(( marks + 1 ))
   122       marks=$(( marks + 1 ))
   116   else
   123   else
   117     echo "  --> test failed" | tee -a $out
   124     echo "  --> test failed" | tee -a $out
   118   fi
   125   fi
   119 fi
   126 fi
   120 
   127 
   121 
   128 
       
   129 
       
   130 # knights3: purity test
       
   131 #
       
   132 echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
   133 
       
   134 
       
   135 if (scala_vars knight3.scala)
       
   136 then
       
   137   echo "  --> test failed" | tee -a $out
       
   138   tsts0=$(( 0 ))
       
   139 else
       
   140   echo "  --> success" | tee -a $out
       
   141   tsts0=$(( 0 )) 
       
   142 fi
       
   143 
       
   144 # compilation test
       
   145 if  [ $tsts0 -eq 0 ]
       
   146 then    
       
   147   echo "knight3.scala runs?" | tee -a $out
       
   148 
       
   149   if (scala_compile knight3.scala)
       
   150   then
       
   151     echo "  --> success" | tee -a $out
       
   152     tsts1=$(( 0 ))
       
   153   else
       
   154     echo -e "  --> test failed" | tee -a $out  
       
   155     tsts1=$(( 1 )) 
       
   156   fi
       
   157 else
       
   158   tsts1=$(( 1 ))     
       
   159 fi
       
   160 
       
   161 
       
   162 if [ $tsts1 -eq 0 ]
       
   163 then
       
   164   echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out
       
   165   
       
   166   if (scala_assert_long "knight3.scala" "knight_test9.scala")
       
   167   then
       
   168       echo -e "  --> success" | tee -a $out
       
   169       marks=$(( marks + 1 ))
       
   170   else
       
   171       echo -e "  --> test  failed" | tee -a $out 
       
   172   fi
       
   173 fi
       
   174 
       
   175 
   122 ## final marks
   176 ## final marks
   123 echo "Overall mark for CW 7, Part 2" | tee -a $out
   177 echo "Overall mark for CW 8, Part 2" | tee -a $out
   124 echo "$marks" | tee -a $out
   178 echo "$marks" | tee -a $out