# HG changeset patch # User Christian Urban # Date 1698933217 0 # Node ID 31b81f20fd9a8cebb3ae1b86a8af7d7bcaf996f9 # Parent 195ad66315d955af3b6042d5910c5cb527156a0a updated diff -r 195ad66315d9 -r 31b81f20fd9a core_testing1/collatz_test.sh --- a/core_testing1/collatz_test.sh Thu Nov 02 12:37:58 2023 +0000 +++ b/core_testing1/collatz_test.sh Thu Nov 02 13:53:37 2023 +0000 @@ -15,13 +15,13 @@ # compilation tests function scala_compile { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$1" ) #2> c$out 1> c$out) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$1" 2> c$out 1> c$out) } # functional tests function scala_assert { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" ) #2> /dev/null 1> /dev/null) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null) } # purity test @@ -42,6 +42,7 @@ tsts=$(( 0 )) else echo -e " --> SCALA DID NOT RUN collatz.scala\n" >> $out + echo -e " --> try running scala-cli compile collatz.scala on your own computer\n" >> $out tsts=$(( 1 )) fi diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test.sh --- a/core_testing3/postfix_test.sh Thu Nov 02 12:37:58 2023 +0000 +++ b/core_testing3/postfix_test.sh Thu Nov 02 13:53:37 2023 +0000 @@ -9,26 +9,26 @@ echo -e "Below is the feedback for your submission postfix.scala and postfix2.scala" >> $out echo -e "" >> $out + # compilation tests function scala_compile { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$1" 2> c$out 1> c$out) } # 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-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null) } # purity test - function scala_vars { - (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null) + (sed 's/immutable/ok/g' c$out > cb$out; + egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null) } - # compilation test echo -e "postfix.scala runs?" >> $out @@ -38,7 +38,8 @@ echo -e " --> passed" >> $out tsts=$(( 0 )) else - echo -e " --> SCALA DID NOT RUN postfix.scala\n" >> $out + echo -e " --> SCALA DID NOT RUN postfix.scala\n" >> $out + echo -e " --> try running scala-cli compile postfix.scala on your own computer\n" >> $out tsts=$(( 1 )) fi @@ -69,7 +70,7 @@ echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out - if (scala_assert "postfix.scala" "postfix_test7.scala") + if (scala_assert "postfix.scala" "postfix_test1.scala") then echo -e " --> success" >> $out else @@ -88,7 +89,7 @@ echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out - if (scala_assert "postfix.scala" "postfix_test8.scala") + if (scala_assert "postfix.scala" "postfix_test2.scala") then echo -e " --> success" >> $out else @@ -111,6 +112,7 @@ tsts1=$(( 0 )) else echo -e " --> SCALA DID NOT RUN postfix2.scala\n" >> $out + echo -e " --> try running scala-cli compile postfix2.scala on your own computer\n" >> $out tsts1=$(( 1 )) fi @@ -152,7 +154,7 @@ echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out - if (scala_assert "postfix2.scala" "postfix_test9.scala") + if (scala_assert "postfix2.scala" "postfix_test3.scala") then echo -e " --> success" >> $out else diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test1.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core_testing3/postfix_test1.scala Thu Nov 02 13:53:37 2023 +0000 @@ -0,0 +1,10 @@ + +def urbanmain() = { + import C3a._ + + + assert(syard(split("3 + 4 * ( 2 - 1 )")) == List("3", "4", "2", "1", "-", "*", "+")) + assert(syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) == List("3", "4", "5", "+", "+")) + assert(syard(split("5 + 7 / 2")) == List("5", "7", "2", "/", "+")) + assert(syard(split("5 * 7 / 2")) == List("5", "7", "*", "2", "/")) +} diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test2.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core_testing3/postfix_test2.scala Thu Nov 02 13:53:37 2023 +0000 @@ -0,0 +1,11 @@ + +def urbanmain() = { + import C3a._ + + assert(compute(syard(split("3 + 4 * ( 2 - 1 )"))) == 7) + assert(compute(syard(split("10 + 12 * 33"))) == 406) + assert(compute(syard(split("( 5 + 7 ) * 2"))) == 24) + assert(compute(syard(split("5 + 7 / 2"))) == 8) + assert(compute(syard(split("5 * 7 / 2"))) == 17) + assert(compute(syard(split("9 + 24 / ( 7 - 3 )"))) == 15) +} diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test3.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core_testing3/postfix_test3.scala Thu Nov 02 13:53:37 2023 +0000 @@ -0,0 +1,23 @@ + + +def urbanmain() = { + import C3b._ + + + assert(syard(split("3 + 4 * ( 2 - 1 )")) == List("3", "4", "2", "1", "-", "*", "+")) + assert(syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) == List("3", "4", "5", "+", "+")) + assert(syard(split("5 + 7 / 2")) == List("5", "7", "2", "/", "+")) + assert(syard(split("5 * 7 / 2")) == List("5", "7", "*", "2", "/")) + assert(syard(split("3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3")) == List("3", "4", "8", "*", "5", "1", "-", "2", "3", "^", "^", "/", "+")) + + assert(compute(syard(split("3 + 4 * ( 2 - 1 )"))) == 7) + assert(compute(syard(split("10 + 12 * 33"))) == 406) + assert(compute(syard(split("( 5 + 7 ) * 2"))) == 24) + assert(compute(syard(split("5 + 7 / 2"))) == 8) + assert(compute(syard(split("5 * 7 / 2"))) == 17) + assert(compute(syard(split("9 + 24 / ( 7 - 3 )"))) == 15) + assert(compute(syard(split("4 ^ 3 ^ 2"))) == 262144) + assert(compute(syard(split("4 ^ ( 3 ^ 2 )"))) == 262144) + assert(compute(syard(split("( 4 ^ 3 ) ^ 2"))) == 4096) + assert(compute(syard(split("( 3 + 1 ) ^ 2 ^ 3"))) == 65536) +} diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test7.scala --- a/core_testing3/postfix_test7.scala Thu Nov 02 12:37:58 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -import C3a._ - - -assert(syard(split("3 + 4 * ( 2 - 1 )")) == List("3", "4", "2", "1", "-", "*", "+")) -assert(syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) == List("3", "4", "5", "+", "+")) -assert(syard(split("5 + 7 / 2")) == List("5", "7", "2", "/", "+")) -assert(syard(split("5 * 7 / 2")) == List("5", "7", "*", "2", "/")) diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test8.scala --- a/core_testing3/postfix_test8.scala Thu Nov 02 12:37:58 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -import C3a._ - -assert(compute(syard(split("3 + 4 * ( 2 - 1 )"))) == 7) -assert(compute(syard(split("10 + 12 * 33"))) == 406) -assert(compute(syard(split("( 5 + 7 ) * 2"))) == 24) -assert(compute(syard(split("5 + 7 / 2"))) == 8) -assert(compute(syard(split("5 * 7 / 2"))) == 17) -assert(compute(syard(split("9 + 24 / ( 7 - 3 )"))) == 15) diff -r 195ad66315d9 -r 31b81f20fd9a core_testing3/postfix_test9.scala --- a/core_testing3/postfix_test9.scala Thu Nov 02 12:37:58 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -import C3b._ - - -assert(syard(split("3 + 4 * ( 2 - 1 )")) == List("3", "4", "2", "1", "-", "*", "+")) -assert(syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) == List("3", "4", "5", "+", "+")) -assert(syard(split("5 + 7 / 2")) == List("5", "7", "2", "/", "+")) -assert(syard(split("5 * 7 / 2")) == List("5", "7", "*", "2", "/")) -assert(syard(split("3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3")) == List("3", "4", "8", "*", "5", "1", "-", "2", "3", "^", "^", "/", "+")) - - - -assert(compute(syard(split("3 + 4 * ( 2 - 1 )"))) == 7) -assert(compute(syard(split("10 + 12 * 33"))) == 406) -assert(compute(syard(split("( 5 + 7 ) * 2"))) == 24) -assert(compute(syard(split("5 + 7 / 2"))) == 8) -assert(compute(syard(split("5 * 7 / 2"))) == 17) -assert(compute(syard(split("9 + 24 / ( 7 - 3 )"))) == 15) -assert(compute(syard(split("4 ^ 3 ^ 2"))) == 262144) -assert(compute(syard(split("4 ^ ( 3 ^ 2 )"))) == 262144) -assert(compute(syard(split("( 4 ^ 3 ) ^ 2"))) == 4096) -assert(compute(syard(split("( 3 + 1 ) ^ 2 ^ 3"))) == 65536) diff -r 195ad66315d9 -r 31b81f20fd9a cws/core_cw01.pdf Binary file cws/core_cw01.pdf has changed diff -r 195ad66315d9 -r 31b81f20fd9a cws/core_cw01.tex --- a/cws/core_cw01.tex Thu Nov 02 12:37:58 2023 +0000 +++ b/cws/core_cw01.tex Thu Nov 02 13:53:37 2023 +0000 @@ -32,8 +32,8 @@ \noindent In addition, the Scala coursework comes with a reference implementation -in form of \texttt{jar}-files. This allows you to run any test cases on -your own computer. For example you can call scala-cli on the command line +in form of a \texttt{jar}-file. This allows you to run any test cases on +your own computer. For example you can call \texttt{scala-cli} on the command line with the option \texttt{--extra-jars collatz.jar} and then query any function from the template file. Say you want to find out what the functions \texttt{collatz} and \texttt{collatz\_max} produce: for this you just @@ -67,7 +67,7 @@ This part is about function definitions and recursion. You are asked to implement a Scala program that tests examples of the \emph{$3n + 1$-conjecture}, also called \emph{Collatz - conjecture}.\video{https://www.youtube.com./watch?v=LqKpkdRRLZw} + conjecture}.\video{https://www.youtube.com/watch?v=LqKpkdRRLZw} This conjecture can be described as follows: Start with any positive number $n$ greater than $0$: diff -r 195ad66315d9 -r 31b81f20fd9a cws/core_cw02.pdf Binary file cws/core_cw02.pdf has changed diff -r 195ad66315d9 -r 31b81f20fd9a cws/core_cw02.tex --- a/cws/core_cw02.tex Thu Nov 02 12:37:58 2023 +0000 +++ b/cws/core_cw02.tex Thu Nov 02 13:53:37 2023 +0000 @@ -34,7 +34,7 @@ \noindent In addition, the Scala part comes with reference implementations in form of \texttt{jar}-files. This allows you to run -any test cases on your own computer. For example you can call scala-cli on +any test cases on your own computer. For example you can call \texttt{scala-cli} on the command line with the option \texttt{--extra-jars docdiff.jar} and then query any function from the template file. Say you want to find out what the function \texttt{occurrences} produces: for this you just need @@ -141,7 +141,7 @@ where $d_1^2$ means $d_1 \cdot d_1$ and so on. You can expect this function to return a \texttt{Double} between 0 and 1. The - overlap between the lists in (2) is $0.5384615384615384$. + overlap between the lists in Task (2) is $0.5384615384615384$. Second, implement a function that calculates the similarity of two strings, by first extracting the substrings using the clean diff -r 195ad66315d9 -r 31b81f20fd9a cws/disclaimer.sty --- a/cws/disclaimer.sty Thu Nov 02 12:37:58 2023 +0000 +++ b/cws/disclaimer.sty Thu Nov 02 13:53:37 2023 +0000 @@ -4,7 +4,7 @@ \begin{itemize} \item #1 \item Make sure the files you submit can be processed by just calling\\ - \mbox{\texttt{scala-cli <>}} on the command line.\footnote{All + \mbox{\texttt{scala-cli compile <>}} on the command line.\footnote{All major OSes, including Windows, have a command line. So there is no good reason to not download scala-cli, install it and run it on your own computer. Just do it!} Use the @@ -37,7 +37,7 @@ \begin{itemize} \item Make sure the files you submit can be processed by just calling\\ - \mbox{\texttt{scala-cli <>}} on the command line.\footnote{All + \mbox{\texttt{scala-cli compile <>}} on the command line.\footnote{All major OSes, including Windows, have a command line. So there is no good reason to not download scala-cli, install it and run it on your own computer. Just do it!} Use the @@ -71,7 +71,7 @@ \begin{itemize} \item Make sure the files you submit can be processed by just calling\\ - \mbox{\texttt{scala <>}} on the command line. Use the + \mbox{\texttt{scala-cli compile <>}} on the command line. Use the template file provided and do not make any changes to arguments of functions or to any types. You are free to implement any auxiliary function you might need.