# HG changeset patch # User Christian Urban # Date 1544918292 0 # Node ID 1616d06a08930cbb8c6e19c1e2ea7a5c344b51d7 # Parent 50a3b874008a004430133edc475803f33d7a6e6a updared diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb.scala --- a/testing1/drumb.scala Sat Dec 15 13:46:54 2018 +0000 +++ b/testing1/drumb.scala Sat Dec 15 23:58:12 2018 +0000 @@ -153,4 +153,15 @@ //} +//val ds = get_deltas(get_prices(List("GOOG", "AAPL"), 2010 to 2012)) +//yearly_yield(ds, 100, 0) => 125 +//yearly_yield(ds, 100, 1) => 117 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100) // => 100 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100) // => 27 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) // => 42 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) // => 27 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) // => 38 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) // => 113 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2006, 100) // => 254 +//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2007, 100) // => 349 diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb_test.sh --- a/testing1/drumb_test.sh Sat Dec 15 13:46:54 2018 +0000 +++ b/testing1/drumb_test.sh Sat Dec 15 23:58:12 2018 +0000 @@ -17,13 +17,13 @@ # functional tests function scala_assert { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" 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) } diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb_test2.scala --- a/testing1/drumb_test2.scala Sat Dec 15 13:46:54 2018 +0000 +++ b/testing1/drumb_test2.scala Sat Dec 15 23:58:12 2018 +0000 @@ -1,8 +1,141 @@ +#!/bin/bash +set -e -assert(get_first_price("GOOG", 1980) == None) +out=${1:-output} + +echo "" > $out + +echo "Below is the feedback for your submission for drumb.scala" >> $out +echo "" >> $out + +# compilation tests + +function scala_compile { + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out) +} + +# functional tests + +function scala_assert { + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null) +} -assert(get_first_price("GOOG", 2010) == Some(311.349976)) +# purity test + +function scala_vars { + (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) +} + + +# var, .par return, ListBuffer test +# +echo "drumb.scala does not contain vars, returns etc?" >> $out + +if (scala_vars drumb.scala) +then + echo " --> fail (make triple-sure your program conforms to the required format)" >> $out + tsts0=$(( 0 )) +else + echo " --> success" >> $out + tsts0=$(( 0 )) +fi +# compilation test +if [ $tsts0 -eq 0 ] +then + echo "drumb.scala runs?" >> $out + + if (scala_compile drumb.scala) + then + echo " --> success" >> $out + tsts=$(( 0 )) + else + echo -e " --> SCALA DID NOT RUN DRUMB.SCALA\n" >> $out + tsts=$(( 1 )) + fi +else + tsts=$(( 1 )) +fi + +### get january data + +if [ $tsts -eq 0 ] +then + echo " get_january_data(\"GOOG\", 1980) == List()" >> $out + echo " get_january_data(\"GOOG\", 2010).head == \"2010-01-04,311.349976\"" >> $out + + if (scala_assert "drumb.scala" "drumb_test1.scala") + then + echo " --> success" >> $out + else + echo -e " --> \n ONE TEST FAILED\n" >> $out + fi +fi + +### get first price + +if [ $tsts -eq 0 ] +then + echo " get_first_price(\"GOOG\", 1980) == None" >> $out + echo " get_first_price(\"GOOG\", 2010) == Some(311.349976)" >> $out + + if (scala_assert "drumb.scala" "drumb_test2.scala") + then + echo " --> success" >> $out + else + echo " --> test failed" >> $out + fi +fi + +### get prices tests + +if [ $tsts -eq 0 ] +then + echo " get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out + echo " List(List(Some(311.349976), Some(20.544939))," >> $out + echo " List(Some(300.222351), Some(31.638695))," >> $out + echo " List(Some(330.555054), Some(39.478039)))" >> $out + + if (scala_assert "drumb.scala" "drumb_test3.scala") + then + echo " --> success" >> $out + else + echo " --> test failed" >> $out + fi +fi + +### get_deltas_test + +#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 +# +# if (scala_assert "drumb.scala" "drumb_test2.scala") +# then +# echo " --> success" >> $out +# else +# echo " --> test failed" >> $out +# fi +#fi +### yield_tests, investment_test + +#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 +# +# if (scala_assert "drumb.scala" "drumb_test3.scala") +# then +# echo " --> success" >> $out +# else +# echo " --> test failed" >> $out +# fi +#fi + diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb_test2.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing1/drumb_test2.sh Sat Dec 15 23:58:12 2018 +0000 @@ -0,0 +1,118 @@ +#!/bin/bash +set -e + +out=${1:-output} + +echo -e "" > $out + +echo -e "Below is the feedback for your submission advanced part of drumb.scala:" >> $out +echo -e "" >> $out + +# compilation tests + +function scala_compile { + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) +} + +# functional tests + +function scala_assert { + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null) +} + +# purity test + +function scala_vars { + (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) +} + + +# var, .par return, ListBuffer test +# +echo -e "drumb.scala does not contain vars, returns etc?" >> $out + +if (scala_vars drumb.scala) +then + echo -e " --> fail (make triple-sure your program conforms to the required format)" >> $out + tsts0=$(( 0 )) +else + echo -e " --> success" >> $out + tsts0=$(( 0 )) +fi + + +# compilation test +if [ $tsts0 -eq 0 ] +then + echo -e "drumb.scala runs?" >> $out + + if (scala_compile drumb.scala) + then + echo -e " --> success" >> $out + tsts=$(( 0 )) + else + echo -e " --> SCALA DID NOT RUN DRUMB.SCALA\n" >> $out + tsts=$(( 1 )) + fi +else + tsts=$(( 1 )) +fi + +### get_deltas_test + +if [ $tsts -eq 0 ] +then + echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out + echo -e " List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " >> $out + echo -e " List(Some(0.10103412653643493), Some(0.24777709700099845)))" >> $out + echo -e "" >> $out + echo -e " get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " >> $out + echo -e " List(List(None), List(None), " >> $out + echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " >> $out + + if (scala_assert "drumb.scala" "drumb_test5.scala") + then + echo -e " --> success" >> $out + else + echo -e " --> \n ONE TEST FAILED\n" >> $out + fi +fi + + +### yield_tests + +if [ $tsts -eq 0 ] +then + echo -e " val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" >> $out + echo -e " yearly_yield(get_deltas(de, 100, 0) == 125" >> $out + echo -e " yearly_yield(get_deltas(de, 100, 1) == 117" >> $out + + if (scala_assert "drumb.scala" "drumb_test6.scala") + then + echo -e " --> success" >> $out + else + echo -e " --> \n ONE TEST FAILED\n" >> $out + fi +fi + +### investment_test + +if [ $tsts -eq 0 ] +then + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" >> $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" >> $out + + if (scala_assert "drumb.scala" "drumb_test7.scala") + then + echo -e " --> success" >> $out + else + echo -e " --> \n ONE TEST FAILED\n" >> $out + fi +fi + diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb_test5.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing1/drumb_test5.scala Sat Dec 15 23:58:12 2018 +0000 @@ -0,0 +1,20 @@ + +// get_prices(List("GOOG", "AAPL"), 2010 to 2012) +val urban_prices = List(List(Some(311.349976), Some(20.544939)), + List(Some(300.222351), Some(31.638695)), + List(Some(330.555054), Some(39.478039))) + + +assert(get_deltas(urban_prices) == List(List(Some(-0.03573992567129673), Some(0.539975124774038)), + List(Some(0.10103412653643493), Some(0.24777709700099845)))) + + +//get_prices(List("BIDU"), 2004 to 2008) +val urban_prices2 = List(List(None), List(None), + List(Some(6.35)), List(Some(12.241)), + List(Some(38.188))) + + +assert(get_deltas(urban_prices2) == List(List(None), List(None), + List(Some(0.9277165354330709)), + List(Some(2.119679764725104)))) diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb_test6.scala --- a/testing1/drumb_test6.scala Sat Dec 15 13:46:54 2018 +0000 +++ b/testing1/drumb_test6.scala Sat Dec 15 23:58:12 2018 +0000 @@ -1,21 +1,9 @@ -//println("starting test now") +//val urban_deltas = get_deltas(get_prices(List("GOOG", "AAPL"), 2010 to 2012)) -/* -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 ds_urban = List(List(Some(-0.03573992567129673), Some(0.539975124774038)), + List(Some(0.10103412653643493), Some(0.24777709700099845))) -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(get_deltas(urban_prices) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), - List(Some(0.10103412653643493), Some(0.2477771728154912)))) +assert(yearly_yield(ds_urban, 100, 0) == 125) +assert(yearly_yield(ds_urban, 100, 1) == 117) diff -r 50a3b874008a -r 1616d06a0893 testing1/drumb_test7.scala --- a/testing1/drumb_test7.scala Sat Dec 15 13:46:54 2018 +0000 +++ b/testing1/drumb_test7.scala Sat Dec 15 23:58:12 2018 +0000 @@ -1,26 +1,9 @@ -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_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") - -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) - -// the rstate value is 30895 because of a faulty ESS.cvs file - -// if you round after each year to a Long you get 30895 and 349597 -// if you work with doubles until the end and then round to a Long you get 30937 and 355204 - -assert((urban_rstate_res > 30885 && urban_rstate_res < 30905) || - (urban_rstate_res > 30927 && urban_rstate_res < 30947)) - -assert((urban_blchip_res > 349587 && urban_blchip_res < 349607) || - (urban_blchip_res > 355194 && urban_blchip_res < 355214)) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100) == 100) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100) == 27) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) == 42) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) == 27) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) == 38) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) == 113) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2006, 100) == 254) +assert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2007, 100) == 349) diff -r 50a3b874008a -r 1616d06a0893 testing1/mark2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing1/mark2 Sat Dec 15 23:58:12 2018 +0000 @@ -0,0 +1,14 @@ +#!/bin/bash +###set -e + +trap "exit" INT + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cp $DIR/* . + +./drumb_test2.sh output1 + +echo -e "Here is an automated test report for your work so far on assignment 6, Part 3. Please note that this is not the mark for your work; it is provided only in the hope that it is useful in developing your solution. Passing these tests does not guarantee your code is free from bugs: after the deadline, your code will be marked against a different, more thorough set of test cases.\n\n" > $1 + +cat output1 >> $1 diff -r 50a3b874008a -r 1616d06a0893 testing3/knight2_test.sh --- a/testing3/knight2_test.sh Sat Dec 15 13:46:54 2018 +0000 +++ b/testing3/knight2_test.sh Sat Dec 15 23:58:12 2018 +0000 @@ -8,14 +8,10 @@ echo "" > $out -echo "Below is the feedback and provisional marks for your submission" >> $out -echo "for assignment 8 Part 2. 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 +echo -e "Below is the feedback for your submission of CW 8, Advanced Part 2." >> $out +echo -e "" >> $out -# marks for CW8 part 2 -marks=$(( 0 )) + # compilation tests @@ -30,10 +26,6 @@ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null) } -function scala_assert_slow { - (ulimit -t 120; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) -} - # purity test @@ -45,15 +37,15 @@ # knights2: purity test # -echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out +echo -e "knight2.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out if (scala_vars knight2.scala) then - echo -e " --> test failed" | tee -a $out + echo -e " --> fail (make triple-sure your program conforms to the required format)" >> $out tsts0=$(( 0 )) else - echo -e " --> success" | tee -a $out + echo -e " --> success" >> $out tsts0=$(( 0 )) fi @@ -61,11 +53,11 @@ # compilation test if [ $tsts0 -eq 0 ] then - echo -e "knight2.scala runs?" | tee -a $out + echo -e "knight2.scala runs?" >> $out if (scala_compile knight2.scala) then - echo -e " --> success" | tee -a $out + echo -e " --> success" >> $out tsts1=$(( 0 )) else echo -e " --> SCALA DID NOT RUN KNIGHT2.SCALA\n" >> $out @@ -79,14 +71,13 @@ if [ $tsts1 -eq 0 ] then - echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out - echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out - echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out + echo -e " ordered_moves(8, List((3,4), (3,2)), (1,3)) == List((0,1), (0,5), (2,1), (2,5))" >> $out + echo -e " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" >> $out + echo -e " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" >> $out if (scala_assert "knight2.scala" "knight_test6.scala") then - echo -e " --> success" | tee -a $out - marks=$(( marks + 1 )) + echo -e " --> success" >> $out else echo -e " --> \n ONE TEST FAILED\n" >> $out fi @@ -97,12 +88,11 @@ if [ $tsts1 -eq 0 ] then - echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" | tee -a $out + echo -e " first_closed_tour_heuristic(6, List((3,3))) found and correct?" >> $out if (scala_assert "knight2.scala" "knight_test7.scala") then - echo -e " --> success" | tee -a $out - marks=$(( marks + 1 )) + echo -e " --> success" >> $out else echo -e " --> \n ONE TEST FAILED\n" >> $out fi @@ -112,13 +102,12 @@ if [ $tsts1 -eq 0 ] then - echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" | tee -a $out - echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" | tee -a $out + echo -e " first_tour_heuristic(8, List((0,0))) found and correct?" >> $out + echo -e " first_tour_heuristic(30, List((0,0))) found and correct?" >> $out if (scala_assert "knight2.scala" "knight_test8.scala") then - echo -e " --> success" | tee -a $out - marks=$(( marks + 1 )) + echo -e " --> success" >> $out else echo -e " --> \n ONE TEST FAILED\n" >> $out fi @@ -127,15 +116,15 @@ # knights3: purity test # -echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out +echo -e "knight3.scala does not contain vars, returns, Arrays, ListBuffers etc?" >> $out if (scala_vars knight3.scala) then - echo " --> test failed" | tee -a $out + echo " --> test failed" >> $out tsts0=$(( 0 )) else - echo " --> success" | tee -a $out + echo " --> success" >> $out tsts0=$(( 0 )) fi @@ -143,11 +132,11 @@ # compilation test if [ $tsts0 -eq 0 ] then - echo "knight3.scala runs?" | tee -a $out + echo "knight3.scala runs?" >> $out if (scala_compile knight3.scala) then - echo " --> success" | tee -a $out + echo " --> success" >> $out tsts1=$(( 0 )) else echo -e " --> SCALA DID NOT RUN KNIGHT3.SCALA\n" >> $out @@ -160,18 +149,13 @@ if [ $tsts1 -eq 0 ] then - echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" | tee -a $out + echo -e " tour_on_mega_board(70, List((0,0))) found and correct?" >> $out if (scala_assert "knight3.scala" "knight_test9.scala") then - echo -e " --> success" | tee -a $out - marks=$(( marks + 1 )) + echo -e " --> success" >> $out else echo -e " --> \n ONE TEST FAILED\n" >> $out fi fi - -## final marks -echo "Overall mark for CW 8, Part 2" | tee -a $out -echo "$marks" | tee -a $out