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