marking3/knight1_test.sh
changeset 486 9c03b5e89a2a
parent 485 19b75e899d37
child 487 efad9725dfd8
equal deleted inserted replaced
485:19b75e899d37 486:9c03b5e89a2a
     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 Preliminary 8.  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 
       
    17 
       
    18 # marks for CW8 part 1
       
    19 marks=$(( 0 ))
       
    20 
       
    21 
       
    22 function scala_compile {
       
    23   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1") # 2>> $out 1>> $out) 
       
    24 }
       
    25 
       
    26 # functional tests
       
    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 
       
    40 function scala_assert {
       
    41   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala  -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    42 }
       
    43 
       
    44 function scala_assert_long {
       
    45   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -2> /dev/null 1> /dev/null)
       
    46 }
       
    47 
       
    48 function scala_assert_elong {
       
    49   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    50 }
       
    51 
       
    52 # purity test
       
    53 
       
    54 function scala_vars {
       
    55    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    56 }
       
    57 
       
    58 
       
    59 # knights1: purity test
       
    60 
       
    61 echo "knight1.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    62 
       
    63 if (scala_vars knight1.scala)
       
    64 then
       
    65   echo "  --> FAIL" | tee -a $out
       
    66   tsts0=$(( 1 ))
       
    67 else
       
    68   echo "  --> success" | tee -a $out
       
    69   tsts0=$(( 0 )) 
       
    70 fi
       
    71 
       
    72 
       
    73 # compilation test
       
    74 
       
    75 if [ $tsts0 -eq 0 ]
       
    76 then    
       
    77   echo "knight1.scala runs?" | tee -a $out
       
    78 
       
    79   if (scala_compile knight1.scala)
       
    80   then
       
    81     echo "  --> success " | tee -a $out
       
    82     tsts1=$(( 0 ))
       
    83   else
       
    84     echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" | tee -a $out
       
    85     tsts1=$(( 1 )) 
       
    86   fi
       
    87 else
       
    88   tsts1=$(( 1 ))   
       
    89 fi
       
    90 
       
    91 ### knight1 test
       
    92 
       
    93 if [ $tsts1 -eq 0 ]
       
    94 then
       
    95     echo " is_legal(8, Nil, (3, 4)) == true " | tee -a $out
       
    96     echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
       
    97     echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out                          
       
    98 
       
    99     if (scala_assert "knight1.scala" "knight1_test1.scala")
       
   100     then
       
   101         echo -e "  --> success\n" | tee -a $out
       
   102 	marks=$(( marks + 1 ))
       
   103     else
       
   104         echo -e "  --> \n ONE TEST FAILED\n"| tee -a $out
       
   105     fi
       
   106 fi
       
   107 
       
   108 ### knight2 test
       
   109 
       
   110 if [ $tsts1 -eq 0 ]
       
   111 then
       
   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
       
   113   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | 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
       
   116   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
       
   117   echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
       
   118   echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
       
   119   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
       
   120   
       
   121   if (scala_assert "knight1.scala" "knight1_test2.scala")
       
   122   then
       
   123      echo -e "  --> success\n" | tee -a $out
       
   124      marks=$(( marks + 1 ))
       
   125   else
       
   126      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
       
   127   fi
       
   128 fi
       
   129 
       
   130 
       
   131 ### knight3 test
       
   132 
       
   133 if [ $tsts1 -eq 0 ]
       
   134 then
       
   135   echo " all_tours from every position on the board" | tee -a $out
       
   136   echo " dim = 1: 1" | tee -a $out
       
   137   echo "       2: 0,0,0,0" | tee -a $out
       
   138   echo "       3: 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
       
   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)
       
   142   
       
   143   if (scala_assert "knight1.scala" "knight1_test3a.scala") 
       
   144   then
       
   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
       
   149      marks=$(( marks + 1 ))
       
   150   else
       
   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
       
   155   fi
       
   156 fi
       
   157 
       
   158 if [ $tsts1 -eq 0 ]
       
   159 then
       
   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)
       
   163   
       
   164   if (scala_assert "knight1.scala" "knight1_test3b.scala") 
       
   165   then
       
   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
       
   170      marks=$(( marks + 1 ))
       
   171   else
       
   172      END=$(date +%s)
       
   173      DIFF=$(( $END - $START ))
       
   174      echo " It took $DIFF seconds" | tee -a $out 
       
   175      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
       
   176   fi
       
   177 fi
       
   178 
       
   179 
       
   180 ## final marks
       
   181 echo "Overall mark for Preliminary 8" | tee -a $out
       
   182 echo "$marks" | tee -a $out
       
   183 
       
   184