testing3/knight2_test.sh
changeset 296 12dc251fc47e
parent 295 3f34da7a3094
child 297 eab44dbee855
equal deleted inserted replaced
295:3f34da7a3094 296:12dc251fc47e
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo "" > $out
       
    10 
       
    11 echo -e "Below is the feedback for your submission of CW 8, Core Part." >> $out
       
    12 echo -e "" >> $out
       
    13 
       
    14 
       
    15 
       
    16 # compilation tests
       
    17 
       
    18 function scala_compile {
       
    19   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) 
       
    20 }
       
    21 
       
    22 # functional tests
       
    23 
       
    24 function scala_assert_slow {
       
    25   (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -i "$1" "-- $2" 2> /dev/null 1> /dev/null)
       
    26 }
       
    27 
       
    28 function scala_assert_thirty {
       
    29   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
       
    30 }
       
    31 
       
    32 function scala_assert_quick {
       
    33   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2"  2> /dev/null 1> /dev/null)
       
    34 }
       
    35 
       
    36 
       
    37 # purity test
       
    38 
       
    39 function scala_vars {
       
    40    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    41 }
       
    42 
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 
       
    48 
       
    49 
       
    50 # knights2: purity test
       
    51 #
       
    52 echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
       
    53 
       
    54 
       
    55 if (scala_vars knight2.scala)
       
    56 then
       
    57   echo -e "  --> fail (make triple-sure your program conforms to the required format)" >> $out    
       
    58   tsts0=$(( 0 ))
       
    59 else
       
    60   echo -e "  --> success" >> $out
       
    61   tsts0=$(( 0 )) 
       
    62 fi
       
    63 
       
    64 
       
    65 # compilation test
       
    66 if  [ $tsts0 -eq 0 ]
       
    67 then    
       
    68   echo -e "knight2.scala runs?" >> $out
       
    69 
       
    70   if (scala_compile knight2.scala)
       
    71   then
       
    72     echo -e "  --> success" >> $out
       
    73     tsts1=$(( 0 ))
       
    74   else
       
    75     echo -e "  --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out  
       
    76     tsts1=$(( 1 )) 
       
    77   fi
       
    78 else
       
    79   tsts1=$(( 1 ))     
       
    80 fi
       
    81 
       
    82 # ordered move test
       
    83 
       
    84 if [ $tsts1 -eq 0 ]
       
    85 then
       
    86   echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out
       
    87   echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out
       
    88   echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out
       
    89   
       
    90   if (scala_assert "knight2.scala" "knight_test6.scala")
       
    91   then
       
    92       echo -e "  --> success" >> $out
       
    93   else
       
    94       echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
    95   fi
       
    96 fi
       
    97 
       
    98 
       
    99 # first-closed-tour test
       
   100 
       
   101 if [ $tsts1 -eq 0 ]
       
   102 then
       
   103   echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" >> $out
       
   104   
       
   105   if (scala_assert "knight2.scala" "knight_test7.scala")
       
   106   then
       
   107       echo -e "  --> success" >> $out
       
   108   else
       
   109       echo -e "  --> \n ONE TEST FAILED\n" >> $out  
       
   110   fi
       
   111 fi
       
   112 
       
   113 
       
   114 
       
   115 if [ $tsts1 -eq 0 ]
       
   116 then
       
   117   echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" >> $out
       
   118   echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" >> $out
       
   119   
       
   120   if (scala_assert "knight2.scala" "knight_test8.scala")
       
   121   then
       
   122       echo -e "  --> success" >> $out
       
   123   else
       
   124       echo -e "  --> \n ONE TEST FAILED\n" >> $out 
       
   125   fi
       
   126 fi
       
   127 
       
   128 
       
   129 # knights3: purity test
       
   130 #
       
   131 echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out
       
   132 
       
   133 
       
   134 if (scala_vars knight3.scala)
       
   135 then
       
   136   echo "  --> test failed" >> $out
       
   137   tsts0=$(( 0 ))
       
   138 else
       
   139   echo "  --> success" >> $out
       
   140   tsts0=$(( 0 )) 
       
   141 fi
       
   142 
       
   143 
       
   144 # compilation test
       
   145 if  [ $tsts0 -eq 0 ]
       
   146 then    
       
   147   echo "knight3.scala runs?" >> $out
       
   148 
       
   149   if (scala_compile knight3.scala)
       
   150   then
       
   151     echo "  --> success" >> $out
       
   152     tsts1=$(( 0 ))
       
   153   else
       
   154     echo -e "  --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $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?" >> $out
       
   165   
       
   166   if (scala_assert "knight3.scala" "knight_test9.scala")
       
   167   then
       
   168       echo -e "  --> success" >> $out
       
   169   else
       
   170       echo -e "  --> \n ONE TEST FAILED\n" >> $out 
       
   171   fi
       
   172 fi
       
   173