pre_testing4/knight_test.sh
changeset 412 98a5964d49d1
parent 411 f55742af79ef
child 413 9c80f411faa7
equal deleted inserted replaced
411:f55742af79ef 412:98a5964d49d1
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 out=${1:-output}
       
     5 
       
     6 echo -e "" > $out
       
     7 
       
     8 echo -e "Below is the feedback for your submission of knight1.scala" >> $out
       
     9 echo -e "" >> $out
       
    10 #echo -e "!! Important: !!" >> $out
       
    11 #echo -e "Because of limitations with our testing infrastructure, we can only" >> $out
       
    12 #echo -e "let code run for 10 seconds and then have to kill it. This might" >> $out
       
    13 #echo -e "mean your code is correct, but still marked as Fail. Remember" >> $out
       
    14 #echo -e "you can test your code on your own machine and benchmark it" >> $out
       
    15 #echo -e "against the reference implementation." >> $out
       
    16 #echo -e "" >> $out
       
    17 
       
    18 # compilation tests
       
    19 
       
    20 function scala_compile {
       
    21   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    22 }
       
    23 
       
    24 # functional tests
       
    25 
       
    26 function scala_assert {
       
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    28 }
       
    29 
       
    30 # purity test
       
    31 
       
    32 function scala_vars {
       
    33    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    34 }
       
    35 
       
    36 
       
    37 # compilation test
       
    38 
       
    39 echo -e "knight1.scala runs?" >> $out
       
    40 
       
    41 if (scala_compile knight1.scala)
       
    42 then
       
    43     echo -e "  --> passed" >> $out
       
    44     tsts=$(( 0 ))
       
    45 else
       
    46     echo -e "  --> SCALA DID NOT RUN knight1.scala\n" >> $out
       
    47     tsts=$(( 1 )) 
       
    48 fi
       
    49 
       
    50 
       
    51 # knights1: purity test
       
    52 
       
    53 echo -e "knight1.scala does not contain vars, returns etc?" >> $out
       
    54 
       
    55 if  [ $tsts -eq 0 ]
       
    56 then
       
    57     if (scala_vars knight1.scala)
       
    58     then
       
    59 	echo -e "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
       
    60 	tsts=$(( 1 ))
       
    61     else
       
    62 	echo -e "  --> passed" >> $out
       
    63 	tsts=$(( 0 )) 
       
    64     fi
       
    65 fi
       
    66 
       
    67 
       
    68 
       
    69 ### knight1 test
       
    70 
       
    71 if [ $tsts -eq 0 ]
       
    72 then
       
    73     #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
    74     echo -e " is_legal(8, Nil, (3, 4)) == true " >> $out
       
    75     echo -e " is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false " >> $out
       
    76     echo -e " is_legal(2, Nil, (0, 0)) == true" >> $out                          
       
    77 
       
    78     if (scala_assert "knight1.scala" "knight_test1.scala")
       
    79     then
       
    80         echo -e "  --> success" >> $out
       
    81     else
       
    82         echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    83     fi
       
    84 fi
       
    85 
       
    86 ### knight2 test
       
    87 
       
    88 if [ $tsts -eq 0 ]
       
    89 then
       
    90   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
    91   echo -e " legal_moves(8, Nil, (2,2)) == List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))" >> $out
       
    92   echo -e " legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))" >> $out
       
    93   echo -e " legal_moves(8, List((4,1), (1,0)), (2,2)) == List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))" >> $out
       
    94   echo -e " legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))" >> $out
       
    95   echo -e " legal_moves(1, Nil, (0,0)) == Nil" >> $out
       
    96   echo -e " legal_moves(2, Nil, (0,0)) == Nil" >> $out
       
    97   echo -e " legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))" >> $out
       
    98   
       
    99   if (scala_assert "knight1.scala" "knight_test2.scala")
       
   100   then
       
   101     echo -e "  --> success" >> $out
       
   102   else
       
   103     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   104   fi
       
   105 fi
       
   106 
       
   107 
       
   108 ### knight3 test
       
   109 
       
   110 if [ $tsts -eq 0 ]
       
   111 then
       
   112   #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   113   echo -e " count_tours from every position on the board" >> $out
       
   114   echo -e " dim = 1: 1" >> $out
       
   115   echo -e "       2: 0,0,0,0" >>  $out
       
   116   echo -e "       3: 0,0,0,0,0,0,0,0,0" >>  $out
       
   117   echo -e "       4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" >> $out
       
   118   #echo -e "       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" >> $out
       
   119   echo -e " enum_tours(5, List((0,0)) ) == 304 and all correct?" >> $out
       
   120   echo -e " enum_tours(5, List((0,1)) ) == 0" >> $out
       
   121   echo -e " enum_tours(5, List((0,2)) ) == 56 and all correct?" >> $out
       
   122   
       
   123   if (scala_assert "knight1.scala" "knight_test3.scala") 
       
   124   then
       
   125     echo -e "  --> success" >> $out
       
   126   else
       
   127     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   128   fi
       
   129 fi
       
   130 
       
   131 ### knight4 test
       
   132 
       
   133 #if [ $tsts -eq 0 ]
       
   134 #then
       
   135 #  #echo -e "For testing needs to take 10 seconds or less to execute: " >> $out
       
   136 #  echo -e " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " >> $out
       
   137 #  echo -e "   first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))" >> $out
       
   138 #  echo -e "   first(List((1,0),(2,0),(3,0)), f) == None" >> $out
       
   139 #
       
   140 #  if (scala_assert "knight1.scala" "knight_test4.scala") 
       
   141 #  then
       
   142 #    echo -e "  --> success" >> $out
       
   143 #  else
       
   144 #    echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
   145 #  fi
       
   146 #fi
       
   147 
       
   148