pre_marking4/knight1_test.sh
changeset 421 864107857d27
parent 420 a6db2b70abdd
child 422 be20e7f67f76
equal deleted inserted replaced
420:a6db2b70abdd 421:864107857d27
     1 #!/bin/zsh
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 out=${1:-output}
       
     7 
       
     8 echo "" > $out
       
     9 
       
    10 echo `date` >> $out
       
    11 echo -e "" >> $out
       
    12 echo -e "Below is the feedback and provisional marks for your submission" >> $out
       
    13 echo -e "of the Preliminary Part of Part 4 (Scala).  Please note all marks are provisional until" >> $out
       
    14 echo -e "ratified by the assessment board -- this is not an official" >> $out
       
    15 echo -e "results transcript." >> $out
       
    16 echo -e "" >> $out
       
    17 
       
    18 echo -e "" >> $out
       
    19 echo -e "Below is the feedback for your submission knight1.scala" >> $out
       
    20 echo -e "" >> $out
       
    21 
       
    22 
       
    23 
       
    24 # marks for CW8 part 1
       
    25 marks=$(( 0.0 ))
       
    26 
       
    27 # compilation tests
       
    28 
       
    29 function scala_compile {
       
    30   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    31 }
       
    32 
       
    33 # functional tests
       
    34 
       
    35 function scala_assert {
       
    36   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    37 }
       
    38 
       
    39 function scala_assert_slow {
       
    40   (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
       
    41 }
       
    42 
       
    43 function scala_assert_thirty {
       
    44   (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)  
       
    45 }
       
    46 
       
    47 function scala_assert_quick {
       
    48   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)    
       
    49 }
       
    50 
       
    51 function scala_assert_long {
       
    52   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)    
       
    53 }
       
    54 
       
    55 function scala_assert_elong {
       
    56   (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) 
       
    57 }
       
    58 
       
    59 # purity test
       
    60 
       
    61 
       
    62 function scala_vars {
       
    63    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    64 }
       
    65 
       
    66 
       
    67 # compilation test
       
    68 
       
    69 echo -e "knight1.scala runs?" | tee -a $out
       
    70 
       
    71 if (scala_compile knight1.scala)
       
    72 then
       
    73     echo -e "  --> success " | tee -a $out
       
    74     tsts=$(( 0 ))
       
    75 else
       
    76     echo -e "  --> SCALA DID NOT RUN KNIGHT1.SCALA\n" | tee -a $out
       
    77     tsts=$(( 1 )) 
       
    78 fi
       
    79 
       
    80 
       
    81 # knights1: purity test
       
    82 if  [ $tsts -eq 0 ]
       
    83   then   
       
    84   echo -e "knight1.scala does not contain VARS, RETURNS etc?" | tee -a $out
       
    85 
       
    86   if (scala_vars knight1.scala)
       
    87   then
       
    88      echo -e "  --> FAIL\n" | tee -a $out
       
    89      tsts=$(( 1 ))
       
    90   else
       
    91      echo -e "  --> success" | tee -a $out
       
    92      tsts=$(( 0 )) 
       
    93   fi
       
    94 else
       
    95   tsts=$(( 1 ))  
       
    96 fi
       
    97 
       
    98 echo >> $out
       
    99 
       
   100 ### knight1 test
       
   101 
       
   102 if [ $tsts -eq 0 ]
       
   103 then
       
   104     echo " is_legal(8, Nil, (3, 4)) == true " | tee -a $out
       
   105     echo " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " | tee -a $out
       
   106     echo " is_legal(2, Nil, (0, 0)) == true" | tee -a $out                          
       
   107 
       
   108     if (scala_assert "knight1.scala" "knight1_test1.scala")
       
   109     then
       
   110         echo -e "  --> success" | tee -a $out
       
   111 	marks=$(( marks + 1.0 ))
       
   112     else
       
   113         echo -e "  --> \n ONE TEST FAILED\n"| tee -a $out
       
   114     fi
       
   115 fi
       
   116 
       
   117 ### knight2 test
       
   118 
       
   119 if [ $tsts -eq 0 ]
       
   120 then
       
   121   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
       
   122   echo " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" | tee -a $out
       
   123   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
       
   124   echo " legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0))" | tee -a $out
       
   125   echo " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" | tee -a $out
       
   126   echo " legal_moves(1, Nil, (0,0)) == Nil" | tee -a $out
       
   127   echo " legal_moves(2, Nil, (0,0)) == Nil" | tee -a $out
       
   128   echo " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" | tee -a $out
       
   129   
       
   130   if (scala_assert "knight1.scala" "knight1_test2.scala")
       
   131   then
       
   132      echo -e "  --> success\n" | tee -a $out
       
   133      marks=$(( marks + 1 ))
       
   134   else
       
   135      echo -e "  --> ONE TEST FAILED\n" | tee -a $out
       
   136   fi
       
   137 fi
       
   138 
       
   139 
       
   140 ### knight3 test
       
   141 
       
   142 if [ $tsts -eq 0 ]
       
   143 then
       
   144   echo " count_tours from every position on the board 1 - 4 (0.5% marks)" | tee -a $out
       
   145   echo " dim = 1: 1" | tee -a $out
       
   146   echo "       2: 0,0,0,0" | tee -a $out
       
   147   echo "       3: 0,0,0,0,0,0,0,0,0" | tee -a $out
       
   148   echo "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out
       
   149   START=$(date +%s)
       
   150   
       
   151   if (scala_assert_thirty "knight1.scala" "knight1_test3a.scala") 
       
   152   then
       
   153      END=$(date +%s)
       
   154      DIFF=$(( $END - $START ))
       
   155      #echo " This test ran for $DIFF seconds." | tee -a $out  
       
   156      echo -e "  --> success\n" | tee -a $out
       
   157      marks=$(( marks + 0.5 ))
       
   158   else
       
   159      END=$(date +%s)
       
   160      DIFF=$(( $END - $START ))
       
   161      echo " This test ran for $DIFF seconds." | tee -a $out 
       
   162      echo -e "  --> ONE TEST FAILED\n" | tee -a $out
       
   163   fi
       
   164 fi
       
   165 
       
   166 
       
   167 
       
   168 if [ $tsts -eq 0 ]
       
   169 then
       
   170   echo " count_tours from every position on the board of dim 5 for the first 3 rows (0.5% marks)" | tee -a $out
       
   171   echo " dim = 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56)" | tee -a $out
       
   172   START=$(date +%s)
       
   173   
       
   174   if (scala_assert_thirty "knight1.scala" "knight1_test3b.scala") 
       
   175   then
       
   176      END=$(date +%s)
       
   177      DIFF=$(( $END - $START ))
       
   178      #echo " This test ran for $DIFF seconds." | tee -a $out  
       
   179      echo -e "  --> success\n" | tee -a $out
       
   180      marks=$(( marks + 0.5 ))
       
   181   else
       
   182      END=$(date +%s)
       
   183      DIFF=$(( $END - $START ))
       
   184      echo " This test ran for $DIFF seconds." | tee -a $out 
       
   185      echo -e "  --> ONE TEST FAILED\n" | tee -a $out
       
   186   fi
       
   187 fi
       
   188 
       
   189 
       
   190 
       
   191 if [ $tsts -eq 0 ]
       
   192 then
       
   193   echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out
       
   194   echo " enum_tours(5, List((0,0)) ) => 304 tours? and all correct?" | tee -a $out
       
   195   START=$(date +%s)
       
   196   
       
   197   if (scala_assert_thirty "knight1.scala" "knight1_test3c.scala") 
       
   198   then
       
   199      END=$(date +%s)
       
   200      DIFF=$(( $END - $START ))
       
   201      #echo " This test ran for $DIFF seconds." | tee -a $out 
       
   202      echo -e "  --> success\n" | tee -a $out
       
   203      marks=$(( marks + 1.0 ))
       
   204   else
       
   205      END=$(date +%s)
       
   206      DIFF=$(( $END - $START ))
       
   207      echo " This test ran for $DIFF seconds." | tee -a $out 
       
   208      echo -e "  --> \n ONE TEST FAILED\n" | tee -a $out
       
   209   fi
       
   210 fi
       
   211 
       
   212 
       
   213 ## final marks
       
   214 echo -e "Overall mark for the Preliminary Part 4 (Scala)" | tee -a $out
       
   215 printf " %0.1f\n" $marks | tee -a $out
       
   216 
       
   217 
       
   218