# HG changeset patch # User Christian Urban # Date 1482026478 0 # Node ID fac25de665d2b9248dcfe534b6c3e372a751f62a # Parent 990a1531135d119a8ee482be604e9150a423e470 updated diff -r 990a1531135d -r fac25de665d2 README --- a/README Fri Dec 16 13:34:33 2016 +0000 +++ b/README Sun Dec 18 02:01:18 2016 +0000 @@ -6,4 +6,14 @@ deleting comments from scala files -find . -name '*.scala' -print0 | xargs -0 perl -n -p -0 -i.bak -e 's%/\*([^*].*?)?\*/%%gs;s%^([^\"\n\r]*(\"[^\"\n\r]*\"[^\"\n\r]*?)*?)//([^*\n\r].*)?$%$1%gm' \ No newline at end of file +find . -name '*.scala' -print0 | xargs -0 perl -n -p -0 -i.bak -e 's%/\*([^*].*?)?\*/%%gs;s%^([^\"\n\r]*(\"[^\"\n\r]*\"[^\"\n\r]*?)*?)//([^*\n\r].*)?$%$1%gm' + + +find . -name '*.scala' -print0 | sed -i.2 's|def ordered_moves(dim: Int, path: Path, x: Pos): List[Pos] = ..|//def ordered_moves(dim: Int, path: Path, x: Pos): List[Pos] = ..|g' + + +LC_ALL=C sed -i.2 -- 's|def ordered_moves(dim: Int, path: Path, x: Pos): List\[Pos\] = \.\.|//def ordered_moves(dim: Int, path: Path, x: Pos): List[Pos] = ..|g' k*/knight3.scala.bak + +LC_ALL=C sed -i.2 -- 's|def first_closed_tour_heuristic(dim: Int, path: Path): Option\[Path\] = \.\.\.|//def first_closed_tour_heuristic(dim: Int, path: Path): Option[Path] = ...|g' k*/knight3.scala.bak + +LC_ALL=C sed -i.2 -- 's|def first_tour_heuristic(dim: Int, path: Path): Option\[Path\] = \.\.\.|//def first_tour_heuristic(dim: Int, path: Path): Option[Path] = ...|g' k*/knight3.scala.bak \ No newline at end of file diff -r 990a1531135d -r fac25de665d2 marking/knight3c_test.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marking/knight3c_test.scala Sun Dec 18 02:01:18 2016 +0000 @@ -0,0 +1,45 @@ + +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 990a1531135d -r fac25de665d2 marking/mark02b --- a/marking/mark02b Fri Dec 16 13:34:33 2016 +0000 +++ b/marking/mark02b Sun Dec 18 02:01:18 2016 +0000 @@ -93,6 +93,19 @@ 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 diff -r 990a1531135d -r fac25de665d2 marking/mark03a --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marking/mark03a Sun Dec 18 02:01:18 2016 +0000 @@ -0,0 +1,113 @@ +#!/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 )) + + +# 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