# HG changeset patch # User Christian Urban # Date 1516370948 0 # Node ID b37052895281c7b4922b790fdd49cd625e192a61 # Parent 03530cb87cd0f136a4f40437617b4e3acc6d4106 updated diff -r 03530cb87cd0 -r b37052895281 cws/cw01.pdf Binary file cws/cw01.pdf has changed diff -r 03530cb87cd0 -r b37052895281 cws/disclaimer.sty --- a/cws/disclaimer.sty Tue Jan 16 10:47:29 2018 +0000 +++ b/cws/disclaimer.sty Fri Jan 19 14:09:08 2018 +0000 @@ -17,7 +17,7 @@ \texttt{Array}s or \texttt{ListBuffer}s, for example. \item Do not use \texttt{return} in your code! It has a different - meaning in Scala, than in Java. + meaning in Scala than in Java. \item Do not use \texttt{var}! This declares a mutable variable. Only use \texttt{val}! diff -r 03530cb87cd0 -r b37052895281 marking/drumb_test1.scala --- a/marking/drumb_test1.scala Tue Jan 16 10:47:29 2018 +0000 +++ b/marking/drumb_test1.scala Fri Jan 19 14:09:08 2018 +0000 @@ -1,16 +1,6 @@ -//println("starting test now") -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - -lazy val f = Future { - assert(get_prices(List("BIDU"), 2004 to 2008) == List(List(None), List(None), - List(Some(6.35)), List(Some(12.241)), - List(Some(38.188)))) -} +assert(get_prices(List("BIDU"), 2004 to 2008) == List(List(None), List(None), + List(Some(6.35)), List(Some(12.241)), + List(Some(38.188)))) -Await.result(f, 180 second) - diff -r 03530cb87cd0 -r b37052895281 marking/drumb_test2.scala --- a/marking/drumb_test2.scala Tue Jan 16 10:47:29 2018 +0000 +++ b/marking/drumb_test2.scala Fri Jan 19 14:09:08 2018 +0000 @@ -1,9 +1,3 @@ -//println("starting test now") - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps val urban_prices = List(List(Some(71.539941), None), List(Some(76.974614), None), @@ -17,11 +11,5 @@ List(Some(0.09141762603007778), Some(2.119679764725104))) -lazy val f = Future { - //assert(get_deltas(urban_prices) == urban_deltas) - assert (get_deltas(get_prices(List("IBM", "BIDU"), 2004 to 2008)) == urban_deltas) -} +assert (get_deltas(get_prices(List("IBM", "BIDU"), 2004 to 2008)) == urban_deltas) - -Await.result(f, 180 second) - diff -r 03530cb87cd0 -r b37052895281 marking/drumb_test3.scala --- a/marking/drumb_test3.scala Tue Jan 16 10:47:29 2018 +0000 +++ b/marking/drumb_test3.scala Fri Jan 19 14:09:08 2018 +0000 @@ -1,9 +1,3 @@ -//println("starting test now") - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps val test_data = List(List(Some(71.539941), None), List(Some(76.974614), None), List(Some(65.226685), Some(6.35)), List(Some(78.354649), Some(12.241)), @@ -14,14 +8,9 @@ List(Some(0.20126676681483952), Some(0.9277165354330709)), List(Some(0.09141762603007778), Some(2.119679764725104))) -lazy val f = Future { - assert((yearly_yield(test_deltas, 100, 0) - 107).abs <= 2) - assert((yearly_yield(test_deltas, 100, 1) - 85).abs <= 2) - assert((yearly_yield(test_deltas, 100, 2) - 156).abs <= 2) - assert((yearly_yield(test_deltas, 100, 3) - 210).abs <= 2) - assert((investment(List("IBM", "BIDU"), 2004 to 2008, 100) - 298).abs <= 10) -} +assert((yearly_yield(test_deltas, 100, 0) - 107).abs <= 2) +assert((yearly_yield(test_deltas, 100, 1) - 85).abs <= 2) +assert((yearly_yield(test_deltas, 100, 2) - 156).abs <= 2) +assert((yearly_yield(test_deltas, 100, 3) - 210).abs <= 2) +assert((investment(List("IBM", "BIDU"), 2004 to 2008, 100) - 298).abs <= 10) - -Await.result(f, 180 second) - diff -r 03530cb87cd0 -r b37052895281 marking1/drumb_test.sh --- a/marking1/drumb_test.sh Tue Jan 16 10:47:29 2018 +0000 +++ b/marking1/drumb_test.sh Fri Jan 19 14:09:08 2018 +0000 @@ -1,42 +1,51 @@ #!/bin/bash -set -e +set -euo pipefail + out=${1:-output} echo "" > $out -echo "Below is the feedback for your submission for drumb.scala" >> $out +echo "Below is the feedback and provisional marks for your submission" >> $out +echo "for assignment 6 Part 3. 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 +# marks for CW7 part 3 +marks=$(( 0 )) + # compilation tests function scala_compile { - (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) + (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) } # functional tests function scala_assert { - (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit -t 360; JAVA_OPTS="-Xmx4g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) } + # purity test function scala_vars { - (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) + (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) } + # var, .par return, ListBuffer test # -echo "drumb.scala does not contain vars, returns etc?" >> $out +echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out if (scala_vars drumb.scala) then - echo " --> fail" >> $out + echo " --> test failed" | tee -a $out tsts0=$(( 1 )) else - echo " --> success" >> $out + echo " --> success" | tee -a $out tsts0=$(( 0 )) fi @@ -44,14 +53,14 @@ # compilation test if [ $tsts0 -eq 0 ] then - echo "drumb.scala runs?" >> $out + echo "drumb.scala runs?" | tee -a $out - if (scala_compile alcohol.scala) + if (scala_compile drumb.scala) then - echo " --> success" >> $out + echo " --> success" | tee -a $out tsts=$(( 0 )) else - echo " --> scala did not run alcohol.scala" >> $out + echo " --> scala drumb.scala did not run successfully" | tee -a $out tsts=$(( 1 )) fi else @@ -64,16 +73,21 @@ if [ $tsts -eq 0 ] then - echo " get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out - echo " List(List(Some(311.349976), Some(27.505054))," >> $out - echo " List(Some(300.222351), Some(42.357094))," >> $out - echo " List(Some(330.555054), Some(52.852215)))" >> $out + echo " get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out + echo " List(List(None), List(None), List(Some(6.35)), " | tee -a $out + echo " List(Some(12.241)), List(Some(38.188)))" | tee -a $out + echo " " | tee -a $out + echo " get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out + echo " List(List(Some(311.349976), Some(27.505054))," | tee -a $out + echo " List(Some(300.222351), Some(42.357094))," | tee -a $out + echo " List(Some(330.555054), Some(52.852215)))" | tee -a $out if (scala_assert "drumb.scala" "drumb_test1.scala") then - echo " --> success" >> $out + echo " --> success" | tee -a $out + marks=$(( marks + 2 )) else - echo " --> test failed" >> $out + echo " --> test failed" | tee -a $out fi fi @@ -81,15 +95,22 @@ if [ $tsts -eq 0 ] then - echo " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out - echo " List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out - echo " List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out + echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out + echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out + echo " " | tee -a $out + echo " get_deltas(prices1) == List(List(None), List(None), " | tee -a $out + echo " List(Some(0.9277165354330709)), " | tee -a $out + echo " List(Some(2.119679764725104)))" | tee -a $out + echo " " | tee -a $out + echo " get_deltas(prices2) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " | tee -a $out + echo " List(Some(0.10103412653643493), Some(0.2477771728154912)))" | tee -a $out if (scala_assert "drumb.scala" "drumb_test2.scala") then - echo " --> success" >> $out + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) else - echo " --> test failed" >> $out + echo " --> test failed" | tee -a $out fi fi @@ -98,16 +119,36 @@ if [ $tsts -eq 0 ] then - echo " yearly_yield(get_deltas(<>), 100, 0) == 125" >> $out - echo "" >> $out - echo " investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out - echo " investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out + echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out + echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out + echo " val prices3 = get_prices(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012)" | tee -a $out + echo " val deltas1 = get_deltas(prices1)" | tee -a $out + echo " val deltas2 = get_deltas(prices2)" | tee -a $out + echo " val deltas3 = get_deltas(prices3)" | tee -a $out + echo "" | tee -a $out + echo " yearly_yield(deltas1, 100, 0) == 100" | tee -a $out + echo " yearly_yield(deltas1, 100, 2) == 192" | tee -a $out + echo " yearly_yield(deltas2, 100, 0) == 125" | tee -a $out + echo " yearly_yield(deltas3, 100, 0) == 164" | tee -a $out + echo " yearly_yield(deltas3, 100, 1) == 119" | tee -a $out + echo "" | tee -a $out + echo " val inv1 = investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100)" | tee -a $out + echo " val inv2 = investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012, 100)" | tee -a $out + echo "" | tee -a $out + echo " inv1 >= 295 && inv1 <= 301" | tee -a $out + echo " inv2 >= 194 && inv2 <= 198" | tee -a $out if (scala_assert "drumb.scala" "drumb_test3.scala") then - echo " --> success" >> $out + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) else - echo " --> test failed" >> $out + echo " --> test failed" | tee -a $out fi fi + + +## final marks +echo "Overall mark for CW 6, Part 3" | tee -a $out +echo "$marks" | tee -a $out diff -r 03530cb87cd0 -r b37052895281 marking1/drumb_test1.scala --- a/marking1/drumb_test1.scala Tue Jan 16 10:47:29 2018 +0000 +++ b/marking1/drumb_test1.scala Fri Jan 19 14:09:08 2018 +0000 @@ -1,14 +1,13 @@ - -/* -assert(CW6c.get_prices(List("BIDU"), 2004 to 2008) == List(List(None), List(None), - List(Some(6.35)), List(Some(12.241)), - List(Some(38.188)))) - -*/ -assert(CW6c.get_prices(List("GOOG", "AAPL"), 2010 to 2012) == - List(List(Some(311.349976), Some(27.505054)), - List(Some(300.222351), Some(42.357094)), - List(Some(330.555054), Some(52.852215)))) +assert(CW6c.get_prices(List("BIDU"), 2004 to 2008) == + List(List(None), List(None), + List(Some(6.35)), List(Some(12.241)), + List(Some(38.188)))) + + +assert(CW6c.get_prices(List("GOOG", "AAPL"), 2010 to 2012) == + List(List(Some(311.349976), Some(27.505054)), + List(Some(300.222351), Some(42.357094)), + List(Some(330.555054), Some(52.852215)))) diff -r 03530cb87cd0 -r b37052895281 marking1/drumb_test2.scala --- a/marking1/drumb_test2.scala Tue Jan 16 10:47:29 2018 +0000 +++ b/marking1/drumb_test2.scala Fri Jan 19 14:09:08 2018 +0000 @@ -1,36 +1,12 @@ -//println("starting test now") -/* -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - -val urban_prices = List(List(Some(71.539941), None), - List(Some(76.974614), None), - List(Some(65.226685), Some(6.35)), - List(Some(78.354649), Some(12.241)), - List(Some(85.517645), Some(38.188))) - -val urban_deltas = List(List(Some(0.07596697626574789), None), - List(Some(-0.152620823795232), None), - List(Some(0.20126676681483952), Some(0.9277165354330709)), - List(Some(0.09141762603007778), Some(2.119679764725104))) +val urban_prices1 = CW6c.get_prices(List("BIDU"), 2004 to 2008) +val urban_prices2 = CW6c.get_prices(List("GOOG", "AAPL"), 2010 to 2012) -lazy val f = Future { - //assert(get_deltas(urban_prices) == urban_deltas) - assert (get_deltas(get_prices(List("IBM", "BIDU"), 2004 to 2008)) == urban_deltas) -} - - -Await.result(f, 180 second) +assert(CW6c.get_deltas(urban_prices1) == + List(List(None), List(None), + List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) -*/ - -val urban_prices = List(List(Some(311.349976), Some(27.505054)), - List(Some(300.222351), Some(42.357094)), - List(Some(330.555054), Some(52.852215))) - -assert(CW6c.get_deltas(urban_prices) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), - List(Some(0.10103412653643493), Some(0.2477771728154912)))) +assert(CW6c.get_deltas(urban_prices2) == + List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), + List(Some(0.10103412653643493), Some(0.2477771728154912)))) diff -r 03530cb87cd0 -r b37052895281 marking1/drumb_test3.scala --- a/marking1/drumb_test3.scala Tue Jan 16 10:47:29 2018 +0000 +++ b/marking1/drumb_test3.scala Fri Jan 19 14:09:08 2018 +0000 @@ -1,20 +1,20 @@ +val urban_prices1 = CW6c.get_prices(List("BIDU"), 2004 to 2008) +val urban_prices2 = CW6c.get_prices(List("GOOG", "AAPL"), 2010 to 2012) +val urban_prices3 = CW6c.get_prices(List("GOOG", "AAPL", "BIDU"), 2010 to 2012) -val urban_prices = List(List(Some(311.349976), Some(27.505054)), - List(Some(300.222351), Some(42.357094)), - List(Some(330.555054), Some(52.852215))) - - -assert(CW6c.yearly_yield(CW6c.get_deltas(urban_prices), 100, 0) == 125) - +val urban_deltas1 = CW6c.get_deltas(urban_prices1) +val urban_deltas2 = CW6c.get_deltas(urban_prices2) +val urban_deltas3 = CW6c.get_deltas(urban_prices3) -val urban_blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU") -val urban_rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", - "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "GGP", "HCP") +assert(CW6c.yearly_yield(urban_deltas1, 100, 0) == 100) +assert(CW6c.yearly_yield(urban_deltas1, 100, 2) == 192) +assert(CW6c.yearly_yield(urban_deltas2, 100, 0) == 125) +assert(CW6c.yearly_yield(urban_deltas3, 100, 0) == 164) +assert(CW6c.yearly_yield(urban_deltas3, 100, 1) == 119) -val urban_rstate_res = CW6c.investment(urban_rstate_portfolio, 1978 to 2017, 100) -val urban_blchip_res = CW6c.investment(urban_blchip_portfolio, 1978 to 2017, 100) +val urban_inv1 = CW6c.investment(List("IBM", "BIDU"), 2004 to 2008, 100) +val urban_inv2 = CW6c.investment(List("GOOG", "AAPL", "BIDU"), 2010 to 2012, 100) -// the rstate value is 30895 because of a faulty ESS.cvs file +assert(urban_inv1 >= 295 && urban_inv1 <= 301) +assert(urban_inv2 >= 194 && urban_inv2 <= 198) -assert(urban_rstate_res > 30885 && urban_rstate_res < 30905) -assert(urban_blchip_res > 349587 && urban_blchip_res < 349607) diff -r 03530cb87cd0 -r b37052895281 marking1/mark --- a/marking1/mark Tue Jan 16 10:47:29 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#!/bin/sh -###set -e - -trap "exit" INT - -./collatz_test.sh output1 -./alcohol_test.sh output2 -./drumb_test.sh output3 - diff -r 03530cb87cd0 -r b37052895281 marking1/mk-advanced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marking1/mk-advanced Fri Jan 19 14:09:08 2018 +0000 @@ -0,0 +1,26 @@ +#!/bin/sh +###set -e + +trap "exit" INT + +files=${1:-assignment20176-*} + +for sd in $files; do + cd $sd + echo $sd + touch . + cp ../../../marking1/drumb_test.sh . + cp ../../../marking1/drumb_test1.scala . + cp ../../../marking1/drumb_test2.scala . + cp ../../../marking1/drumb_test3.scala . + cp ../../../marking1/*.csv . + ./drumb_test.sh output + rm drumb_test.sh + rm drumb_test1.scala + rm drumb_test2.scala + rm drumb_test3.scala + rm *.csv + cd .. +done + + diff -r 03530cb87cd0 -r b37052895281 testing1/drumb_test.sh --- a/testing1/drumb_test.sh Tue Jan 16 10:47:29 2018 +0000 +++ b/testing1/drumb_test.sh Fri Jan 19 14:09:08 2018 +0000 @@ -46,12 +46,12 @@ then echo "drumb.scala runs?" >> $out - if (scala_compile alcohol.scala) + if (scala_compile drumb.scala) then echo " --> success" >> $out tsts=$(( 0 )) else - echo " --> scala did not run alcohol.scala" >> $out + echo " --> scala did not run drumb.scala" >> $out tsts=$(( 1 )) fi else