#!/bin/bash# try this to make it fail safelyset -eu -o pipefail -posix#set -eout=${1:-output}echo "" > $outecho "Below is the feedback and provisional mark for your submission" >> $outecho "for assignment 6. Please note all marks are provisional until" >> $outecho "ratified by the assessment board -- this is not an official" >> $outecho "results transcript." >> $outecho "" >> $out#alarm() { perl -e 'alarm shift; exec @ARGV' "$@"; }#alarm 20 foo arg1# compilation testsfunction scala_compile { (scala "$1" 2> /dev/null 1> /dev/null) }# functional testsfunction scala_assert { (scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)}# marks for CW1 parts 1 + 2marks=$(( 0 ))# compilation testecho "collatz.scala runs?" | tee -a $outif (scala_compile collatz.scala)then echo " --> success" | tee -a $out tsts=$(( 0 ))else echo " --> scala did not run collatz.scala" | tee -a $out tsts=$(( 1 )) fi### collatz testsif [ $tsts -eq 0 ]then echo " collatz(1) == 1" | tee -a $out echo " collatz(2) == 2" | tee -a $out echo " collatz(9) == 20" | tee -a $out echo " collatz(9000) == 48" | tee -a $out if (scala_assert "collatz.scala" "../collatz_test1.scala") then echo " --> success" | tee -a $out marks=$(( marks + 2 )) else echo " --> one of the tests failed" | tee -a $out fifi### collatz max testsif [ $tsts -eq 0 ]then echo " collatz_max(2) == (2, 2)" | tee -a $out echo " collatz_max(77000) == (340, 52527)" | tee -a $out if (scala_assert "collatz.scala" "../collatz_test2.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) else echo " --> one of the tests failed" | tee -a $out fifi# compilation testecho "trade.scala runs?" | tee -a $outif (scala_compile trade.scala)then echo " --> success" | tee -a $out tsts=$(( 0 ))else echo " --> scala did not run trade.scala" | tee -a $out tsts=$(( 1 ))fi### trade times testsif [ $tsts -eq 0 ]then echo " trade_times(List(3.0, 7.0, 2.0, 4.0)) == (2, 3)" | tee -a $out echo " trade_times(List(28.0, 18.0, 20.0, 26.0, 24.0)) == (1, 3)" | tee -a $out if (scala_assert "trade.scala" "../trade_test1.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) else echo " --> one of the tests failed" | tee -a $out fifiif [ $tsts -eq 0 ]then echo " get_page(\"GOOG\").length >= 3088" | tee -a $out echo " get_page(\"AAPL\").length >= 9065" | tee -a $out echo " get_page(\"FB\").length >= 1136" | tee -a $out if (scala_assert "trade.scala" "../trade_test2.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) else echo " --> one of the tests failed" | tee -a $out fifiif [ $tsts -eq 0 ]then echo " get_page(\"IBM\").last or head == \"1962-01-02,578.499985,578.499985,571.999991,571.999991,387200,2.260487\")" | tee -a $out echo " process_page(\"IBM\").length == get_page(\"IBM\").length - 1" | tee -a $out if (scala_assert "trade.scala" "../trade_test3.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) else echo " --> one of the tests failed" | tee -a $out fifiif [ $tsts -eq 0 ]then echo " query_company(\"YHOO\") == (\"1996-07-24\", \"2000-01-03\")" | tee -a $out echo " query_company(\"IBM\") == (\"1962-06-14\", \"2013-03-14\")" | tee -a $out echo " query_company(\"BIDU\") == (\"2006-02-07\", \"2014-11-11\")" | tee -a $out if (scala_assert "trade.scala" "../trade_test4.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) else echo " --> one of the tests failed" | tee -a $out fifi## final marksecho "Overall mark for Parts 1 and 2:" | tee -a $outecho "$marks" | tee -a $out