core_testing2/docdiff_test.sh
changeset 401 9471c3b7ea02
parent 376 6cc36d0ef79e
child 473 ac79c2e534bd
equal deleted inserted replaced
400:e48ea8300b2d 401:9471c3b7ea02
       
     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 "Below is the feedback for your submission docdiff.scala" >> $out
       
    12 echo "" >> $out
       
    13 
       
    14 
       
    15 # compilation tests
       
    16 
       
    17 function scala_compile {
       
    18   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
       
    19 }
       
    20 
       
    21 # functional tests
       
    22 
       
    23 function scala_assert {
       
    24   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
       
    25 }
       
    26 
       
    27 # purity test
       
    28 
       
    29 function scala_vars {
       
    30    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
       
    31 }
       
    32 
       
    33 
       
    34 
       
    35 ### compilation test
       
    36 
       
    37 echo -e "docdiff.scala runs?" >> $out
       
    38 
       
    39 if (scala_compile docdiff.scala)
       
    40 then
       
    41     echo -e "  --> passed" >> $out
       
    42     tsts=$(( 0 ))
       
    43 else
       
    44     echo -e "  --> SCALA DID NOT RUN docdiff.scala\n" >> $out
       
    45     tsts=$(( 1 )) 
       
    46 fi
       
    47 
       
    48 
       
    49 # var, .par return, ListBuffer test
       
    50 #
       
    51 echo -e "docdiff.scala does not contain vars, returns etc?" >> $out
       
    52 
       
    53 if  [ $tsts -eq 0 ]
       
    54 then 
       
    55    if (scala_vars docdiff.scala)
       
    56    then
       
    57       echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" >> $out
       
    58       tsts=$(( 1 ))
       
    59    else
       
    60       echo -e "  --> passed" >> $out
       
    61       tsts=$(( 0 )) 
       
    62    fi
       
    63 fi
       
    64 
       
    65 ### docdiff clean tests
       
    66 
       
    67 if [ $tsts -eq 0 ]
       
    68 then
       
    69   echo -e "docdiff.scala tests:" >> $out
       
    70   echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" >> $out
       
    71   echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" >> $out
       
    72 
       
    73   if (scala_assert "docdiff.scala" "docdiff_test1.scala")
       
    74   then
       
    75     echo -e "  --> success\n" >> $out
       
    76   else
       
    77     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
    78   fi
       
    79 fi
       
    80 
       
    81 ### docdiff occurrences tests
       
    82 
       
    83 if [ $tsts -eq 0 ]
       
    84 then
       
    85   echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " >> $out
       
    86   echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" >> $out
       
    87   echo -e "  " >> $out
       
    88   echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " >> $out
       
    89   echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" >> $out
       
    90 
       
    91   if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
       
    92   then
       
    93     echo -e "  --> success\n" >> $out
       
    94   else
       
    95     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
    96   fi
       
    97 fi
       
    98 
       
    99 ### docdiff prod tests
       
   100 
       
   101 if [ $tsts -eq 0 ]
       
   102 then
       
   103   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
       
   104   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
       
   105   echo -e "  " >> $out
       
   106   echo -e "  prod(l1, l2) == 7 " >> $out
       
   107   echo -e "  prod(l1, l1) == 7 " >> $out
       
   108   echo -e "  prod(l2, l2) == 13 " >> $out
       
   109 
       
   110   if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
       
   111   then
       
   112     echo -e "  --> success\n" >> $out
       
   113   else
       
   114     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   115   fi
       
   116 fi
       
   117 
       
   118 ### docdiff overlap tests
       
   119 
       
   120 if [ $tsts -eq 0 ]
       
   121 then
       
   122   echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" >> $out
       
   123   echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" >> $out
       
   124   echo -e "  " >> $out
       
   125   echo -e "  overlap(l1, l2) == 0.5384615384615384 " >> $out
       
   126   echo -e "  overlap(l1, l1) == 1.0 " >> $out
       
   127   echo -e "  overlap(l2, l2) == 1.0 " >> $out
       
   128 
       
   129   if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
       
   130   then
       
   131     echo -e "  --> success\n" >> $out
       
   132   else
       
   133     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   134   fi
       
   135 fi