# HG changeset patch # User Christian Urban # Date 1586517168 -3600 # Node ID 24bc76d97db21c7c5b0d968db255f2aae4c1f81e # Parent 703c7e42bf468e2576b48858c47688d9cec050a6 updated diff -r 703c7e42bf46 -r 24bc76d97db2 Attic/bfc_test.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Attic/bfc_test.sh Fri Apr 10 12:12:48 2020 +0100 @@ -0,0 +1,156 @@ +#!/bin/bash + +# to make the script fail safely +set -euo pipefail + + +out=${1:-output} + +echo "" > $out + + +echo "Below is the feedback and provisional marks for your submission" >> $out +echo "for assignment 10 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 + +# marks for CW10 part 2 +marks=$(( 0 )) + +# compilation tests + +function scala_compile { + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) +} + +# functional tests + +function scala_assert { + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 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, return, ListBuffer test +# +echo "bfc.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out + +if (scala_vars bfc.scala) +then + echo " --> FAIL (make triple-sure your program conforms to the required format)" | tee -a $out + tsts0=$(( 1 )) +else + echo " --> success" | tee -a $out + tsts0=$(( 0 )) +fi + + +# compilation test +if [ $tsts0 -eq 0 ] +then + echo "bfc.scala runs?" | tee -a $out + + if (scala_compile bfc.scala) + then + echo " --> success" | tee -a $out + tsts1=$(( 0 )) + else + echo " --> SCALA DID NOT RUN BFC.SCALA\n" | tee -a $out + tsts1=$(( 1 )) + fi +else + tsts1=$(( 1 )) +fi + + +### bfc5 test + +if [ $tsts1 -eq 0 ] +then + echo -e " val p1 = \"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\"" | tee -a $out + echo -e " jtable(p1) == Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" | tee -a $out + echo -e " val p2 = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " jtable(p2) == Map(14 -> 34, 33 -> 15, 45 -> 44, 48 -> 9, 43 -> 46, 8 -> 49)" | tee -a $out + echo -e " run2(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out + echo -e " run2(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out + echo -e " run2(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out + echo -e " run2(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out + echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out + echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out + echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " run2(hello, Map()) == " | tee -a $out + echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out + + if (scala_assert "bfc.scala" "bf_test5.scala") + then + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) + else + echo " --> \n ONE TEST FAILED\n" | tee -a $out + fi +fi + + +### bfc6 test + +if [ $tsts1 -eq 0 ] +then + echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" | tee -a $out + echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" | tee -a $out + echo -e " run3(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out + echo -e " run3(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out + echo -e " run3(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out + echo -e " run3(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out + echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out + echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out + echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " run3(hello, Map()) == " | tee -a $out + echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out + + if (scala_assert "bfc.scala" "bf_test6.scala") + then + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) + else + echo " --> \n ONE TEST FAILED\n" | tee -a $out + fi +fi + +### bfc7 test + +if [ $tsts1 -eq 0 ] +then + echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" | tee -a $out + echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" | tee -a $out + echo -e " run4(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out + echo -e " run4(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out + echo -e " run4(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out + echo -e " run4(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out + echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out + echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out + echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " run4(hello, Map()) == " | tee -a $out + echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out + + if (scala_assert "bfc.scala" "bf_test7.scala") + then + echo " --> success" | tee -a $out + marks=$(( marks + 2 )) + else + echo " --> \n ONE TEST FAILED\n" | tee -a $out + fi +fi + + +## final marks +echo "Overall mark for CW 10, Part 2" | tee -a $out +echo "$marks" | tee -a $out + diff -r 703c7e42bf46 -r 24bc76d97db2 Attic/mk-bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Attic/mk-bf Fri Apr 10 12:12:48 2020 +0100 @@ -0,0 +1,28 @@ +#!/bin/sh +###set -e + +trap "exit" INT + +files=${1:-assignment201810-*} + +for sd in $files; do + cd $sd + echo $sd + touch . + cp ../../../marking5/bf_test.sh . + cp ../../../marking5/bf_test1.scala . + cp ../../../marking5/bf_test2.scala . + cp ../../../marking5/bf_test3.scala . + cp ../../../marking5/bf_test4.scala . + cp ../../../marking5/benchmark.bf . + ./bf_test.sh output + rm bf_test.sh + rm bf_test1.scala + rm bf_test2.scala + rm bf_test3.scala + rm bf_test4.scala + rm benchmark.bf + cd .. +done + + diff -r 703c7e42bf46 -r 24bc76d97db2 README --- a/README Wed Feb 05 12:24:27 2020 +0000 +++ b/README Fri Apr 10 12:12:48 2020 +0100 @@ -1,3 +1,29 @@ +Wartremover + +./wartremover -traverser org.wartremover.warts.Return -traverser org.wartremover.warts.Var -traverser org.wartremover.warts.MutableDataStructures $i + + +compilation + +git clone https://github.com/wartremover/wartremover.git +sbt "++ 2.13.1" core/assembly + + +====================== + + +./dff > sort | more +./dff | sort > d + + +Repeating commands for data in a file: + +input="d" + +while IFS= read -r file; do opendiff some_copy "$file"; done < "$input" + +---------------------------- + Decompilation diff -r 703c7e42bf46 -r 24bc76d97db2 cws/cw02.tex --- a/cws/cw02.tex Wed Feb 05 12:24:27 2020 +0000 +++ b/cws/cw02.tex Fri Apr 10 12:12:48 2020 +0100 @@ -230,7 +230,9 @@ \item[(2)] Implement two functions that process the (broken up) CSV-files from (1). The \pcode{process_ratings} function filters out all ratings below 4 and returns a list of (userID, movieID) pairs. The - \pcode{process_movies} function returns a list of (movieID, title) pairs.\\ + \pcode{process_movies} function returns a list of (movieID, title) pairs. + Note the input to these functions will be the output of the function + \pcode{get_csv_url}.\\ \mbox{}\hfill [1 Mark] %\end{itemize} % diff -r 703c7e42bf46 -r 24bc76d97db2 handouts/pep-ho.pdf Binary file handouts/pep-ho.pdf has changed diff -r 703c7e42bf46 -r 24bc76d97db2 handouts/pep-ho.tex --- a/handouts/pep-ho.tex Wed Feb 05 12:24:27 2020 +0000 +++ b/handouts/pep-ho.tex Fri Apr 10 12:12:48 2020 +0100 @@ -41,6 +41,9 @@ % nice example for map and reduce using Harry potter characters % https://www.matthewgerstman.com/map-filter-reduce/ +% interesting talk about differences in Java and Scala +% Goto'19 conference ; about differences in type-system +% https://www.youtube.com/watch?v=e6n-Ci8V2CM % Timing % @@ -207,19 +210,19 @@ Before we go on, let me explain a bit more why we want to inflict upon you another programming language. You hopefully have mastered Java and -C++\ldots{}the world should be your oyster, no? Well, this is not as -simple as one might wish. We do require Scala in PEP, but actually we -do not religiously care whether you learn Scala---after all it is just -a programming language (albeit a nifty one IMHO). What we do care -about is that you learn about \textit{functional programming}. Scala -is just the vehicle for that. Still, you need to learn Scala well -enough to get good marks in PEP, but functional programming could -equally be taught with Haskell, F\#, SML, Ocaml, Kotlin, Clojure, -Scheme, Elm and many other functional programming languages. -%Your -%friendly lecturer just happens to like Scala -%and the Department agreed that it is a good idea to inflict Scala upon -%you. +C++\ldots{}the world should be your oyster, no? Well, matters are not as +simple as one might wish. We do require Scala in PEP, but actually we do +not religiously care whether you learn Scala---after all it is just a +programming language (albeit a nifty one IMHO). What we do care about is +that you learn about \textit{functional programming}. Scala is just the +vehicle for that. Still, you need to learn Scala well enough to get good +marks in PEP, but functional programming could perhaps equally be taught +with Haskell, F\#, SML, Ocaml, Kotlin, Clojure, Scheme, Elm and many +other functional programming languages. + +%Your friendly lecturer just +%happens to like Scala and the Department agreed that it is a good idea +%to inflict Scala upon you. Very likely writing programs in a functional programming language is quite different from what you are used to in your study so far. It @@ -265,30 +268,31 @@ stuck. This is unlike previous generations of developers who could rely upon the fact that approximately every 2 years their code would run twice as fast because the clock-speed of their CPUs got twice as fast. + Unfortunately this does not happen any more nowadays. To get you out of this dreadful situation, CPU producers pile more and more cores into CPUs in order to make them more powerful and potentially make software faster. The task for you as developer is to take somehow advantage of these cores by running as much of your code as possible in parallel on -as many cores you have available (typically 4 in modern laptops and -sometimes much more on high-end machines). In this situation -\textit{mutable} variables like \texttt{i} above are evil, or at least a -major nuisance: Because if you want to distribute some of the -loop-iterations over the cores that are currently idle in your system, -you need to be extremely careful about who can read and overwrite the -variable \texttt{i}.\footnote{If you are of the mistaken belief that -nothing nasty can happen to \texttt{i} inside the \texttt{for}-loop, -then you need to go back over the C++ material.} Especially the writing -operation is critical because you do not want that conflicting writes -mess about with \texttt{i}. Take my word: an untold amount of misery has -arisen from this problem. The catch is that if you try to solve this -problem in C/C++ or Java, and be as defensive as possible about reads -and writes to \texttt{i}, then you need to synchronise access to it. The -result is that very often your program waits more than it runs, thereby -defeating the point of trying to run the program in parallel in the -first place. If you are less defensive, then usually all hell breaks -loose by seemingly obtaining random results. And forget the idea of -being able to debug such code. +as many cores you have available (typically 4 or more in modern laptops +and sometimes much more on high-end machines). In this situation +\textit{mutable} variables like \texttt{i} in the C-code above are evil, +or at least a major nuisance: Because if you want to distribute some of +the loop-iterations over several cores that are currently idle in your +system, you need to be extremely careful about who can read and +overwrite the variable \texttt{i}.\footnote{If you are of the mistaken +belief that nothing nasty can happen to \texttt{i} inside the +\texttt{for}-loop, then you need to go back over the C++ material.} +Especially the writing operation is critical because you do not want +that conflicting writes mess about with \texttt{i}. Take my word: an +untold amount of misery has arisen from this problem. The catch is that +if you try to solve this problem in C/C++ or Java, and be as defensive +as possible about reads and writes to \texttt{i}, then you need to +synchronise access to it. The result is that very often your program +waits more than it runs, thereby defeating the point of trying to run +the program in parallel in the first place. If you are less defensive, +then usually all hell breaks loose by seemingly obtaining random +results. And forget the idea of being able to debug such code. The central idea of functional programming is to eliminate any state from programs---or at least from the ``interesting bits'' of the @@ -1632,6 +1636,10 @@ features of Scala and other languages, and it seems even it introduces new features on its own. + +Scala is deep: After many years, I still continue to learn new technique +for writing more elegant code. + %So all in all, Scala might not be a great teaching language, %but I hope this is mitigated by the fact that I never require %you to write any Scala code. You only need to be able to read diff -r 703c7e42bf46 -r 24bc76d97db2 marking1/drumb_test.sh --- a/marking1/drumb_test.sh Wed Feb 05 12:24:27 2020 +0000 +++ b/marking1/drumb_test.sh Fri Apr 10 12:12:48 2020 +0100 @@ -39,12 +39,14 @@ # purity test +#function scala_vars { +# (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) +#} + function scala_vars { - (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null) + (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|new Array' "$1" 2> /dev/null 1> /dev/null) } - - # var, .par return, ListBuffer test # echo -e "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out diff -r 703c7e42bf46 -r 24bc76d97db2 marking4/re_test.sh --- a/marking4/re_test.sh Wed Feb 05 12:24:27 2020 +0000 +++ b/marking4/re_test.sh Fri Apr 10 12:12:48 2020 +0100 @@ -171,7 +171,7 @@ echo -e " matcher(EVIL, \"b\") == true" | tee -a $out echo -e " matcher(EVIL, \"bb\") == false" | tee -a $out echo -e " matcher(\"abc\", \"abc\") == true" | tee -a $out - echo -e " matcher(\"abc\", \"ab\") == true" | tee -a $out + echo -e " matcher(\"abc\", \"ab\") == false" | tee -a $out echo -e " matcher((\"ab\" | \"a\") ~ (ONE | \"bc\"), \"abc\") == true" | tee -a $out echo -e " matcher(ONE, \"\") == true" | tee -a $out echo -e " matcher(ZERO, \"\") == false" | tee -a $out diff -r 703c7e42bf46 -r 24bc76d97db2 marking5/bf_test.sh --- a/marking5/bf_test.sh Wed Feb 05 12:24:27 2020 +0000 +++ b/marking5/bf_test.sh Fri Apr 10 12:12:48 2020 +0100 @@ -10,7 +10,7 @@ echo -e "Below is the feedback and provisional marks for your submission" >> $out -echo -e "for assignment 10 Part 1. Please note all marks are provisional until" >> $out +echo -e "for assignment 10. Please note all marks are provisional until" >> $out echo -e "ratified by the assessment board -- this is not an official" >> $out echo -e "results transcript." >> $out echo -e "" >> $out @@ -45,7 +45,7 @@ if (scala_vars bf.scala) then - echo -e " --> FAIL (make triple-sure your program conforms to the required format)" | tee -a $out + echo -e " --> TEST FAILED\n" | tee -a $out tsts0=$(( 1 )) else echo -e " --> success" | tee -a $out @@ -63,7 +63,7 @@ echo -e " --> success" | tee -a $out tsts1=$(( 0 )) else - echo -e " --> SCALA DID NOT RUN BF.SCALA\n" | tee -a $out + echo -e " --> SCALA DID NOT RUN bf.scala\n" | tee -a $out tsts1=$(( 1 )) fi else @@ -83,7 +83,7 @@ echo -e " --> success" | tee -a $out marks=$(( marks + 1 )) else - echo -e " --> \n ONE TEST FAILED\n" | tee -a $out + echo -e " --> TEST FAILED\n" | tee -a $out fi fi @@ -102,7 +102,7 @@ echo -e " --> success" | tee -a $out marks=$(( marks + 1 )) else - echo -e " --> \n ONE TEST FAILED\n" | tee -a $out + echo -e " --> TEST FAILED\n" | tee -a $out fi fi @@ -124,7 +124,7 @@ echo -e " --> success" | tee -a $out marks=$(( marks + 2 )) else - echo -e " --> \n ONE TEST FAILED\n" | tee -a $out + echo -e " --> TEST FAILED\n" | tee -a $out fi fi @@ -147,12 +147,123 @@ echo -e " --> success" | tee -a $out marks=$(( marks + 2 )) else - echo -e " --> \n ONE TEST FAILED\n" | tee -a $out + echo -e " --> TEST FAILED\n" | tee -a $out + fi +fi + + +# var, return, ListBuffer test +# +echo "bfc.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out + +if (scala_vars bfc.scala) +then + echo -e " --> TEST FAILED\n" | tee -a $out + tsts0=$(( 1 )) +else + echo -e " --> success" | tee -a $out + tsts0=$(( 0 )) +fi + + +# compilation test +if [ $tsts0 -eq 0 ] +then + echo "bfc.scala runs?" | tee -a $out + + if (scala_compile bfc.scala) + then + echo -e " --> success" | tee -a $out + tsts1=$(( 0 )) + else + echo -e " --> SCALA DID NOT RUN bfc.scala\n" | tee -a $out + tsts1=$(( 1 )) + fi +else + tsts1=$(( 1 )) +fi + + +### bfc5 test + +if [ $tsts1 -eq 0 ] +then + echo -e " val p1 = \"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\"" | tee -a $out + echo -e " jtable(p1) == Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" | tee -a $out + echo -e " val p2 = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " jtable(p2) == Map(14 -> 34, 33 -> 15, 45 -> 44, 48 -> 9, 43 -> 46, 8 -> 49)" | tee -a $out + echo -e " run2(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out + echo -e " run2(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out + echo -e " run2(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out + echo -e " run2(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out + echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out + echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out + echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " run2(hello, Map()) == " | tee -a $out + echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out + + if (scala_assert "bfc.scala" "bf_test5.scala") + then + echo -e " --> success" | tee -a $out + marks=$(( marks + 1 )) + else + echo -e " --> TEST FAILED\n" | tee -a $out + fi +fi + + +### bfc6 test + +if [ $tsts1 -eq 0 ] +then + echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" | tee -a $out + echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" | tee -a $out + echo -e " run3(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out + echo -e " run3(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out + echo -e " run3(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out + echo -e " run3(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out + echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out + echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out + echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " run3(hello, Map()) == " | tee -a $out + echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out + + if (scala_assert "bfc.scala" "bf_test6.scala") + then + echo -e " --> success" | tee -a $out + marks=$(( marks + 1 )) + else + echo -e " --> TEST FAILED\n" | tee -a $out + fi +fi + +### bfc7 test + +if [ $tsts1 -eq 0 ] +then + echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" | tee -a $out + echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" | tee -a $out + echo -e " run4(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out + echo -e " run4(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out + echo -e " run4(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out + echo -e " run4(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out + echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out + echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out + echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out + echo -e " run4(hello, Map()) == " | tee -a $out + echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out + + if (scala_assert "bfc.scala" "bf_test7.scala") + then + echo -e " --> success" | tee -a $out + marks=$(( marks + 2 )) + else + echo -e " --> TEST FAILED\n" | tee -a $out fi fi ## final marks -echo -e "Overall mark for CW 10, Part 1" | tee -a $out +echo -e "Overall mark for CW 10" | tee -a $out echo -e "$marks" | tee -a $out diff -r 703c7e42bf46 -r 24bc76d97db2 marking5/bfc_test.sh --- a/marking5/bfc_test.sh Wed Feb 05 12:24:27 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,156 +0,0 @@ -#!/bin/bash - -# to make the script fail safely -set -euo pipefail - - -out=${1:-output} - -echo "" > $out - - -echo "Below is the feedback and provisional marks for your submission" >> $out -echo "for assignment 10 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 - -# marks for CW10 part 2 -marks=$(( 0 )) - -# compilation tests - -function scala_compile { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null) -} - -# functional tests - -function scala_assert { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 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, return, ListBuffer test -# -echo "bfc.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out - -if (scala_vars bfc.scala) -then - echo " --> FAIL (make triple-sure your program conforms to the required format)" | tee -a $out - tsts0=$(( 1 )) -else - echo " --> success" | tee -a $out - tsts0=$(( 0 )) -fi - - -# compilation test -if [ $tsts0 -eq 0 ] -then - echo "bfc.scala runs?" | tee -a $out - - if (scala_compile bfc.scala) - then - echo " --> success" | tee -a $out - tsts1=$(( 0 )) - else - echo " --> SCALA DID NOT RUN BFC.SCALA\n" | tee -a $out - tsts1=$(( 1 )) - fi -else - tsts1=$(( 1 )) -fi - - -### bfc5 test - -if [ $tsts1 -eq 0 ] -then - echo -e " val p1 = \"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\"" | tee -a $out - echo -e " jtable(p1) == Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" | tee -a $out - echo -e " val p2 = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out - echo -e " jtable(p2) == Map(14 -> 34, 33 -> 15, 45 -> 44, 48 -> 9, 43 -> 46, 8 -> 49)" | tee -a $out - echo -e " run2(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out - echo -e " run2(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out - echo -e " run2(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out - echo -e " run2(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out - echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out - echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out - echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out - echo -e " run2(hello, Map()) == " | tee -a $out - echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out - - if (scala_assert "bfc.scala" "bf_test5.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> \n ONE TEST FAILED\n" | tee -a $out - fi -fi - - -### bfc6 test - -if [ $tsts1 -eq 0 ] -then - echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" | tee -a $out - echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" | tee -a $out - echo -e " run3(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out - echo -e " run3(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out - echo -e " run3(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out - echo -e " run3(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out - echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out - echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out - echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out - echo -e " run3(hello, Map()) == " | tee -a $out - echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out - - if (scala_assert "bfc.scala" "bf_test6.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 1 )) - else - echo " --> \n ONE TEST FAILED\n" | tee -a $out - fi -fi - -### bfc7 test - -if [ $tsts1 -eq 0 ] -then - echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" | tee -a $out - echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" | tee -a $out - echo -e " run4(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" | tee -a $out - echo -e " run4(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" | tee -a $out - echo -e " run4(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" | tee -a $out - echo -e " run4(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" | tee -a $out - echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" | tee -a $out - echo -e " val hello = \"\"\"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---." | tee -a $out - echo -e " +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\"\"\"" | tee -a $out - echo -e " run4(hello, Map()) == " | tee -a $out - echo -e " Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" | tee -a $out - - if (scala_assert "bfc.scala" "bf_test7.scala") - then - echo " --> success" | tee -a $out - marks=$(( marks + 2 )) - else - echo " --> \n ONE TEST FAILED\n" | tee -a $out - fi -fi - - -## final marks -echo "Overall mark for CW 10, Part 2" | tee -a $out -echo "$marks" | tee -a $out - diff -r 703c7e42bf46 -r 24bc76d97db2 marking5/mk --- a/marking5/mk Wed Feb 05 12:24:27 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#!/bin/sh -###set -e - -trap "exit" INT - -files=${1:-assignment201810-*} - -for sd in $files; do - cd $sd - echo $sd - touch . - cp ../../../marking5/bf_test.sh . - cp ../../../marking5/bf_test1.scala . - cp ../../../marking5/bf_test2.scala . - cp ../../../marking5/bf_test3.scala . - cp ../../../marking5/bf_test4.scala . - cp ../../../marking5/benchmark.bf . - ./bf_test.sh output - rm bf_test.sh - rm bf_test1.scala - rm bf_test2.scala - rm bf_test3.scala - rm bf_test4.scala - rm benchmark.bf - cd .. -done - - diff -r 703c7e42bf46 -r 24bc76d97db2 marking5/mk-advanced --- a/marking5/mk-advanced Wed Feb 05 12:24:27 2020 +0000 +++ b/marking5/mk-advanced Fri Apr 10 12:12:48 2020 +0100 @@ -3,24 +3,33 @@ trap "exit" INT -files=${1:-assignment201810-*} +files=${1:-assignment2019scala-*/Part10} for sd in $files; do cd $sd echo $sd touch . - cp ../../../marking5/bfc_test.sh . - cp ../../../marking5/bf_test5.scala . - cp ../../../marking5/bf_test6.scala . - cp ../../../marking5/bf_test7.scala . - cp ../../../marking5/*.bf . - ./bfc_test.sh output - rm bfc_test.sh + cp ../../../../../marking5/bf_test.sh . + cp ../../../../../marking5/bf_test1.scala . + cp ../../../../../marking5/bf_test2.scala . + cp ../../../../../marking5/bf_test3.scala . + cp ../../../../../marking5/bf_test4.scala . + cp ../../../../../marking5/bf_test5.scala . + cp ../../../../../marking5/bf_test6.scala . + cp ../../../../../marking5/bf_test7.scala . + cp ../../../../../marking5/*.bf . + ./bf_test.sh output + rm bf_test.sh + rm bf_test1.scala + rm bf_test2.scala + rm bf_test3.scala + rm bf_test4.scala rm bf_test5.scala rm bf_test6.scala rm bf_test7.scala rm *.bf cd .. + cd .. done diff -r 703c7e42bf46 -r 24bc76d97db2 progs/lecture5.scala --- a/progs/lecture5.scala Wed Feb 05 12:24:27 2020 +0000 +++ b/progs/lecture5.scala Fri Apr 10 12:12:48 2020 +0100 @@ -1,6 +1,9 @@ // Scala Lecture 5 //================= +// TODO: word count for a very large file (40GB or so) +// Transform Farenheit into Celsius + // Laziness with style //===================== diff -r 703c7e42bf46 -r 24bc76d97db2 templates2/danube.scala --- a/templates2/danube.scala Wed Feb 05 12:24:27 2020 +0000 +++ b/templates2/danube.scala Fri Apr 10 12:12:48 2020 +0100 @@ -25,7 +25,7 @@ // testcases //----------- -//val ratings = get_csv_url(ratings_url) +//: //val movies = get_csv_url(movies_url) //ratings.length // 87313 @@ -36,7 +36,8 @@ // (2) Implement two functions that process the CSV-files from (1). The ratings // function filters out all ratings below 4 and ReTurns a list of // (userID, movieID) pairs. The movies function just ReTurns a list -// of (movieID, title) pairs. +// of (movieID, title) pairs. Note the input to these functions, that is +// the argument lines, will be the output of the function get_csv_url. //def process_ratings(lines: List[String]) : List[(String, String)] = ... diff -r 703c7e42bf46 -r 24bc76d97db2 templates5/bfc.scala --- a/templates5/bfc.scala Wed Feb 05 12:24:27 2020 +0000 +++ b/templates5/bfc.scala Fri Apr 10 12:12:48 2020 +0100 @@ -83,7 +83,7 @@ // testcases // time_needed(1, run2(load_bff("benchmark.bf"))) -// time_needed(1, run2(load_bff("seirpinski.bf"))) +// time_needed(1, run2(load_bff("sierpinski.bf")))