# HG changeset patch # User Christian Urban # Date 1509883329 0 # Node ID dcaab8068baa2cece899860166cda2293fd199a8 # Parent c45d3cd9a7498a0d49ca37ce711c0c96b98243f4 updated diff -r c45d3cd9a749 -r dcaab8068baa cws/cw01.pdf Binary file cws/cw01.pdf has changed diff -r c45d3cd9a749 -r dcaab8068baa cws/cw01.tex --- a/cws/cw01.tex Sat Nov 04 16:17:19 2017 +0000 +++ b/cws/cw01.tex Sun Nov 05 12:02:09 2017 +0000 @@ -7,7 +7,7 @@ \section*{Coursework 6 (Scala)} This coursework is about Scala and is worth 10\%. The first and second -part are due on 16 November at 11pm, and the third part on ??? November +part are due on 16 November at 11pm, and the third part on 21 December at 11pm. You are asked to implement three programs about list processing and recursion. The third part is more advanced and might include material you have not yet seen in the first lecture. diff -r c45d3cd9a749 -r dcaab8068baa handouts/pep-ho.pdf Binary file handouts/pep-ho.pdf has changed diff -r c45d3cd9a749 -r dcaab8068baa handouts/pep-ho.tex --- a/handouts/pep-ho.tex Sat Nov 04 16:17:19 2017 +0000 +++ b/handouts/pep-ho.tex Sun Nov 05 12:02:09 2017 +0000 @@ -8,7 +8,7 @@ \begin{document} -\section*{A Crash-Course on Scala} +\section*{A Crash-Course in Scala} \subsection*{The Very Basics} @@ -40,7 +40,7 @@ \noindent indicating that the result of the addition is of type \code{Int} and the actual result is 5; \code{res0} is a name that -Scala gives automatically to the result. Yoy can reuse this name later +Scala gives automatically to the result. You can reuse this name later on. Another classic example you can try out is \begin{lstlisting}[numbers=none] diff -r c45d3cd9a749 -r dcaab8068baa marking/mark02b --- a/marking/mark02b Sat Nov 04 16:17:19 2017 +0000 +++ b/marking/mark02b Sun Nov 05 12:02:09 2017 +0000 @@ -1,4 +1,4 @@ -#!/bin/bash +=-p#!/bin/bash set -e out=${1:-output} @@ -33,7 +33,7 @@ # marks for CW2b marks=$(( 0 )) - +lm # knights3: var, comments test # echo "knight3.scala does not contain vars, returns etc?" | tee -a $out diff -r c45d3cd9a749 -r dcaab8068baa marking/mark03a --- a/marking/mark03a Sat Nov 04 16:17:19 2017 +0000 +++ b/marking/mark03a Sun Nov 05 12:02:09 2017 +0000 @@ -19,14 +19,14 @@ # compilation tests function scala_compile { - (scala "$1" 2> /dev/null 1> /dev/null) + (ulimit -t 1 ; scala "$1" 1> $out 2> $out) } # functional tests function scala_assert { - (scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit - t 1; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) } diff -r c45d3cd9a749 -r dcaab8068baa progs/lecture1.scala --- a/progs/lecture1.scala Sat Nov 04 16:17:19 2017 +0000 +++ b/progs/lecture1.scala Sun Nov 05 12:02:09 2017 +0000 @@ -13,6 +13,28 @@ // (you cannot reassign values: z = 9 will give an error) + +// Hello World +//============= + +// an example of a stand-alone scala file; +// in the coursework students must submit +// plain scala "work-sheets" + +object Hello extends App { + println("hello world") +} + +// can be called with +// +// $> scalac hello-world.scala +// $> scala Hello +// +// $> java -cp /usr/local/src/scala/lib/scala-library.jar:. Hello + + + + // Collections //============= List(1,2,3,1) @@ -126,24 +148,6 @@ val t = (4,1,2,3) t._4 -// Hello World -//============= - -// an example of a stand-alone scala file; -// in the coursework students must submit -// plain scala "work-sheets" - -object Hello extends App { - println("hello world") -} - -// can be called with -// -// $> scalac hello-world.scala -// $> scala Hello -// -// $> java -cp /usr/local/src/scala/lib/scala-library.jar:. Hello - // Function Definitions //====================== diff -r c45d3cd9a749 -r dcaab8068baa testing/collatz_test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/collatz_test Sun Nov 05 12:02:09 2017 +0000 @@ -0,0 +1,101 @@ +#!/bin/bash + +# to make the script fail safely +set -euo pipefail + + +out=${1:-output} + +echo "" > $out + +echo "Below is the feedback for your submission" >> $out +echo "" >> $out + + +# compilation tests + +function scala_compile { + (ulimit -t 30 -m 1024000 ; scala "$1" 2> $out 1> $out) +} + +# functional tests + +function scala_assert { + (ulimit -t 30 -m 1024000 ; 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) +} + + +# var, .par return, ListBuffer test +# +echo "collatz.scala does not contain vars, returns etc?" >> $out + +if (scala_vars collatz.scala) +then + echo " --> fail" >> $out + tsts0=$(( 1 )) +else + echo " --> yes" >> $out + tsts0=$(( 0 )) +fi + +### compilation test + + +if [ $tsts0 -eq 0 ] +then + echo "collatz.scala runs?" >> $out + + if (scala_compile collatz.scala) + then + echo " --> success" >> $out + tsts=$(( 0 )) + else + echo " --> scala did not run collatz.scala" >> $out + tsts=$(( 1 )) + fi +else + tsts=$(( 1 )) +fi + +### collatz tests + +if [ $tsts -eq 0 ] +then + echo " collatz(1) == 0,1 or 4" >> $out + echo " collatz(6) == 9" >> $out + echo " collatz(9) == 20" >> $out + + if (scala_assert "collatz.scala" "collatz_test1.scala") + then + echo " --> success" >> $out + else + echo " --> one of the tests failed" >> $out + fi +fi + +### collatz-max tests + +if [ $tsts -eq 0 ] +then + echo " collatz_max(10) == (9, 20)" >> $out + echo " collatz_max(100) == (97, 119)" >> $out + echo " collatz_max(1000) == (871, 179)" >> $out + echo " collatz_max(10000) == (6171, 262)" >> $out + echo " collatz_max(100000) == (77031, 351)" >> $out + echo " collatz_max(1000000) == (837799, 525)" >> $out + + if (scala_assert "collatz.scala" "collatz_test2.scala") + then + echo " --> success" >> $out + else + echo " --> one of the tests failed" >> $out + fi +fi + + diff -r c45d3cd9a749 -r dcaab8068baa testing/collatz_test1.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/collatz_test1.scala Sun Nov 05 12:02:09 2017 +0000 @@ -0,0 +1,8 @@ + +assert(List(0,1,4).contains(collatz(1))) + +assert(collatz(6) == 9) + +assert(collatz(9) == 20) + + diff -r c45d3cd9a749 -r dcaab8068baa testing/collatz_test2.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/collatz_test2.scala Sun Nov 05 12:02:09 2017 +0000 @@ -0,0 +1,13 @@ + + +assert(collatz_max(10) == (9, 20)) + +assert(collatz_max(100) == (97, 119)) + +assert(collatz_max(1000) == (871, 179)) + +assert(collatz_max(10000) == (6171, 262)) + +assert(collatz_max(100000) == (77031, 351)) + +assert(collatz_max(1000000) == (837799, 525)) diff -r c45d3cd9a749 -r dcaab8068baa testing/mark --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/mark Sun Nov 05 12:02:09 2017 +0000 @@ -0,0 +1,8 @@ +#!/bin/sh +###set -e + +trap "exit" INT + +./collatz_test output1 + +