# HG changeset patch # User Christian Urban # Date 1572358344 0 # Node ID 87b9e3e2c1a7f08795b8de5486c2e1ba4abb421f # Parent a057dc4457fccaa5b89ae710aef0fbf1c3b5e4a3 updated diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/collatz_test1.scala --- a/marking/collatz_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ - -assert(List(0,1).contains(collatz(1))) - -assert(collatz(2)==2) - -assert(collatz(9)==20) - -assert(collatz(9000)==48) - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/collatz_test2.scala --- a/marking/collatz_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -//println("starting test now") - -assert(collatz_max(2)==(2,2)) - -assert(collatz_max(77000)==(340,52527)) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/drumb_test1.scala --- a/marking/drumb_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ - -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)))) - - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/drumb_test2.scala --- a/marking/drumb_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ - -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))) - - -assert (get_deltas(get_prices(List("IBM", "BIDU"), 2004 to 2008)) == urban_deltas) - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/drumb_test3.scala --- a/marking/drumb_test3.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ - -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)), - List(Some(85.517645), Some(38.188))) - -val test_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))) - -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) - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/knight1_test.scala --- a/marking/knight1_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - -lazy val f = Future { - assert(legal_moves(8, Nil, (2,2)) == - List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))) - assert(legal_moves(8, Nil, (7,7)) == List((6,5), (5,6))) - assert(legal_moves(8, List((4,1), (1,0)), (2,2)) == - List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4))) - assert(legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6))) - assert(legal_moves(1, Nil, (0,0)) == List()) - assert(legal_moves(2, Nil, (0,0)) == List()) - assert(legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))) -} - -Await.result(f, 120 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/knight1b_test.scala --- a/marking/knight1b_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - -def count_all_tours(dim: Int) = { - for (i <- (0 until dim).toList; - j <- (0 until dim).toList) yield count_tours(dim, List((i, j))) -} - -def add_pair_urban(x: Pos)(y: Pos): Pos = - (x._1 + y._1, x._2 + y._2) - -def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean = - 0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x) - -def moves_urban(x: Pos): List[Pos] = - List(( 1, 2),( 2, 1),( 2, -1),( 1, -2), - (-1, -2),(-2, -1),(-2, 1),(-1, 2)).map(add_pair_urban(x)) - -def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] = - moves_urban(x).filter(is_legal_urban(dim, path)) - -def correct_urban(dim: Int)(p: Path): Boolean = p match { - case Nil => true - case x::Nil => true - case x::y::p => if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false -} - - -lazy val f = Future { - assert(count_all_tours(1) == List(1)) - assert(count_all_tours(2) == List(0, 0, 0, 0)) - assert(count_all_tours(3) == List(0, 0, 0, 0, 0, 0, 0, 0, 0)) - assert(count_all_tours(4) == List(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) - assert(count_all_tours(5) == List(304, 0, 56, 0, 304, 0, 56, 0, 56, 0, 56, 0, 64, 0, 56, 0, 56, 0, 56, 0, 304, 0, 56, 0, 304)) - - val ts = enum_tours(5, List((0, 2))) - assert(ts.map(correct_urban(5)).forall(_ == true) == true) - assert(ts.length == 56) -} - -Await.result(f, 360 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/knight2b_test.scala --- a/marking/knight2b_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - -def add_pair_urban(x: Pos)(y: Pos): Pos = - (x._1 + y._1, x._2 + y._2) - -def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean = - 0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x) - -def moves_urban(x: Pos): List[Pos] = - List(( 1, 2),( 2, 1),( 2, -1),( 1, -2), - (-1, -2),(-2, -1),(-2, 1),(-1, 2)).map(add_pair_urban(x)) - -def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] = - moves_urban(x).filter(is_legal_urban(dim, path)) - -def correct_urban(dim: Int)(p: Path): Boolean = p match { - case Nil => true - case x::Nil => true - case x::y::p => - if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false -} - - -lazy val f = Future { - - val ts1 = first_tour(8, List((0, 0))).get - assert(correct_urban(8)(ts1) == true) - - val ts2 = first_tour(4, List((0, 0))) - assert(ts2 == None) -} - -Await.result(f, 300 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/knight3a_test.scala --- a/marking/knight3a_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - -lazy val f = Future { - -assert( ordered_moves(8, List((3,4), (3,2)), (1, 3)) == List((0,1), (0,5), (2,1), (2,5))) -assert( ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))) -assert( ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))) - -} - -Await.result(f, 120 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/knight3b_test.scala --- a/marking/knight3b_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - -def add_pair_urban(x: Pos)(y: Pos): Pos = - (x._1 + y._1, x._2 + y._2) - -def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean = - 0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x) - -def moves_urban(x: Pos): List[Pos] = - List(( 1, 2),( 2, 1),( 2, -1),( 1, -2), - (-1, -2),(-2, -1),(-2, 1),(-1, 2)).map(add_pair_urban(x)) - -def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] = - moves_urban(x).filter(is_legal_urban(dim, path)) - -def correct_urban(dim: Int)(p: Path): Boolean = p match { - case Nil => true - case x::Nil => true - case x::y::p => - if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false -} - -def correct_closed_urban(dim: Int)(p: Path) = - correct_urban(6)(p) && moves_urban(p.head).contains(p.last) - -lazy val f = Future { - - val tsc = first_closed_tour_heuristic(6, List((3, 3))).get - assert(correct_closed_urban(6)(tsc) == true) - -} - -Await.result(f, 300 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/knight3c_test.scala --- a/marking/knight3c_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - -def add_pair_urban(x: Pos)(y: Pos): Pos = - (x._1 + y._1, x._2 + y._2) - -def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean = - 0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x) - -def moves_urban(x: Pos): List[Pos] = - List(( 1, 2),( 2, 1),( 2, -1),( 1, -2), - (-1, -2),(-2, -1),(-2, 1),(-1, 2)).map(add_pair_urban(x)) - -def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] = - moves_urban(x).filter(is_legal_urban(dim, path)) - -def correct_urban(dim: Int)(p: Path): Boolean = p match { - case Nil => true - case x::Nil => true - case x::y::p => - if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false -} - - -lazy val f1 = Future { - - val ts8 = first_tour_heuristic(8, List((0,0))).get - assert(correct_urban(8)(ts8) == true) - -} - -Await.result(f1, 360 second) - -lazy val f2 = Future { - - val ts50 = first_tour_heuristic(50, List((0,0))).get - assert(correct_urban(50)(ts50) == true) - -} - -Await.result(f2, 360 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mark01a --- a/marking/mark01a Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -#!/bin/bash - -# try this to make it fail safely -set -eu -o pipefail -posix -#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 diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mark01b --- a/marking/mark01b Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -#!/bin/bash -set -e - -out=${1:-output2} - -echo "" > $out - -echo "Below is the feedback and provisional mark 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 - - -#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 part 3 -marks=$(( 0 )) - - -# compilation test -echo "drumb.scala runs?" | tee -a $out - -if (scala_compile drumb.scala) -then - echo " --> yes" | tee -a $out - tsts=$(( 0 )) -else - echo " --> scala did not run drumb.scala" | tee -a $out - tsts=$(( 1 )) -fi - - -### get price tests - -if [ $tsts -eq 0 ] -then - 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 - - if (scala_assert "drumb.scala" "../../../marking/drumb_test1.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -### get_deltas_test - -if [ $tsts -eq 0 ] -then - echo " get_deltas(get_prices(List(\"IBM\", \"BIDU\"), 2004 to 2008)) = " | tee -a $out - echo " List(List(Some(0.07596697626574789), None), " | tee -a $out - echo " List(Some(-0.152620823795232), None)," | tee -a $out - echo " List(Some(0.20126676681483952), Some(0.9277165354330709))," | tee -a $out - echo " List(Some(0.09141762603007778), Some(2.119679764725104)))" | tee -a $out - - if (scala_assert "drumb.scala" "../../../marking/drumb_test2.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -### yield_tests, investmetn_test - -if [ $tsts -eq 0 ] -then - echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 0) - 107).abs <= 2 " | tee -a $out - echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 1) - 85).abs <= 2 " | tee -a $out - echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 2) - 156).abs <= 2 " | tee -a $out - echo " yearly_yield(IBM + BIDU, 04 - 08, 100, 3) - 210).abs <= 2 " | tee -a $out - echo " investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100) - 298).abs <= 10" | tee -a $out - - if (scala_assert "drumb.scala" "../../../marking/drumb_test3.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -## final marks -echo "Overall mark for CW 1, Part 3:" | tee -a $out -echo "$marks" | tee -a $out diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mark02 --- a/marking/mark02 Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,226 +0,0 @@ -#!/bin/bash -set -e - -out=${1:-output} - -echo "" > $out - -echo "Below is the feedback and provisional mark for your submission" >> $out -echo "for CW 7, Part 1. 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 - -function scala_vars { - (egrep 'var|return|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) -} - - -# 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 CW2 -marks=$(( 0 )) - -# knights1: var, comments test - -echo "knight1.scala does not contain vars, returns etc?" | tee -a $out - -if (scala_vars knight1.scala) -then - echo " --> fail" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> yes" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test - -if [ $tsts0 -eq 0 ] -then - echo "knight1.scala runs?" | tee -a $out - - if (scala_compile knight1.scala.bak) - then - echo " --> yes" | tee -a $out - tsts1=$(( 0 )) - else - echo " --> scala did not run knight1.scala" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - -### knight1a test - -if [ $tsts1 -eq 0 ] -then - echo " is_legal(8, Nil) (3,4) == true " | tee -a $out - echo " is_legal(8, (4,1) (1,0)) (4,1) == false " | tee -a $out - echo " is_legal(2, Nil) (0,0) == true" | tee -a $out - - if (scala_assert "knight1.scala.bak" "../../../marking/knight1c_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " legal_moves(8, Nil, (2,2)) = (3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)" | tee -a $out - echo " legal_moves(8, Nil, (7,7)) = (6,5), (5,6)" | tee -a $out - echo " legal_moves(8, (4,1), (1,0), (2,2)) = (3,4), (4,3), (3,0), (0,1), (0,3), (1,4)" | tee -a $out - echo " legal_moves(8, (6,6), (7,7)) = (6,5), (5,6)" | tee -a $out - echo " legal_moves(1, Nil, (0,0)) = Nil" | tee -a $out - echo " legal_moves(2, Nil, (0,0)) = Nil" | tee -a $out - echo " legal_moves(3, Nil, (0,0)) = (1,2), (2,1)" | tee -a $out - - if (scala_assert "knight1.scala.bak" "../../../marking/knight1_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -### knight1b test - -if [ $tsts1 -eq 0 ] -then - echo " all_tours from every position on the board" | tee -a $out - echo " dim = 1: 1" | tee -a $out - echo " 2: 0,0,0,0" | tee -a $out - echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out - echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out - echo " 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56,0,56,0,56,0,304,0,56,0,304" | tee -a $out - echo " enum_tours(5, (0,2) ) = 56 and all correct?" | tee -a $out - - if (scala_assert "knight1.scala.bak" "../../../marking/knight1b_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 2 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - - -# knights2: var, comments test - -echo "knight2.scala does not contain vars, returns etc?" | tee -a $out - -if (scala_vars knight2.scala) -then - echo " --> fail" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> yes" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - echo "knight2.scala runs?" | tee -a $out - - if (scala_compile knight2.scala.bak) - then - echo " --> yes" | tee -a $out - tsts1=$(( 0 )) - else - echo " --> scala did not run knight2.scala" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - -### knight2 test - -if [ $tsts1 -eq 0 ] -then - echo " Let f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None " | tee -a $out - echo " first((1,0),(2,0),(3,0),(4,0), f) == Some(List((4,0)))" | tee -a $out - echo " first((1,0),(2,0),(3,0), f) == None" | tee -a $out - - if (scala_assert "knight2.scala.bak" "../../../marking/knight2_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -### knight2b test - -if [ $tsts1 -eq 0 ] -then - echo " is first_tour(8, (0, 0)) ok? " | tee -a $out - echo " is first_tour(4, (0, 0)) == None " | tee -a $out - - if (scala_assert "knight2.scala.bak" "../../../marking/knight2b_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 2 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - -# knights3: var, comments test -# -#echo "knight3.scala does not contain vars, returns etc?" | tee -a $out - -#if (scala_vars knight3.scala) -#then -# echo " --> fail" | tee -a $out -# tsts0=$(( 1 )) -#else -# echo " --> success" | tee -a $out -# tsts0=$(( 0 )) -#fi - - -# compilation test -#if [ $tsts0 -eq 0 ] -#then -# echo "knight3.scala runs?" | tee -a $out -# -# if (scala_compile knight3.scala.bak) -# then -# echo " --> success" | tee -a $out -# tsts1=$(( 0 )) -# else -# echo " --> scala did not run knight3.scala" | tee -a $out -# tsts1=$(( 1 )) -# fi -#else -# tsts1=$(( 1 )) -#fi - - -## final marks -echo "Overall mark for CW 2, Part 1 " | tee -a $out -echo "$marks" | tee -a $out diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mark02b --- a/marking/mark02b Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -=-p#!/bin/bash -set -e - -out=${1:-output} - -echo "" > $out - -echo "Below is the feedback and provisional mark for your submission" >> $out -echo "for CW 7, 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 - -function scala_vars { - (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) -} - - -# 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 CW2b -marks=$(( 0 )) - -lm -# knights3: var, comments test -# -echo "knight3.scala does not contain vars, returns etc?" | tee -a $out - -if (scala_vars knight3.scala) -then - echo " --> fail" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> yes" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - echo "knight3.scala runs?" | tee -a $out - - if (scala_compile knight3.scala.bak) - then - echo " --> yes" | tee -a $out - tsts1=$(( 0 )) - else - echo " --> scala knight3.scala did not run successfully" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - -if [ $tsts1 -eq 0 ] -then - echo " ordered_moves(8, List((3,4), (3,2)), (1, 3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out - echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out - echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out - - if (scala_assert "knight3.scala.bak" "../../../marking/knight3a_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " first_closed_tour_heuristic(6, List((3, 3))) found and ok?" | tee -a $out - - if (scala_assert "knight3.scala.bak" "../../../marking/knight3b_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " first_tour_heuristic(8, List((0,0))) found and ok?" | tee -a $out - echo " first_tour_heuristic(50, List((0,0))) found and ok?" | tee -a $out - - if (scala_assert "knight3.scala.bak" "../../../marking/knight3c_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - -## final marks -echo "Overall mark for CW 7, Part 2" | tee -a $out -echo "$marks" | tee -a $out diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mark03a --- a/marking/mark03a Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +0,0 @@ -#!/bin/bash -set -e - -out=${1:-output} - -echo "" > $out - -echo "Below is the feedback and provisional mark for your submission" >> $out -echo "for CW 8, Part 1. 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 - -function scala_vars { - (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) -} - - -# compilation tests - -function scala_compile { - (ulimit -t 1 ; scala "$1" 1> $out 2> $out) -} - - -# functional tests - -function scala_assert { - (ulimit - t 1; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) -} - - -# marks for CW -marks=$(( 0 )) - - -# var, return, ListBuffer test -# -echo "re.scala does not contain vars, returns etc?" | tee -a $out - -if (scala_vars re.scala) -then - echo " --> fail" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> yes" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - echo "re.scala runs?" | tee -a $out - - if (scala_compile re.scala.bak) - then - echo " --> yes" | tee -a $out - tsts1=$(( 0 )) - else - echo " --> scala re.scala did not run successfully" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - -if [ $tsts1 -eq 0 ] -then - echo " nullable(ZERO) == false" | tee -a $out - echo " nullable(ONE) == true" | tee -a $out - echo " nullable(CHAR('a')) == false" | tee -a $out - echo " nullable(ZERO | ONE) == true" | tee -a $out - echo " nullable(ZERO | CHAR('a')) == false" | tee -a $out - echo " nullable(ONE ~ ONE) == true" | tee -a $out - echo " nullable(ONE ~ CHAR('a')) == false" | tee -a $out - echo " nullable(STAR(ZERO)) == true" | tee -a $out - - if (scala_assert "re.scala.bak" "../../../marking/re1a_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out - echo " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out - echo " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out - echo " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out - - if (scala_assert "re.scala.bak" "../../../marking/re1b_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " simp(ZERO | ONE) == ONE" | tee -a $out - echo " simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)" | tee -a $out - echo " simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')" | tee -a $out - echo " simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO" | tee -a $out - echo " simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')" | tee -a $out - echo " simp(CHAR('a') | CHAR('a')) == CHAR('a')" | tee -a $out - echo " simp(ONE | CHAR('a')) == (ONE | CHAR('a'))" | tee -a $out - - if (scala_assert "re.scala.bak" "../../../marking/re1c_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " EVIL = (a*)* b" | tee -a $out - echo " ders(List.fill(5)('a'),EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out - echo " ders(List('b'),EVIL) == ONE" | tee -a $out - echo " ders(List('b','b'),EVIL) == ZERO" | tee -a $out - echo " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out - echo " matcher(EVIL, \"b\") == true" | tee -a $out - echo " matcher(EVIL, \"bb\") == false" | tee -a $out - echo " matcher(\"abc\", \"abc\") == true" | tee -a $out - echo " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out - echo " matcher(ONE, \"\") == true" | tee -a $out - echo " matcher(ZERO, \"\") == false" | tee -a $out - echo " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out - echo " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out - - if (scala_assert "re.scala.bak" "../../../marking/re1d_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " replace(\"aa\".% | \"bb\", \"aabbbaaaaaaabaaaaabbaaaabb\" , \"c\") == \"ccbcabcaccc\"" | tee -a $out - echo " replace(\"aa\".% | \"bb\", \"abba\" , \"\") == \"aa\"" | tee -a $out - - if (scala_assert "re.scala.bak" "../../../marking/re1e_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 2 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - -## final marks -echo "Overall mark for CW 8, Part 1" | tee -a $out -echo "$marks" | tee -a $out diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mark03b --- a/marking/mark03b Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -#!/bin/bash -set -e - -out=${1:-output} - -echo "" > $out - -echo "Below is the feedback and provisional mark for your submission" >> $out -echo "for CW 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 - -function scala_vars { - (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) -} - - -# 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 CW -marks=$(( 0 )) - - -# var, return, ListBuffer test -# -echo "re2.scala does not contain vars, returns etc?" | tee -a $out - -if (scala_vars re2.scala) -then - echo " --> fail" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> yes" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - echo "re2.scala runs?" | tee -a $out - - if (scala_compile re2.scala) - then - echo " --> yes" | tee -a $out - tsts1=$(( 0 )) - else - echo " --> scala re2.scala did not run successfully" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - -if [ $tsts1 -eq 0 ] -then - echo " iterT(200000, (x: Int) => x + 1, 0) == 200000" | tee -a $out - echo " iterT(100, (x: BigInt) => x * 2, BigInt(2)) == BigInt(\"2535301200456458802993406410752\")" | tee -a $out - echo " iterT(10, (x: String) => x ++ \"a\", \"a\") == \"aaaaaaaaaaa\"" | tee -a $out - - if (scala_assert "re2.scala" "../../../marking/re2a_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 2 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " size(iterT(20, (r: Rexp) => der('a', r), EVIL)) == 7340068" | tee -a $out - echo " size(iterT(20, (r: Rexp) => simp(der('a', r)), EVIL)) == 8" | tee -a $out - - if (scala_assert "re2.scala" "../../../marking/re2b_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -if [ $tsts1 -eq 0 ] -then - echo " fixpT((x:Int) => if (200000 < x) x else x + 1, 0) == 200001" | tee -a $out - echo " fixpT((x:Long) => if (20 < x) x else x + 1, 0L) == 21L" | tee -a $out - - if (scala_assert "re2.scala" "../../../marking/re2c_test.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - -## final marks -echo "Overall mark for CW 8, Part 2" | tee -a $out -echo "$marks" | tee -a $out diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/mk --- a/marking/mk Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#!/bin/sh -###set -e - -trap "exit" INT -for sd in k*; do - cd $sd - echo $sd - touch . - #../mark - ../mark01b - cd .. -done - - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re1a_test.scala --- a/marking/re1a_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - - -lazy val f = Future { - assert(nullable(ZERO) == false) - assert(nullable(ONE) == true) - assert(nullable(CHAR('a')) == false) - assert(nullable(ZERO | ONE) == true) - assert(nullable(ZERO | CHAR('a')) == false) - assert(nullable(ONE ~ ONE) == true) - assert(nullable(ONE ~ CHAR('a')) == false) - assert(nullable(STAR(ZERO)) == true) -} - -Await.result(f, 120 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re1b_test.scala --- a/marking/re1b_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - - -lazy val f = Future { - assert(der('a', ZERO | ONE) == (ZERO | ZERO)) - assert(der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)) - assert(der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))) - assert(der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))) -} - -Await.result(f, 120 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re1c_test.scala --- a/marking/re1c_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - - -lazy val f = Future { - assert(simp(ZERO | ONE) == ONE) - assert(simp(STAR(ZERO | ONE)) == STAR(ZERO | ONE)) - assert(simp(ONE ~ (ONE ~ (ONE ~ CHAR('a')))) == CHAR('a')) - assert(simp(ONE ~ (ONE ~ (ONE ~ ZERO))) == ZERO) - assert(simp(ALT(ONE ~ (ONE ~ (ONE ~ ZERO)), CHAR('a'))) == CHAR('a')) - assert(simp(CHAR('a') | CHAR('a')) == CHAR('a')) - assert(simp(ONE | CHAR('a')) == (ONE | CHAR('a'))) -} - -Await.result(f, 30 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re1d_test.scala --- a/marking/re1d_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - -val EVIL_urban = SEQ(STAR(STAR(CHAR('a'))), CHAR('b')) - -lazy val f = Future { - println("1") - assert(ders(List.fill(5)('a'), EVIL_urban) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))) - println("2") - assert(ders(List('b'), EVIL_urban) == ONE) - println("3") - assert(ders(List('b','b'), EVIL_urban) == ZERO) - println("4") - assert(matcher(EVIL_urban, "a" * 5 ++ "b") == true) - println("5") - assert(matcher(EVIL_urban, "b") == true) - println("6") - assert(matcher(EVIL_urban, "bb") == false) - println("7") - assert(matcher("abc", "abc") == true) - println("8") - assert(matcher(("ab" | "a") ~ (ONE | "bc"), "abc") == true) - println("9") - assert(matcher(ONE, "") == true) - println("10") - assert(matcher(ZERO, "") == false) - println("11") - assert(matcher(ONE | CHAR('a'), "") == true) - println("12") - assert(matcher(ONE | CHAR('a'), "a") == true) -} - -Await.result(f, 90 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re1e_test.scala --- a/marking/re1e_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - - -lazy val f = Future { - assert(replace("aa".% | "bb", "aabbbaaaaaaabaaaaabbaaaabb" , "c") == "ccbcabcaccc") - assert(replace("aa".% | "bb", "abba" , "") == "aa") -} - -Await.result(f, 120 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re2a_test.scala --- a/marking/re2a_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - - -lazy val f = Future { - assert(iterT(200000, (x: Int) => x + 1, 0) == 200000) - assert(iterT(100, (x: BigInt) => x * 2, BigInt(2)) == BigInt("2535301200456458802993406410752")) - assert(iterT(10, (x: String) => x ++ "a", "a") == "aaaaaaaaaaa") -} - -Await.result(f, 90 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re2b_test.scala --- a/marking/re2b_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - -val EVIL_urban = SEQ(STAR(STAR(CHAR('a'))), CHAR('b')) - -def nullable_urban (r: Rexp) : Boolean = r match { - case ZERO => false - case ONE => true - case CHAR(_) => false - case ALT(r1, r2) => nullable_urban(r1) || nullable_urban(r2) - case SEQ(r1, r2) => nullable_urban(r1) && nullable_urban(r2) - case STAR(_) => true -} - -def der_urban (c: Char, r: Rexp) : Rexp = r match { - case ZERO => ZERO - case ONE => ZERO - case CHAR(d) => if (c == d) ONE else ZERO - case ALT(r1, r2) => ALT(der_urban(c, r1), der_urban(c, r2)) - case SEQ(r1, r2) => - if (nullable_urban(r1)) ALT(SEQ(der_urban(c, r1), r2), der_urban(c, r2)) - else SEQ(der_urban(c, r1), r2) - case STAR(r1) => SEQ(der_urban(c, r1), STAR(r1)) -} - -def simp_urban(r: Rexp) : Rexp = r match { - case ALT(r1, r2) => (simp_urban(r1), simp_urban(r2)) match { - case (ZERO, r2s) => r2s - case (r1s, ZERO) => r1s - case (r1s, r2s) => if (r1s == r2s) r1s else ALT (r1s, r2s) - } - case SEQ(r1, r2) => (simp_urban(r1), simp_urban(r2)) match { - case (ZERO, _) => ZERO - case (_, ZERO) => ZERO - case (ONE, r2s) => r2s - case (r1s, ONE) => r1s - case (r1s, r2s) => SEQ(r1s, r2s) - } - case r => r -} - -import scala.annotation.tailrec - -@tailrec -def iterT_urban[A](n: Int, f: A => A, x: A): A = - if (n == 0) x else iterT_urban(n - 1, f, f(x)) - - -lazy val f = Future { - assert(size(iterT_urban(20, (r: Rexp) => der_urban('a', r), EVIL_urban)) == 7340068) - assert(size(iterT_urban(20, (r: Rexp) => simp_urban(der_urban('a', r)), EVIL_urban)) == 8) -} - -Await.result(f, 90 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/re2c_test.scala --- a/marking/re2c_test.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - - - -lazy val f = Future { - assert(fixpT((x:Int) => if (200000 < x) x else x + 1, 0) == 200001) - assert(fixpT((x:Long) => if (20 < x) x else x + 1, 0L) == 21L) -} - -Await.result(f, 90 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/test --- a/marking/test Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -#!/bin/bash -set -e - -out=${1:-output-test} - - -function scala_vars { - (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) -} - - -# 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) -} - - - -# var, return, ListBuffer test -# -#echo "re.scala does not contain vars, returns etc?" | tee -a $out - -if (scala_vars re.scala) -then - #echo " --> fail" | tee -a $out - tsts0=$(( 1 )) -else - #echo " --> yes" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - #echo "re.scala runs?" | tee -a $out - - if (scala_compile re.scala.bak) - then - #echo " --> yes" | tee -a $out - tsts1=$(( 0 )) - else - #echo " --> scala re.scala did not run successfully" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - - -if [ $tsts1 -eq 0 ] -then - if (scala_assert "re.scala.bak" "../../../marking/re1d_test.scala") - then - echo " --> success" | tee -a $out - t1=$(( 1 )) - else - echo " --> test failed" | tee -a $out - t1=$(( 0 )) - fi -else - t1=$(( 0 )) -fi - -if [ $tsts1 -eq 0 ] -then - if (scala_assert "re.scala.bak" "../../../marking/re1d_bug_test.scala") - then - echo " bug --> success" | tee -a $out - t2=$(( 1 )) - else - echo " bug --> test failed" | tee -a $out - t2=$(( 0 )) - fi -else - t2=$(( 0 )) -fi - -if [ $t1 -ne $t2 ] -then - echo "disagree" - pwd -fi - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/trade_test1.scala --- a/marking/trade_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -//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)) - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/trade_test2.scala --- a/marking/trade_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -//println("starting test now") - -assert(get_page("GOOG").length >= 3087) -assert(get_page("AAPL").length >= 9064) -assert(get_page("FB").length >= 1135) - - diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/trade_test3.scala --- a/marking/trade_test3.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -//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) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking/trade_test4.scala --- a/marking/trade_test4.scala Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -//println("starting test now") - - -import scala.concurrent._ -import scala.concurrent.duration._ -import ExecutionContext.Implicits.global -import scala.language.postfixOps - -lazy val f = Future { - 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")) -} - -Await.result(f, 120 second) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/collatz_test.sh --- a/marking1/collatz_test.sh Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/collatz_test.sh Tue Oct 29 14:12:24 2019 +0000 @@ -11,7 +11,7 @@ echo `date` >> $out echo >> $out echo "Below is the feedback and provisional marks for your submission" >> $out -echo "for the Basic Part of Assignment 6. Please note all marks are provisional until" >> $out +echo "for the Preliminary Part of 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 @@ -31,7 +31,7 @@ # functional tests function scala_assert { - (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null) } # purity test diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/collatz_test1.scala --- a/marking1/collatz_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/collatz_test1.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,14 +1,8 @@ -def myassert(cond : => Boolean) = { - try { - assert(cond) - } catch { - case _ : Throwable => System.exit(1) - } -} -myassert(collatz(1) == 0) -myassert(collatz(6) == 8) -myassert(collatz(9) == 19) -myassert(collatz(9000) == 47) +assert(CW6a.collatz(1) == 0) +assert(CW6a.collatz(6) == 8) +assert(CW6a.collatz(9) == 19) +assert(CW6a.collatz(9000) == 47) + diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/collatz_test2.scala --- a/marking1/collatz_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/collatz_test2.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,23 +1,16 @@ -def myassert(cond : => Boolean) = { - try { - assert(cond) - } catch { - case _ : Throwable => System.exit(1) - } -} - -myassert(collatz_max(10) == (19, 9)) - -myassert(collatz_max(100) == (118, 97)) +//def myassert(cond : => Boolean) = { +// try { +// assert(cond) +// } catch { +// case _ : Throwable => System.exit(1) +// } +//} -myassert(collatz_max(1000) == (178, 871)) - -myassert(collatz_max(10000) == (261, 6171)) - -myassert(collatz_max(100000) == (350, 77031)) - -myassert(collatz_max(1000000) == (524, 837799)) - -myassert(collatz_max(2) == (1, 2)) - -myassert(collatz_max(77000) == (339, 52527)) +assert(CW6a.collatz_max(10) == (19, 9)) +assert(CW6a.collatz_max(100) == (118, 97)) +assert(CW6a.collatz_max(1000) == (178, 871)) +assert(CW6a.collatz_max(10000) == (261, 6171)) +assert(CW6a.collatz_max(100000) == (350, 77031)) +assert(CW6a.collatz_max(1000000) == (524, 837799)) +assert(CW6a.collatz_max(2) == (1, 2)) +assert(CW6a.collatz_max(77000) == (339, 52527)) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb.scala --- a/marking1/drumb.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,7 +1,7 @@ // Main Part about a really dumb investment strategy //====================================================== -//object CW6b { // for purposes of generating a jar +object CW6b { //two test portfolios @@ -167,7 +167,7 @@ //println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100)) //println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100)) -//} +} diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test.sh --- a/marking1/drumb_test.sh Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test.sh Tue Oct 29 14:12:24 2019 +0000 @@ -9,7 +9,7 @@ echo `date` >> $out echo >> $out echo "Below is the feedback and provisional marks for your submission" >> $out -echo "for the Main Part of Assignment 6 . Please note all marks are provisional until" >> $out +echo "for the Core Part of 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 @@ -32,7 +32,7 @@ # functional tests function scala_assert { - (ulimit -t 60; JAVA_OPTS="-Xmx4g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit -t 60; JAVA_OPTS="-Xmx4g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) } @@ -217,5 +217,5 @@ ## final marks echo >> $out -echo "Overall mark for CW 6, Main Part" | tee -a $out +echo "Overall mark for CW 6, Core Part" | tee -a $out echo "$marks" | tee -a $out diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test1.scala --- a/marking1/drumb_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test1.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,12 +1,12 @@ -def myassert(cond : => Boolean) = { +/*def myassert(cond : => Boolean) = { try { assert(cond) } catch { case _ : Throwable => System.exit(1) } } - -myassert(get_january_data("GOOG", 1980) == List()) +*/ -myassert(get_january_data("GOOG", 2010).head == "2010-01-04,312.204773") +assert(CW6b.get_january_data("GOOG", 1980) == List()) +assert(CW6b.get_january_data("GOOG", 2010).head == "2010-01-04,312.204773") diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test2.scala --- a/marking1/drumb_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test2.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,12 +1,12 @@ -def myassert(cond : => Boolean) = { +/*def myassert(cond : => Boolean) = { try { assert(cond) } catch { case _ : Throwable => System.exit(1) } } - -myassert(get_first_price("GOOG", 1980) == None) +*/ -myassert(get_first_price("GOOG", 2010) == Some(312.204773)) +assert(CW6b.get_first_price("GOOG", 1980) == None) +assert(CW6b.get_first_price("GOOG", 2010) == Some(312.204773)) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test2.sh --- a/marking1/drumb_test2.sh Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -#!/bin/bash -set -euo pipefail - - -out=${1:-output} - -echo "" > $out - -echo "Below is the feedback and provisional marks for your submission" >> $out -echo "for assignment 6 Advanced 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 CW6 part 3 -marks=$(( 0 )) - - -# compilation tests - -function scala_compile { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null) -} - -# 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 "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out - -if (scala_vars drumb.scala) -then - echo " --> test failed" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> success" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - echo "drumb.scala runs?" | tee -a $out - - if (scala_compile drumb.scala) - then - echo " --> success" | tee -a $out - tsts=$(( 0 )) - else - echo " --> scala drumb.scala did not run successfully" | tee -a $out - tsts=$(( 1 )) - fi -else - tsts=$(( 1 )) -fi - - -### get_delta test - -if [ $tsts -eq 0 ] -then - echo " get_delta(None, None) == None" | tee -a $out - echo " get_delta(Some(50.0), None) == None" | tee -a $out - echo " get_delta(None, Some(100.0)) == None" | tee -a $out - echo " get_delta(Some(50.0), Some(100.0)) == Some(1.0)" | tee -a $out - - if (scala_assert "drumb.scala" "drumb_test4.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - -### get_deltas_test - -if [ $tsts -eq 0 ] -then - echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out - echo -e " List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " | tee -a $out - echo -e " List(Some(0.10103412653643493), Some(0.24777709700099845)))" | tee -a $out - echo -e "" | tee -a $out - echo -e " get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " | tee -a $out - echo -e " List(List(None), List(None), " | tee -a $out - echo -e " List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " | tee -a $out - - if (scala_assert "drumb.scala" "drumb_test5.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - -### yield_tests - -if [ $tsts -eq 0 ] -then - echo -e " val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out - echo -e " yearly_yield(get_deltas(ds, 100, 0)) == 125" | tee -a $out - echo -e " yearly_yield(get_deltas(ds, 100, 1)) == 117" | tee -a $out - - if (scala_assert "drumb.scala" "drumb_test6.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> test failed" | tee -a $out - fi -fi - - -### investment_test - -if [ $tsts -eq 0 ] -then - echo -e " All results need to be in the range of -/+ 1% of the given values." | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 83061" | tee -a $out - - - if (scala_assert "drumb.scala" "drumb_test7.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - 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 a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test3.scala --- a/marking1/drumb_test3.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test3.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,17 +1,17 @@ -def myassert(cond : => Boolean) = { +/*def myassert(cond : => Boolean) = { try { assert(cond) } catch { case _ : Throwable => System.exit(1) } } - -myassert(get_prices(List("BIDU"), 2004 to 2008) == +*/ +assert(CW6b.get_prices(List("BIDU"), 2004 to 2008) == List(List(None), List(None), List(Some(6.35)), List(Some(12.241)), List(Some(38.188)))) -myassert(get_prices(List("GOOG", "AAPL"), 2010 to 2012) == +assert(CW6b.get_prices(List("GOOG", "AAPL"), 2010 to 2012) == List(List(Some(312.204773), Some(26.782711)), List(Some(301.0466), Some(41.244694)), List(Some(331.462585), Some(51.464207)))) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test4.scala --- a/marking1/drumb_test4.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test4.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,12 +1,6 @@ -def myassert(cond : => Boolean) = { - try { - assert(cond) - } catch { - case _ : Throwable => System.exit(1) - } -} + -myassert(get_delta(None, None) == None) -myassert(get_delta(Some(50.0), None) == None) -myassert(get_delta(None, Some(100.0)) == None) -myassert(get_delta(Some(50.0), Some(100.0)) == Some(1.0)) +assert(CW6b.get_delta(None, None) == None) +assert(CW6b.get_delta(Some(50.0), None) == None) +assert(CW6b.get_delta(None, Some(100.0)) == None) +assert(CW6b.get_delta(Some(50.0), Some(100.0)) == Some(1.0)) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test5.scala --- a/marking1/drumb_test5.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test5.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,18 +1,18 @@ -def myassert(cond : => Boolean) = { +/*def myassert(cond : => Boolean) = { try { assert(cond) } catch { case _ : Throwable => System.exit(1) } } - +*/ // get_prices(List("GOOG", "AAPL"), 2010 to 2012) val urban_prices = List(List(Some(312.204773), Some(26.782711)), List(Some(301.0466), Some(41.244694)), List(Some(331.462585), Some(51.464207))) -myassert(get_deltas(urban_prices) == List(List(Some(-0.03573991804411003), Some(0.539974575389325)), +assert(CW6b.get_deltas(urban_prices) == List(List(Some(-0.03573991804411003), Some(0.539974575389325)), List(Some(0.10103414222249969), Some(0.24777764141006836)))) @@ -22,6 +22,6 @@ List(Some(38.188))) -myassert(get_deltas(urban_prices2) == List(List(None), List(None), +assert(CW6b.get_deltas(urban_prices2) == List(List(None), List(None), List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test6.scala --- a/marking1/drumb_test6.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test6.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,5 +1,5 @@ //val urban_deltas = get_deltas(get_prices(List("GOOG", "AAPL"), 2010 to 2012)) - +/* def myassert(cond : => Boolean) = { try { assert(cond) @@ -7,12 +7,12 @@ case _ : Throwable => System.exit(1) } } - +*/ val ds_urban = List(List(Some(-0.03573991804411003), Some(0.539974575389325)), List(Some(0.10103414222249969), Some(0.24777764141006836))) -myassert(yearly_yield(ds_urban, 100, 0) == 125) -myassert(yearly_yield(ds_urban, 100, 1) == 117) +assert(CW6b.yearly_yield(ds_urban, 100, 0) == 125) +assert(CW6b.yearly_yield(ds_urban, 100, 1) == 117) diff -r a057dc4457fc -r 87b9e3e2c1a7 marking1/drumb_test7.scala --- a/marking1/drumb_test7.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/marking1/drumb_test7.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,3 +1,4 @@ +/* def myassert(cond : => Boolean) = { try { assert(cond) @@ -5,14 +6,14 @@ case _ : Throwable => System.exit(1) } } - +*/ -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100) == 100) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100) == 27) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) == 42) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) == 27) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) == 38) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) == 113) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2006, 100) == 254) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2007, 100) == 349) -myassert(investment(List("GOOG", "AAPL", "BIDU"), 1990 to 2017, 100) == 11504) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100) == 100) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100) == 27) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) == 42) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) == 27) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) == 38) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) == 113) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2006, 100) == 254) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2007, 100) == 349) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 1990 to 2017, 100) == 11504) diff -r a057dc4457fc -r 87b9e3e2c1a7 style.sty --- a/style.sty Tue Oct 29 11:11:44 2019 +0000 +++ b/style.sty Tue Oct 29 14:12:24 2019 +0000 @@ -34,18 +34,18 @@ \makeatother % CW deadlines -\def\cwSIX{13 November} -\def\cwSIXa{8 January} +\def\cwSIX{14 November} +\def\cwSIXa{15 January} -\def\cwSEVEN{20 November} -\def\cwSEVENa{8 January} +\def\cwSEVEN{21 November} +\def\cwSEVENa{15 January} -\def\cwEIGHT{27 November} -\def\cwEIGHTa{8 January} +\def\cwEIGHT{28 November} +\def\cwEIGHTa{15 January} -\def\cwNINE{4 December} -\def\cwNINEa{8 January} +\def\cwNINE{5 December} +\def\cwNINEa{15 January} -\def\cwTEN{8 January} -\def\cwTENa{8 January} +\def\cwTEN{15 January} +\def\cwTENa{15 January} diff -r a057dc4457fc -r 87b9e3e2c1a7 templates1/collatz.scala --- a/templates1/collatz.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/templates1/collatz.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,6 +1,7 @@ // Basic Part about the 3n+1 conjecture //====================================== +object CW6a { //(1) Complete the collatz function below. It should // recursively calculate the number of steps needed @@ -23,5 +24,5 @@ //def collatz_max(bnd: Long) : (Long, Long) = ... +} - diff -r a057dc4457fc -r 87b9e3e2c1a7 templates1/drumb.scala --- a/templates1/drumb.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/templates1/drumb.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,6 +1,7 @@ -// Main Part about a really dumb investment strategy +// Core Part about a really dumb investment strategy //=================================================== +object CW6b { //two test portfolios @@ -81,3 +82,4 @@ //println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100)) +} diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/collatz.scala --- a/testing1/collatz.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/collatz.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,8 +1,11 @@ // Part 1 about the 3n+1 conjecture //================================== +// generate jar with +// > scala -d collatz.jar collatz.scala -//object CW6a { // for purposes of generating a jar +object CW6a { + def collatz(n: Long): Long = if (n == 1) 0 else @@ -15,6 +18,7 @@ all.maxBy(_._1) } + /* some test cases val bnds = List(10, 100, 1000, 10000, 100000, 1000000) @@ -25,4 +29,8 @@ */ -//} + +} + + + diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/collatz_test.sh --- a/testing1/collatz_test.sh Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/collatz_test.sh Tue Oct 29 14:12:24 2019 +0000 @@ -21,7 +21,7 @@ # 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 diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/collatz_test1.scala --- a/testing1/collatz_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/collatz_test1.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,9 +1,8 @@ +import CW6a._ -assert(collatz(1) == 0) - +assert(collatz(1) == 0) assert(collatz(6) == 8) - assert(collatz(9) == 19) diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/collatz_test2.scala --- a/testing1/collatz_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/collatz_test2.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,13 +1,8 @@ - +import CW6a._ assert(collatz_max(10) == (19, 9)) - assert(collatz_max(100) == (118, 97)) - assert(collatz_max(1000) == (178, 871)) - assert(collatz_max(10000) == (261, 6171)) - assert(collatz_max(100000) == (350, 77031)) - assert(collatz_max(1000000) == (524, 837799)) diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb.scala --- a/testing1/drumb.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,7 +1,7 @@ -// Part 2 and 3 about a really dumb investment strategy +// Main Part about a really dumb investment strategy //====================================================== -//object CW6b { // for purposes of generating a jar +object CW6b { //two test portfolios @@ -73,16 +73,13 @@ //test cases -//val p_fb = get_prices(List("FB"), 2012 to 2014) -//val p = get_prices(List("GOOG", "AAPL"), 2010 to 2012) - -//val tt = get_prices(List("BIDU"), 2004 to 2008) +//println("Task 3 data from Google and Apple in 2010 to 2012") +//val goog_aapl_prices = get_prices(List("GOOG", "AAPL"), 2010 to 2012) +//println(goog_aapl_prices.toString ++ "\n") -//============================================== -// Do not change anything below, unless you want -// to submit the file for the advanced part 3! -//============================================== +//val p_fb = get_prices(List("FB"), 2012 to 2014) +//val tt = get_prices(List("BIDU"), 2004 to 2008) // (4) The function below calculates the change factor (delta) between @@ -105,8 +102,13 @@ for (j <- (0 until (data(0).length)).toList) yield get_delta(data(i)(j), data(i + 1)(j)) + // test case using the prices calculated above -//val d = get_deltas(p) + +//println("Task 5 change prices from Google and Apple in 2010 and 2011") +//val goog_aapl_deltas = get_deltas(goog_aapl_prices) +//println(goog_aapl_deltas.toString ++ "\n") + //val ttd = get_deltas(tt) @@ -124,6 +126,21 @@ } } +// test case using the deltas calculated above +//println("Task 6 yield from Google and Apple in 2010 with balance 100") + +//val d0 = goog_aapl_deltas(0)(0) +//val d1 = goog_aapl_deltas(0)(1) +//println(s"50 * ${d0.get} + 50 * ${d1.get} = ${50.toDouble * d0.get + 50.toDouble * d1.get}") + + +//val goog_aapl_yield = yearly_yield(goog_aapl_deltas, 100, 0) +//println("Rounded yield: " ++ goog_aapl_yield.toString ++ "\n") + + +//yearly_yield(get_prices(rstate_portfolio, 2016 to 2018), 100, 2) +//get_prices(rstate_portfolio, 2016 to 2018)(2).flatten.sum + // (7) Write a function compound_yield that calculates the overall balance for a // range of years where in each year the yearly profit is compounded to the new @@ -147,21 +164,10 @@ //test cases for the two portfolios given above -//println("Real data: " + investment(rstate_portfolio, 1978 to 2018, 100)) -//println("Blue data: " + investment(blchip_portfolio, 1978 to 2018, 100)) +//println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100)) +//println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100)) -//} +} -//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 a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test.sh --- a/testing1/drumb_test.sh Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test.sh Tue Oct 29 14:12:24 2019 +0000 @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -euo pipefail out=${1:-output} @@ -17,7 +17,7 @@ # 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 @@ -33,7 +33,7 @@ if (scala_vars drumb.scala) then - echo " --> fail (make triple-sure your program conforms to the required format)" >> $out + echo " --> FAIL (make triple-sure your program conforms to the required format)" >> $out tsts0=$(( 0 )) else echo " --> success" >> $out @@ -51,7 +51,7 @@ echo " --> success" >> $out tsts=$(( 0 )) else - echo " --> scala did not run drumb.scala" >> $out + echo " --> SCALA DID NOT RUN drumb.scala" >> $out tsts=$(( 1 )) fi else @@ -63,13 +63,13 @@ 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 + echo " get_january_data(\"GOOG\", 2010).head == \"2010-01-04,312.204773\"" >> $out if (scala_assert "drumb.scala" "drumb_test1.scala") then echo " --> success" >> $out else - echo " --> test failed" >> $out + echo " --> ONE OF THE TESTS FAILED\n" >> $out fi fi @@ -78,13 +78,13 @@ if [ $tsts -eq 0 ] then echo " get_first_price(\"GOOG\", 1980) == None" >> $out - echo " get_first_price(\"GOOG\", 2010) == Some(311.349976)" >> $out + echo " get_first_price(\"GOOG\", 2010) == Some(312.204773)" >> $out if (scala_assert "drumb.scala" "drumb_test2.scala") then echo " --> success" >> $out else - echo " --> test failed" >> $out + echo " --> ONE OF THE TESTS FAILED\n" >> $out fi fi @@ -93,49 +93,95 @@ 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 + 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 + echo " --> ONE OF THE TESTS FAILED\n" >> $out fi fi +### get_delta_test + +if [ $tsts -eq 0 ] +then + echo " get_delta(None, None) == None" >> $out + echo " get_delta(Some(50.0), None) == None" >> $out + echo " get_delta(None, Some(100.0)) == None" >> $out + echo " get_delta(Some(50.0), Some(100.0)) == Some(1.0)" >> $out + + if (scala_assert "drumb.scala" "drumb_test4.scala") + then + echo " --> success" >> $out + else + echo " --> ONE OF THE TESTS FAILED\n" >> $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 +if [ $tsts -eq 0 ] +then + echo -e " get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out + echo -e " List(List(Some(-0.03573991804411003), Some(0.539974575389325)), " >> $out + echo -e " List(Some(0.10103414222249969), Some(0.24777764141006836)))" >> $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 " --> success" >> $out + else + echo " --> ONE OF THE TESTS FAILED\n" >> $out + fi +fi -### yield_tests, investment_test +### 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(ds, 100, 0)) == 125" >> $out + echo -e " yearly_yield(get_deltas(ds, 100, 1)) == 117" >> $out + + if (scala_assert "drumb.scala" "drumb_test6.scala") + then + echo " --> success" >> $out + else + echo " --> ONE OF THE TESTS FAILED\n" >> $out + fi +fi + + +### 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 +if [ $tsts -eq 0 ] +then + echo -e " All results need to be in the range of -/+ 1% of the given values." >> $out + 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 + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 11504" >> $out + + + if (scala_assert "drumb.scala" "drumb_test7.scala") + then + echo " --> success" >> $out + else + echo " --> ONE OF THE TESTS FAILED\n" >> $out + fi +fi diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test1.scala --- a/testing1/drumb_test1.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test1.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,7 +1,5 @@ - -assert(get_january_data("GOOG", 1980) == List()) - -assert(get_january_data("GOOG", 2010).head == "2010-01-04,311.349976") +assert(CW6b.get_january_data("GOOG", 1980) == List()) +assert(CW6b.get_january_data("GOOG", 2010).head == "2010-01-04,312.204773") diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test2.scala --- a/testing1/drumb_test2.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test2.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,141 +1,12 @@ -#!/bin/bash -set -e - -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) -} - -# purity test - -function scala_vars { - (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) +/*def myassert(cond : => Boolean) = { + try { + assert(cond) + } catch { + case _ : Throwable => System.exit(1) + } } - - -# 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 +assert(CW6b.get_first_price("GOOG", 1980) == None) +assert(CW6b.get_first_price("GOOG", 2010) == Some(312.204773)) - 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 a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test2.sh --- a/testing1/drumb_test2.sh Tue Oct 29 11:11:44 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -#!/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 "$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) -} - -# 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(ds, 100, 0) == 125" >> $out - echo -e " yearly_yield(get_deltas(ds, 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 a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test3.scala --- a/testing1/drumb_test3.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test3.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,3 +1,4 @@ +import CW6b._ assert(get_prices(List("GOOG", "AAPL"), 2010 to 2012) == List(List(Some(311.349976), Some(20.544939)), diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test4.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing1/drumb_test4.scala Tue Oct 29 14:12:24 2019 +0000 @@ -0,0 +1,6 @@ + + +assert(CW6b.get_delta(None, None) == None) +assert(CW6b.get_delta(Some(50.0), None) == None) +assert(CW6b.get_delta(None, Some(100.0)) == None) +assert(CW6b.get_delta(Some(50.0), Some(100.0)) == Some(1.0)) diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test5.scala --- a/testing1/drumb_test5.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test5.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,12 +1,19 @@ - +/*def myassert(cond : => Boolean) = { + try { + assert(cond) + } catch { + case _ : Throwable => System.exit(1) + } +} +*/ // 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))) +val urban_prices = List(List(Some(312.204773), Some(26.782711)), + List(Some(301.0466), Some(41.244694)), + List(Some(331.462585), Some(51.464207))) -assert(get_deltas(urban_prices) == List(List(Some(-0.03573992567129673), Some(0.539975124774038)), - List(Some(0.10103412653643493), Some(0.24777709700099845)))) +assert(CW6b.get_deltas(urban_prices) == List(List(Some(-0.03573991804411003), Some(0.539974575389325)), + List(Some(0.10103414222249969), Some(0.24777764141006836)))) //get_prices(List("BIDU"), 2004 to 2008) @@ -15,6 +22,6 @@ List(Some(38.188))) -assert(get_deltas(urban_prices2) == List(List(None), List(None), +assert(CW6b.get_deltas(urban_prices2) == List(List(None), List(None), List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test6.scala --- a/testing1/drumb_test6.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test6.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,9 +1,18 @@ //val urban_deltas = get_deltas(get_prices(List("GOOG", "AAPL"), 2010 to 2012)) +/* +def myassert(cond : => Boolean) = { + try { + assert(cond) + } catch { + case _ : Throwable => System.exit(1) + } +} +*/ -val ds_urban = List(List(Some(-0.03573992567129673), Some(0.539975124774038)), - List(Some(0.10103412653643493), Some(0.24777709700099845))) +val ds_urban = List(List(Some(-0.03573991804411003), Some(0.539974575389325)), + List(Some(0.10103414222249969), Some(0.24777764141006836))) -assert(yearly_yield(ds_urban, 100, 0) == 125) -assert(yearly_yield(ds_urban, 100, 1) == 117) +assert(CW6b.yearly_yield(ds_urban, 100, 0) == 125) +assert(CW6b.yearly_yield(ds_urban, 100, 1) == 117) diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb_test7.scala --- a/testing1/drumb_test7.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb_test7.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,9 +1,24 @@ +/* +def myassert(cond : => Boolean) = { + try { + assert(cond) + } catch { + case _ : Throwable => System.exit(1) + } +} +*/ -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) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100) == 100) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100) == 27) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) == 42) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) == 27) +assert(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) == 38) + +// 113 +assert((112 to 114).contains(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100))) +// 254 +assert((252 to 256).contains(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2006, 100))) +// 349 +assert((346 to 352).contains(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2007, 100))) +//11504 +assert((11389 to 11619).contains(CW6b.investment(List("GOOG", "AAPL", "BIDU"), 1990 to 2017, 100)))