main_testing2/wordle_test.sh
changeset 435 fda7c39f3b6a
child 436 db3300b47725
equal deleted inserted replaced
434:8c5804b2f9d2 435:fda7c39f3b6a
       
     1 #!/bin/zsh
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo -e "" > $out
       
    10 
       
    11 echo "The feedback for your submission for wordle.scala" >> $out
       
    12 echo "" >> $out
       
    13 
       
    14 # marks for main part 2
       
    15 
       
    16 # compilation tests
       
    17 
       
    18 function scala_compile {
       
    19   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    20 }
       
    21 
       
    22 # functional tests
       
    23 
       
    24 function scala_assert {
       
    25   (ulimit -t 35; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    26 }
       
    27  
       
    28 # purity test
       
    29 function scala_vars {
       
    30    (sed 's/immutable/ok/g' c$out > cb$out;
       
    31     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
       
    32 }
       
    33 
       
    34 
       
    35 ### compilation test
       
    36 
       
    37 echo -e "wordle.scala runs?" >> $out
       
    38 
       
    39 if (scala_compile wordle.scala)
       
    40 then
       
    41     echo -e "  --> success" >> $out
       
    42     tsts0=$(( 0 ))
       
    43 else
       
    44     echo -e "  --> SCALA DID NOT RUN wordle.scala\n" >> $out
       
    45     tsts0=$(( 1 )) 
       
    46 fi
       
    47 
       
    48 # var, .par return, ListBuffer test
       
    49 #
       
    50 
       
    51 if  [ $tsts0 -eq 0 ]
       
    52 then
       
    53    echo -e "wordle.scala does not contain VARS, RETURNS etc?" >> $out
       
    54     
       
    55    if (scala_vars wordle.scala)
       
    56    then
       
    57       echo -e "  --> test failed\n" >> $out
       
    58       tsts=$(( 1 ))
       
    59    else
       
    60       echo -e "  --> success" >> $out
       
    61       tsts=$(( 0 )) 
       
    62    fi
       
    63 else
       
    64    tsts=$(( 1 ))  
       
    65 fi    
       
    66 
       
    67 
       
    68 echo >> $out
       
    69 
       
    70 ### wordle tests: Task 1 (0.25%)
       
    71 
       
    72 if [ $tsts -eq 0 ]
       
    73 then
       
    74   echo "Task 1:"  >> $out
       
    75   echo "  val wordle_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/wordle.txt\"\"\""     >> $out
       
    76   echo "  val secrets = get_wordle_list(wordle_url)"     >> $out
       
    77   echo "  secrets.length == 12972"    >> $out
       
    78   echo "  secrets.filter(_.length != 5) == Nil" >> $out
       
    79   echo "  get_wordle_list(wordle_url ++ \"2\") == Nil" >> $out
       
    80   
       
    81 
       
    82   if (scala_assert "wordle.scala" "wordle_test1.scala")
       
    83   then
       
    84       echo -e "  --> success\n" >> $out
       
    85   else
       
    86       echo -e "  --> one of the tests failed\n" >> $out
       
    87   fi
       
    88 fi
       
    89 
       
    90 ### wordle tests: Task 2 (0.25%)
       
    91 
       
    92 if [ $tsts -eq 0 ]
       
    93 then
       
    94   echo "Task 2:"  >> $out  
       
    95   echo "  removeOne(List(1,2,3,2,1), 3) == List(1, 2, 2, 1)" >> $out
       
    96   echo "  removeOne(List(1,2,3,2,1), 2) == List(1, 3, 2, 1)" >> $out
       
    97   echo "  removeOne(List(1,2,3,2,1), 1) == List(2, 3, 2, 1)" >> $out
       
    98   echo "  removeOne(List(1,2,3,2,1), 0) == List(1, 2, 3, 2, 1)" >> $out
       
    99   echo "  removeOne(List(\"a\", \"b\", \"b\"), \"b\") == List(\"a\", \"b\")" >> $out
       
   100 
       
   101   if (scala_assert "wordle.scala" "wordle_test2.scala")
       
   102   then
       
   103       echo -e "  --> success\n" >> $out
       
   104   else
       
   105       echo -e "  --> one of the tests failed\n" >> $out
       
   106   fi
       
   107 fi
       
   108 
       
   109 ### wordle tests: Task 3 (1.5%)
       
   110 
       
   111 
       
   112 if [ $tsts -eq 0 ]
       
   113 then
       
   114   echo "Task 3:"  >> $out    
       
   115   echo "  pool(\"chess\", \"caves\").toSet == Set('h', 'e', 's')" >> $out
       
   116   echo "  pool(\"chess\", \"swiss\").toSet == Set('c', 'h', 'e')" >> $out
       
   117 
       
   118   if (scala_assert "wordle.scala" "wordle_test3a.scala") 
       
   119   then
       
   120       echo -e "  --> success\n" >> $out
       
   121   else
       
   122     echo -e "  --> one of the tests failed\n" >> $out
       
   123   fi
       
   124 fi
       
   125 
       
   126 if [ $tsts -eq 0 ]
       
   127 then    
       
   128   echo "  score(\"chess\", \"caves\") == List(C, A, A, P, C)" >> $out
       
   129   echo "  score(\"doses\", \"slide\") == List(P, A, A, P, P)" >> $out
       
   130   echo "  score(\"chess\", \"swiss\") == List(A, A, A, C, C)" >> $out
       
   131   echo "  score(\"chess\", \"eexss\") == List(P, A, A, C, C)" >> $out
       
   132   echo "" >> $out
       
   133   echo "  val p = pool(\"chess\", \"caves\")"     >> $out
       
   134   echo "  aux(\"chess\".toList, \"caves\".toList, Nil) == List(P, A, A, A, C)" >> $out
       
   135   echo "  aux(\"chess\".toList, \"caves\".toList, p)   == List(P, A, A, P, C)" >> $out
       
   136 
       
   137   if (scala_assert "wordle.scala" "wordle_test3b.scala") 
       
   138   then
       
   139       echo -e "  --> success\n" >> $out
       
   140   else
       
   141     echo -e "  --> one of the tests failed\n" >> $out
       
   142   fi
       
   143 fi
       
   144 
       
   145 ### wordle tests: Task 4 (0.5%)
       
   146 
       
   147 if [ $tsts -eq 0 ]
       
   148 then
       
   149   echo "Task 4:"  >> $out  
       
   150   echo "  iscore(\"chess\", \"caves\") == 21" >> $out
       
   151   echo "  iscore(\"chess\", \"swiss\") == 20" >> $out
       
   152  
       
   153 
       
   154   if (scala_assert "wordle.scala" "wordle_test4.scala")
       
   155   then
       
   156       echo -e "  --> success\n" >> $out
       
   157   else
       
   158       echo -e "  --> one of the tests failed\n" >> $out
       
   159   fi
       
   160 fi
       
   161 
       
   162 ### wordle tests: Task 5 (1.5%)
       
   163 
       
   164 if [ $tsts -eq 0 ]
       
   165 then
       
   166   echo "Task 5:"  >> $out  
       
   167   echo "  val secrets = ..." >> $out
       
   168   echo "  evil(secrets, \"stent\").length == 1907" >> $out
       
   169   echo "  evil(secrets, \"hexes\").length == 2966" >> $out
       
   170   echo "  evil(secrets, \"horse\").length == 1203" >> $out
       
   171   echo "  evil(secrets, \"hoise\").length == 901" >> $out
       
   172   echo "  evil(secrets, \"house\").length == 1228" >> $out
       
   173 
       
   174   if (scala_assert "wordle.scala" "wordle_test5.scala")
       
   175   then
       
   176       echo -e "  --> success\n" >> $out
       
   177   else
       
   178       echo -e "  --> one of the tests failed\n" >> $out
       
   179   fi
       
   180 fi
       
   181 
       
   182 ### wordle tests: Task 6 (1.0%)
       
   183 
       
   184 if [ $tsts -eq 0 ]
       
   185 then
       
   186   echo "Task 6:"  >> $out  
       
   187   echo "  val secrets = ..." >> $out
       
   188   echo "  frequencies(secrets)('y') == 0.9680234350909651" >> $out
       
   189   echo "  frequencies(secrets)('e') == 0.897286463151403"  >> $out
       
   190   echo "  frequencies(secrets)('z') == 0.9933086648165279" >> $out
       
   191 
       
   192   if (scala_assert "wordle.scala" "wordle_test6.scala")
       
   193   then
       
   194       echo -e "  --> success\n" >> $out
       
   195   else
       
   196       echo -e "  --> one of the tests failed\n" >> $out
       
   197   fi
       
   198 fi
       
   199 
       
   200 ### wordle tests: Task 7 (1.0%)
       
   201 
       
   202 if [ $tsts -eq 0 ]
       
   203 then
       
   204   echo "Task 7:"  >> $out  
       
   205   echo "  val secrets = ..." >> $out
       
   206   echo "  ranked_evil(secrets, \"beats\") == List(\"orlon\") || ... == List(\"fuzzy\")" >> $out
       
   207   echo "  ranked_evil(secrets, \"vitae\") == List(\"sools\", \"solos\") || ... == List(\"fuzzy\")" >> $out
       
   208   echo "  ranked_evil(secrets, \"bento\") == List(\"assai\") || ... == List(\"fuzzy\")" >> $out
       
   209   echo "  ranked_evil(secrets, \"belts\") == List(\"anana\") || ... == List(\"fuzzy\")" >> $out
       
   210   
       
   211   if (scala_assert "wordle.scala" "wordle_test7.scala")
       
   212   then
       
   213       echo -e "  --> success\n" >> $out
       
   214   else
       
   215       echo -e "  --> one of the tests failed\n" >> $out
       
   216   fi
       
   217 fi
       
   218 
       
   219 
       
   220 
       
   221