--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/collatz_test1.scala Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,9 @@
+
+assert(List(0,1).contains(collatz(1)))
+
+assert(collatz(2)==2)
+
+assert(collatz(9)==20)
+
+assert(collatz(9000)==48)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/collatz_test2.scala Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,5 @@
+//println("starting test now")
+
+assert(collatz_max(2)==(2,2))
+
+assert(collatz_max(77000)==(340,52527))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/mark Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,165 @@
+#!/bin/bash
+set -e
+
+out=${1:-output}
+
+echo "" > $out
+
+echo "Below is the feedback and provisional mark for your submission" >> $out
+echo "for assignment 6. Please note all marks are provisional until" >> $out
+echo "ratified by the assessment board -- this is not an official" >> $out
+echo "results transcript." >> $out
+echo "" >> $out
+
+
+#alarm() { perl -e 'alarm shift; exec @ARGV' "$@"; }
+#alarm 20 foo arg1
+
+# compilation tests
+
+function scala_compile {
+ (scala "$1" 2> /dev/null 1> /dev/null)
+}
+
+
+
+# functional tests
+
+function scala_assert {
+ (scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
+}
+
+
+# marks for CW1 parts 1 + 2
+marks=$(( 0 ))
+
+
+# compilation test
+echo "collatz.scala runs?" | tee -a $out
+
+if (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 tests
+
+if [ $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
+ fi
+fi
+
+### collatz max tests
+
+if [ $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
+ fi
+fi
+
+
+
+
+
+# compilation test
+
+echo "trade.scala runs?" | tee -a $out
+
+if (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 tests
+
+if [ $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
+ fi
+fi
+
+if [ $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
+ fi
+fi
+
+if [ $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
+ fi
+fi
+
+if [ $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
+ fi
+fi
+
+
+## final marks
+echo "Overall mark for Parts 1 and 2:" | tee -a $out
+echo "$marks" | tee -a $out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/mk Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,14 @@
+#!/bin/sh
+###set -e
+
+
+for sd in k*; do
+ cd $sd
+ echo $sd
+ ../mark
+ cd ..
+done
+
+
+#scala -i collatz.scala -e "println(\"test\")"
+#
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/trade_test1.scala Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,6 @@
+//println("starting test now")
+
+assert(trade_times(List(3.0, 7.0, 2.0, 4.0)) == (2, 3))
+
+assert(trade_times(List(28.0, 18.0, 20.0, 26.0, 24.0)) == (1, 3))
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/trade_test2.scala Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,7 @@
+//println("starting test now")
+
+assert(get_page("GOOG").length >= 3087)
+assert(get_page("AAPL").length >= 9064)
+assert(get_page("FB").length >= 1135)
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/trade_test3.scala Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,8 @@
+//println("starting test now")
+
+val IBM = get_page("IBM")
+val str = "1962-01-02,578.499985,578.499985,571.999991,571.999991,387200,2.260487"
+
+assert(IBM.last == str || IBM.head == str)
+
+assert(process_page("IBM").length == IBM.length - 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/trade_test4.scala Mon Nov 21 19:23:37 2016 +0000
@@ -0,0 +1,6 @@
+//println("starting test now")
+
+
+assert(query_company("YHOO") == ("1996-07-24", "2000-01-03"))
+assert(query_company("IBM") == ("1962-06-14", "2013-03-14"))
+assert(query_company("BIDU") == ("2006-02-07", "2014-11-11"))
--- a/progs/collatz_sol.scala Fri Nov 18 18:47:50 2016 +0000
+++ b/progs/collatz_sol.scala Mon Nov 21 19:23:37 2016 +0000
@@ -36,7 +36,7 @@
// some testing harness
-val bnds = List(10, 100, 1000, 10000, 100000, 1000000)
+val bnds = List(2, 10, 100, 1000, 10000, 100000, 77000, 90000, 1000000)
for (bnd <- bnds) {
val (max, steps) = collatz_max(bnd)
--- a/progs/drumb_sol.scala Fri Nov 18 18:47:50 2016 +0000
+++ b/progs/drumb_sol.scala Mon Nov 21 19:23:37 2016 +0000
@@ -142,3 +142,28 @@
investment(List("FB"), 2011 to 2016, 100) // => 363
+val rs_p = get_prices(rstate_portfolio, 1978 to 2016)
+val bl_p = get_prices(blchip_portfolio, 1978 to 2016)
+
+val rs_d = get_deltas(rs_p)
+val bl_d = get_deltas(bl_p)
+
+rs_p(0)
+ <-
+rs_p(1)
+ <-
+rs_p(2)
+ <-
+rs_p(3)
+
+rs_d(0)
+rs_d(1)
+rs_d(2)
+
+yearly_yield(rs_d, 100, 0)
+yearly_yield(rs_d, 96, 1)
+yearly_yield(rs_d, 95, 2)
+yearly_yield(rs_d, 134, 3)
+yearly_yield(rs_d, 126, 4)
+yearly_yield(rs_d, 169, 5)
+
--- a/progs/knight2_sol.scala Fri Nov 18 18:47:50 2016 +0000
+++ b/progs/knight2_sol.scala Mon Nov 21 19:23:37 2016 +0000
@@ -48,3 +48,6 @@
println(s"${dim} x ${dim} " + (if (t == None) "" else { print_board(dim, t.get) ; "" }))
}
+
+
+