| 64 |      1 | #!/bin/bash
 | 
|  |      2 | set -e
 | 
|  |      3 | 
 | 
|  |      4 | out=${1:-output}
 | 
|  |      5 | 
 | 
|  |      6 | echo "" > $out
 | 
|  |      7 | 
 | 
|  |      8 | echo "Below is the feedback and provisional mark for your submission" >> $out
 | 
|  |      9 | echo "for assignment 6.  Please note all marks are provisional until" >> $out
 | 
|  |     10 | echo "ratified by the assessment board -- this is not an official" >> $out
 | 
|  |     11 | echo "results transcript." >> $out
 | 
|  |     12 | echo "" >> $out
 | 
|  |     13 | 
 | 
|  |     14 | 
 | 
|  |     15 | #alarm() { perl -e 'alarm shift; exec @ARGV' "$@"; }
 | 
|  |     16 | #alarm 20 foo arg1
 | 
|  |     17 | 
 | 
|  |     18 | # compilation tests
 | 
|  |     19 | 
 | 
|  |     20 | function scala_compile {
 | 
|  |     21 |   (scala "$1" 2> /dev/null 1> /dev/null) 
 | 
|  |     22 | }
 | 
|  |     23 | 
 | 
|  |     24 | 
 | 
|  |     25 | 
 | 
|  |     26 | # functional tests
 | 
|  |     27 | 
 | 
|  |     28 | function scala_assert {
 | 
|  |     29 |   (scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
 | 
|  |     30 | }
 | 
|  |     31 | 
 | 
|  |     32 | 
 | 
|  |     33 | # marks for CW1 parts 1 + 2
 | 
|  |     34 | marks=$(( 0 ))
 | 
|  |     35 | 
 | 
|  |     36 | 
 | 
|  |     37 | # compilation test
 | 
|  |     38 | echo "collatz.scala runs?" | tee -a $out
 | 
|  |     39 | 
 | 
|  |     40 | if (scala_compile collatz.scala)
 | 
|  |     41 | then
 | 
|  |     42 |   echo "  --> success" | tee -a $out
 | 
|  |     43 |   tsts=$(( 0 ))
 | 
|  |     44 | else
 | 
|  |     45 |   echo "  --> scala did not run collatz.scala" | tee -a $out
 | 
|  |     46 |   tsts=$(( 1 )) 
 | 
|  |     47 | fi
 | 
|  |     48 | 
 | 
|  |     49 | 
 | 
|  |     50 | ### collatz tests
 | 
|  |     51 | 
 | 
|  |     52 | if [ $tsts -eq 0 ]
 | 
|  |     53 | then
 | 
|  |     54 |   echo "  collatz(1) == 1" | tee -a $out
 | 
|  |     55 |   echo "  collatz(2) == 2" | tee -a $out
 | 
|  |     56 |   echo "  collatz(9) == 20" | tee -a $out
 | 
|  |     57 |   echo "  collatz(9000) == 48" | tee -a $out
 | 
|  |     58 | 
 | 
|  |     59 |   if (scala_assert "collatz.scala" "../collatz_test1.scala")
 | 
|  |     60 |   then
 | 
|  |     61 |     echo "  --> success" | tee -a $out
 | 
|  |     62 |     marks=$(( marks + 2 ))
 | 
|  |     63 |   else
 | 
|  |     64 |     echo "  --> one of the tests failed" | tee -a $out
 | 
|  |     65 |   fi
 | 
|  |     66 | fi
 | 
|  |     67 | 
 | 
|  |     68 | ### collatz max tests
 | 
|  |     69 | 
 | 
|  |     70 | if [ $tsts -eq 0 ]
 | 
|  |     71 | then
 | 
|  |     72 |   echo "  collatz_max(2) == (2, 2)" | tee -a $out
 | 
|  |     73 |   echo "  collatz_max(77000) == (340, 52527)" | tee -a $out
 | 
|  |     74 | 
 | 
|  |     75 |   if (scala_assert "collatz.scala" "../collatz_test2.scala") 
 | 
|  |     76 |   then
 | 
|  |     77 |     echo "  --> success" | tee -a $out
 | 
|  |     78 |     marks=$(( marks + 1 ))
 | 
|  |     79 |   else
 | 
|  |     80 |     echo "  --> one of the tests failed" | tee -a $out
 | 
|  |     81 |   fi
 | 
|  |     82 | fi
 | 
|  |     83 | 
 | 
|  |     84 | 
 | 
|  |     85 | 
 | 
|  |     86 | 
 | 
|  |     87 | 
 | 
|  |     88 | # compilation test
 | 
|  |     89 | 
 | 
|  |     90 | echo "trade.scala runs?" | tee -a $out
 | 
|  |     91 | 
 | 
|  |     92 | if (scala_compile trade.scala)
 | 
|  |     93 | then
 | 
|  |     94 |   echo "  --> success" | tee -a $out
 | 
|  |     95 |   tsts=$(( 0 ))
 | 
|  |     96 | else
 | 
|  |     97 |   echo "  --> scala did not run trade.scala" | tee -a $out
 | 
|  |     98 |   tsts=$(( 1 ))
 | 
|  |     99 | fi
 | 
|  |    100 | 
 | 
|  |    101 | 
 | 
|  |    102 | ### trade times tests
 | 
|  |    103 | 
 | 
|  |    104 | if [ $tsts -eq 0 ]
 | 
|  |    105 | then
 | 
|  |    106 |   echo "  trade_times(List(3.0, 7.0, 2.0, 4.0)) == (2, 3)" | tee -a $out
 | 
|  |    107 |   echo "  trade_times(List(28.0, 18.0, 20.0, 26.0, 24.0)) == (1, 3)" | tee -a $out
 | 
|  |    108 | 
 | 
|  |    109 |   if (scala_assert "trade.scala" "../trade_test1.scala") 
 | 
|  |    110 |   then
 | 
|  |    111 |     echo "  --> success" | tee -a $out
 | 
|  |    112 |     marks=$(( marks + 1 ))
 | 
|  |    113 |   else
 | 
|  |    114 |     echo "  --> one of the tests failed" | tee -a $out
 | 
|  |    115 |   fi
 | 
|  |    116 | fi
 | 
|  |    117 | 
 | 
|  |    118 | if [ $tsts -eq 0 ]
 | 
|  |    119 | then
 | 
|  |    120 |   echo "  get_page(\"GOOG\").length >= 3088" | tee -a $out
 | 
|  |    121 |   echo "  get_page(\"AAPL\").length >= 9065" | tee -a $out
 | 
|  |    122 |   echo "  get_page(\"FB\").length >= 1136" | tee -a $out
 | 
|  |    123 | 
 | 
|  |    124 |   if (scala_assert "trade.scala" "../trade_test2.scala") 
 | 
|  |    125 |   then
 | 
|  |    126 |     echo "  --> success" | tee -a $out
 | 
|  |    127 |     marks=$(( marks + 1 ))
 | 
|  |    128 |   else
 | 
|  |    129 |     echo "  --> one of the tests failed" | tee -a $out
 | 
|  |    130 |   fi
 | 
|  |    131 | fi
 | 
|  |    132 | 
 | 
|  |    133 | if [ $tsts -eq 0 ]
 | 
|  |    134 | then
 | 
|  |    135 |   echo "  get_page(\"IBM\").last or head == \"1962-01-02,578.499985,578.499985,571.999991,571.999991,387200,2.260487\")" | tee -a $out
 | 
|  |    136 |   echo "  process_page(\"IBM\").length == get_page(\"IBM\").length - 1" | tee -a $out
 | 
|  |    137 | 
 | 
|  |    138 |   if (scala_assert "trade.scala" "../trade_test3.scala") 
 | 
|  |    139 |   then
 | 
|  |    140 |     echo "  --> success" | tee -a $out
 | 
|  |    141 |     marks=$(( marks + 1 ))
 | 
|  |    142 |   else
 | 
|  |    143 |     echo "  --> one of the tests failed" | tee -a $out
 | 
|  |    144 |   fi
 | 
|  |    145 | fi
 | 
|  |    146 | 
 | 
|  |    147 | if [ $tsts -eq 0 ]
 | 
|  |    148 | then
 | 
|  |    149 |   echo "  query_company(\"YHOO\") == (\"1996-07-24\", \"2000-01-03\")" | tee -a $out
 | 
|  |    150 |   echo "  query_company(\"IBM\") == (\"1962-06-14\", \"2013-03-14\")" | tee -a $out
 | 
|  |    151 |   echo "  query_company(\"BIDU\") == (\"2006-02-07\", \"2014-11-11\")" | tee -a $out
 | 
|  |    152 | 
 | 
|  |    153 |  if (scala_assert "trade.scala" "../trade_test4.scala") 
 | 
|  |    154 |   then
 | 
|  |    155 |     echo "  --> success" | tee -a $out
 | 
|  |    156 |     marks=$(( marks + 1 ))
 | 
|  |    157 |   else
 | 
|  |    158 |     echo "  --> one of the tests failed" | tee -a $out
 | 
|  |    159 |   fi
 | 
|  |    160 | fi
 | 
|  |    161 | 
 | 
|  |    162 | 
 | 
|  |    163 | ## final marks
 | 
|  |    164 | echo "Overall mark for Parts 1 and 2:" | tee -a $out
 | 
|  |    165 | echo "$marks" | tee -a $out
 |