marking3/knight1_test.sh
changeset 326 e5453add7df6
parent 250 1b08b8ac13fd
child 331 e3878cdd38bc
equal deleted inserted replaced
325:ca9c1cf929fa 326:e5453add7df6
     6 out=${1:-output}
     6 out=${1:-output}
     7 
     7 
     8 echo "" > $out
     8 echo "" > $out
     9 
     9 
    10 echo "Below is the feedback and provisional marks for your submission" >> $out
    10 echo "Below is the feedback and provisional marks for your submission" >> $out
    11 echo "for assignment 8 Part 1.  Please note all marks are provisional until" >> $out
    11 echo "for Preliminary 8.  Please note all marks are provisional until" >> $out
    12 echo "ratified by the assessment board -- this is not an official" >> $out
    12 echo "ratified by the assessment board -- this is not an official" >> $out
    13 echo "results transcript." >> $out
    13 echo "results transcript." >> $out
    14 echo "" >> $out
    14 echo "" >> $out
    15 
    15 
    16 
    16 
    17 
    17 
    18 # marks for CW8 part 1
    18 # marks for CW8 part 1
    19 marks=$(( 0 ))
    19 marks=$(( 0 ))
    20 
    20 
    21 
    21 
    22 # compilation tests (used to be 30 secs)
       
    23 
       
    24 function scala_compile {
    22 function scala_compile {
    25   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null) 
    23   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
    26 }
    24 }
    27 
    25 
    28 # functional tests
    26 # functional tests
    29 
    27 
       
    28 function scala_assert_slow {
       
    29   (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "-- $2" 2> /dev/null 1> /dev/null)
       
    30 }
       
    31 
       
    32 function scala_assert_thirty {
       
    33   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    34 }
       
    35 
       
    36 function scala_assert_quick {
       
    37   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    38 }
       
    39 
    30 function scala_assert {
    40 function scala_assert {
    31   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
    41   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala  -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
    32 }
    42 }
    33 
    43 
    34 function scala_assert_long {
    44 function scala_assert_long {
    35   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
    45   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -2> /dev/null 1> /dev/null)
    36 }
    46 }
    37 
    47 
    38 function scala_assert_elong {
    48 function scala_assert_elong {
    39   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
    49   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
    40 }
    50 }
    41 
       
    42 
    51 
    43 # purity test
    52 # purity test
    44 
    53 
    45 function scala_vars {
    54 function scala_vars {
    46    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
    55    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
    51 
    60 
    52 echo "knight1.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
    61 echo "knight1.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
    53 
    62 
    54 if (scala_vars knight1.scala)
    63 if (scala_vars knight1.scala)
    55 then
    64 then
    56   echo "  --> fail" | tee -a $out
    65   echo "  --> FAIL" | tee -a $out
    57   tsts0=$(( 1 ))
    66   tsts0=$(( 1 ))
    58 else
    67 else
    59   echo "  --> success" | tee -a $out
    68   echo "  --> success" | tee -a $out
    60   tsts0=$(( 0 )) 
    69   tsts0=$(( 0 )) 
    61 fi
    70 fi
    70   if (scala_compile knight1.scala)
    79   if (scala_compile knight1.scala)
    71   then
    80   then
    72     echo "  --> success " | tee -a $out
    81     echo "  --> success " | tee -a $out
    73     tsts1=$(( 0 ))
    82     tsts1=$(( 0 ))
    74   else
    83   else
    75     echo "  --> scala did not run knight1.scala" | tee -a $out
    84     echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" | tee -a $out
    76     tsts1=$(( 1 )) 
    85     tsts1=$(( 1 )) 
    77   fi
    86   fi
    78 else
    87 else
    79   tsts1=$(( 1 ))   
    88   tsts1=$(( 1 ))   
    80 fi
    89 fi
    87     echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
    96     echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
    88     echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out                          
    97     echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out                          
    89 
    98 
    90     if (scala_assert "knight1.scala" "knight1_test1.scala")
    99     if (scala_assert "knight1.scala" "knight1_test1.scala")
    91     then
   100     then
    92         echo "  --> success" | tee -a $out
   101         echo -e "  --> success\n" | tee -a $out
    93 	marks=$(( marks + 1 ))
   102 	marks=$(( marks + 1 ))
    94     else
   103     else
    95         echo "  --> test failed" | tee -a $out
   104         echo -e "  --> \n ONE TEST FAILED\n"| tee -a $out
    96     fi
   105     fi
    97 fi
   106 fi
    98 
   107 
    99 ### knight2 test
   108 ### knight2 test
   100 
   109 
   101 if [ $tsts1 -eq 0 ]
   110 if [ $tsts1 -eq 0 ]
   102 then
   111 then
   103   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
   112   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
   104   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out
   113   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out
   105   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
   114   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
       
   115   echo " legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0))" | tee -a $out
   106   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
   116   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
   107   echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
   117   echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
   108   echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
   118   echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
   109   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
   119   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
   110   
   120   
   111   if (scala_assert "knight1.scala" "knight1_test2.scala")
   121   if (scala_assert "knight1.scala" "knight1_test2.scala")
   112   then
   122   then
   113      echo "  --> success" | tee -a $out
   123      echo -e "  --> success\n" | tee -a $out
   114      marks=$(( marks + 1 ))
   124      marks=$(( marks + 1 ))
   115   else
   125   else
   116     echo "  --> test failed" | tee -a $out
   126      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
   117   fi
   127   fi
   118 fi
   128 fi
   119 
   129 
   120 
   130 
   121 ### knight3 test
   131 ### knight3 test
   126   echo " dim = 1: 1" | tee -a $out
   136   echo " dim = 1: 1" | tee -a $out
   127   echo "       2: 0,0,0,0" | tee -a $out
   137   echo "       2: 0,0,0,0" | tee -a $out
   128   echo "       3: 0,0,0,0,0,0,0,0,0" | tee -a $out
   138   echo "       3: 0,0,0,0,0,0,0,0,0" | tee -a $out
   129   echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
   139   echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
   130   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
   140   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
       
   141   START=$(date +%s)
   131   
   142   
   132   if (time scala_assert_elong "knight1.scala" "knight1_test3a.scala") 
   143   if (scala_assert_elong "knight1.scala" "knight1_test3a.scala") 
   133   then
   144   then
   134      echo "  --> success" | tee -a $out
   145      END=$(date +%s)
       
   146      DIFF=$(( $END - $START ))
       
   147      echo " It took $DIFF seconds" | tee -a $out  
       
   148      echo -e "  --> success\n" | tee -a $out
   135      marks=$(( marks + 1 ))
   149      marks=$(( marks + 1 ))
   136   else
   150   else
   137     echo "  --> test failed" | tee -a $out
   151      END=$(date +%s)
       
   152      DIFF=$(( $END - $START ))
       
   153      echo " It took $DIFF seconds" | tee -a $out 
       
   154      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
   138   fi
   155   fi
   139 fi
   156 fi
   140 
   157 
   141 if [ $tsts1 -eq 0 ]
   158 if [ $tsts1 -eq 0 ]
   142 then
   159 then
   143   echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out
   160   echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out
       
   161   echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out
       
   162   START=$(date +%s)
   144   
   163   
   145   if (time scala_assert "knight1.scala" "knight1_test3b.scala") 
   164   if (scala_assert "knight1.scala" "knight1_test3b.scala") 
   146   then
   165   then
   147      echo "  --> success" | tee -a $out
   166      END=$(date +%s)
       
   167      DIFF=$(( $END - $START ))
       
   168      echo " It took $DIFF seconds" | tee -a $out 
       
   169      echo -e "  --> success\n" | tee -a $out
   148      marks=$(( marks + 1 ))
   170      marks=$(( marks + 1 ))
   149   else
   171   else
   150     echo "  --> test failed" | tee -a $out
   172      END=$(date +%s)
   151   fi
   173      DIFF=$(( $END - $START ))
   152 fi
   174      echo " It took $DIFF seconds" | tee -a $out 
   153 
   175      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
   154 
       
   155 ### knight4 test
       
   156 
       
   157 if [ $tsts1 -eq 0 ]
       
   158 then
       
   159   echo " val f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out
       
   160   echo "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" | tee -a $out
       
   161   echo "   first(List((1,0),(2,0),(3,0)), f) == None" | tee -a $out
       
   162 
       
   163   if (scala_assert "knight1.scala" "knight1_test4.scala") 
       
   164   then
       
   165     echo "  --> success" | tee -a $out
       
   166     marks=$(( marks + 1 ))
       
   167   else
       
   168     echo "  --> test failed" | tee -a $out
       
   169   fi
       
   170 fi
       
   171 
       
   172 
       
   173 ### knight5 test
       
   174 
       
   175 if [ $tsts1 -eq 0 ]
       
   176 then
       
   177   echo " is first_tour(8, List((0, 0))) ok? " | tee -a $out
       
   178   echo " is first_tour(4, List((0, 0))) == None " | tee -a $out
       
   179 
       
   180   if (time scala_assert_long "knight1.scala" "knight1_test5.scala") 
       
   181   then
       
   182      echo "  --> success" | tee -a $out
       
   183      marks=$(( marks + 1 ))
       
   184   else
       
   185     echo "  --> test failed" | tee -a $out
       
   186   fi
   176   fi
   187 fi
   177 fi
   188 
   178 
   189 
   179 
   190 ## final marks
   180 ## final marks
   191 echo "Overall mark for Part 1" | tee -a $out
   181 echo "Overall mark for Preliminary 8" | tee -a $out
   192 echo "$marks" | tee -a $out
   182 echo "$marks" | tee -a $out
   193 
   183 
   194 
   184