updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Wed, 02 Dec 2020 01:15:14 +0000
changeset 382 1bd800376e0c
parent 381 116fa3c8584f
child 383 c02929f2647c
updated
marking2/docdiff.scala
marking2/docdiff_test.sh
marking2/docdiff_test1.scala
marking2/docdiff_test2.scala
marking2/docdiff_test3.scala
marking2/docdiff_test4.scala
marking2/mk
pre_marking1/collatz_test.sh
pre_marking1/mk
pre_marking2/docdiff.scala
pre_marking2/docdiff_test.sh
pre_marking2/docdiff_test1.scala
pre_marking2/docdiff_test2.scala
pre_marking2/docdiff_test3.scala
pre_marking2/docdiff_test4.scala
pre_marking2/mk
progs/lecture4.scala
slides/slides03.pdf
slides/slides03.tex
slides/slides04.pdf
--- a/marking2/docdiff.scala	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-// Preliminary Part about Code Similarity
-//========================================
-
-
-object CW7a { 
-
-//(1) Complete the clean function below. It should find
-//    all words in a string using the regular expression
-//    \w+  and the library function 
-//
-//         some_regex.findAllIn(some_string)
-//
-//    The words should be Returned as a list of strings.
-
-def clean(s: String) : List[String] = 
-  ("""\w+""".r).findAllIn(s).toList
-
-
-//(2) The function occurrences calculates the number of times  
-//    strings occur in a list of strings. These occurrences should 
-//    be calculated as a Map from strings to integers.
-
-def occurrences(xs: List[String]): Map[String, Int] =
-  (for (x <- xs.distinct) yield (x, xs.count(_ == x))).toMap
-
-//(3) This functions calculates the dot-product of two documents
-//    (list of strings). For this it calculates the occurrence
-//    maps from (2) and then multiplies the corresponding occurrences. 
-//    If a string does not occur in a document, the product is zero.
-//    The function finally sums up all products. 
-
-def prod(lst1: List[String], lst2: List[String]) : Int = {
-    val words = (lst1 ::: lst2).distinct
-    val occs1 = occurrences(lst1)
-    val occs2 = occurrences(lst2)
-    words.map{ w => occs1.getOrElse(w, 0) * occs2.getOrElse(w, 0) }.sum
-}
-
-//(4) Complete the functions overlap and similarity. The overlap of
-//    two documents is calculated by the formula given in the assignment
-//    description. The similarity of two strings is given by the overlap
-//    of the cleaned (see (1)) strings.  
-
-def overlap(lst1: List[String], lst2: List[String]) : Double = {
-    val m1 = prod(lst1, lst1)
-    val m2 = prod(lst2, lst2) 
-    prod(lst1, lst2).toDouble / (List(m1, m2).max)
-}
-
-def similarity(s1: String, s2: String) : Double =
-  overlap(clean(s1), clean(s2))
-
-
-/*
-
-
-val list1 = List("a", "b", "b", "c", "d") 
-val list2 = List("d", "b", "d", "b", "d")
-
-occurrences(List("a", "b", "b", "c", "d"))   // Map(a -> 1, b -> 2, c -> 1, d -> 1)
-occurrences(List("d", "b", "d", "b", "d"))   // Map(d -> 3, b -> 2)
-
-prod(list1,list2) // 7 
-
-overlap(list1, list2)   // 0.5384615384615384
-overlap(list2, list1)   // 0.5384615384615384
-overlap(list1, list1)   // 1.0
-overlap(list2, list2)   // 1.0
-
-// Plagiarism examples from 
-// https://desales.libguides.com/avoidingplagiarism/examples
-
-val orig1 = """There is a strong market demand for eco-tourism in
-Australia. Its rich and diverse natural heritage ensures Australia's
-capacity to attract international ecotourists and gives Australia a
-comparative advantage in the highly competitive tourism industry."""
-
-val plag1 = """There is a high market demand for eco-tourism in
-Australia. Australia has a comparative advantage in the highly
-competitive tourism industry due to its rich and varied natural
-heritage which ensures Australia's capacity to attract international
-ecotourists."""
-
-similarity(orig1, plag1)
-
-
-// Plagiarism examples from 
-// https://www.utc.edu/library/help/tutorials/plagiarism/examples-of-plagiarism.php
-
-val orig2 = """No oil spill is entirely benign. Depending on timing and
-location, even a relatively minor spill can cause significant harm to
-individual organisms and entire populations. Oil spills can cause
-impacts over a range of time scales, from days to years, or even
-decades for certain spills. Impacts are typically divided into acute
-(short-term) and chronic (long-term) effects. Both types are part of a
-complicated and often controversial equation that is addressed after
-an oil spill: ecosystem recovery."""
-
-val plag2 = """There is no such thing as a "good" oil spill. If the
-time and place are just right, even a small oil spill can cause damage
-to sensitive ecosystems. Further, spills can cause harm days, months,
-years, or even decades after they occur. Because of this, spills are
-usually broken into short-term (acute) and long-term (chronic)
-effects. Both of these types of harm must be addressed in ecosystem
-recovery: a controversial tactic that is often implemented immediately
-following an oil spill."""
-
-overlap(clean(orig2), clean(plag2))
-similarity(orig2, plag2)
-
-// The punchline: everything above 0.6 looks suspicious and 
-// should be looked at by staff.
-
-*/
-
-
-}
--- a/marking2/docdiff_test.sh	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-#!/bin/bash
-
-# to make the script fail safely
-set -euo pipefail
-
-
-out=${1:-output}
-
-echo "" > $out
-
-echo -e "Below is the feedback and provisional marks for your submission" >> $out
-echo -e "for the Preliminary Part of Assignemnt 7.  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
-
-echo -e "Below is the feedback for your submission docdiff.scala" >> $out
-echo -e "" >> $out
-
-# marks for CW7 parts 1 + 2
-marks=$(( 0 ))
-
-
-# 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" 2> /dev/null 1> /dev/null)
-}
-
-# purity test
-
-function scala_vars {
-   (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
-}
-
-
-# var, .par return, ListBuffer test
-#
-echo -e "docdiff.scala does not contain vars, returns etc?" |  tee -a $out
-
-if (scala_vars docdiff.scala)
-then
-  echo -e "  --> FAIL (make triple-sure your program conforms to the required format)\n" | tee -a $out  
-  tsts0=$(( 1 ))
-else
-  echo -e "  --> success" |  tee -a $out
-  tsts0=$(( 0 )) 
-fi
-
-### compilation test
-
-
-if  [ $tsts0 -eq 0 ]
-then 
-  echo -e "docdiff.scala runs?" |  tee -a $out
-
-  if (scala_compile docdiff.scala)
-  then
-    echo -e "  --> success" |  tee -a $out
-    tsts=$(( 0 ))
-  else
-    echo -e "  --> scala did not run docdiff.scala" |  tee -a $out
-    tsts=$(( 1 )) 
-  fi
-else
-  tsts=$(( 1 ))     
-fi
-
-### docdiff clean tests
-
-if [ $tsts -eq 0 ]
-then
-  echo -e "docdiff.scala tests:" |  tee -a $out
-  echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
-  echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
-
-  if (scala_assert "docdiff.scala" "docdiff_test1.scala")
-  then
-      echo -e "  --> success" |  tee -a $out
-      marks=$(( marks + 1 ))
-  else
-      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
-  fi
-fi
-
-### docdiff occurrences tests
-
-if [ $tsts -eq 0 ]
-then
-  echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
-  echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out
-  echo -e "  " |  tee -a $out
-  echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
-  echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
-  echo -e "  " |  tee -a $out
-  echo -e "  occurrences(Nil) == Map() " |  tee -a $out
-  echo -e "  " |  tee -a $out
-  echo -e "  occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" |  tee -a $out
-
-  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
-  then
-      echo -e "  --> success" |  tee -a $out
-      marks=$(( marks + 1 ))
-  else
-    echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
-  fi
-fi
-
-### docdiff prod tests
-
-if [ $tsts -eq 0 ]
-then
-  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
-  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
-  echo -e "  " |  tee -a $out
-  echo -e "  prod(l1, l2) == 7 " |  tee -a $out
-  echo -e "  prod(l1, l1) == 7 " |  tee -a $out
-  echo -e "  prod(l2, l2) == 13 " |  tee -a $out
-  echo -e "  " |  tee -a $out
-  echo -e "  val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" |  tee -a $out
-  echo -e "  prod(l1, l3) == 0 " |  tee -a $out
-
-  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
-  then
-      echo -e "  --> success" |  tee -a $out
-      marks=$(( marks + 1 ))
-  else
-    echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
-  fi
-fi
-
-### docdiff overlap tests
-
-if [ $tsts -eq 0 ]
-then
-  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
-  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
-  echo -e "  " |  tee -a $out
-  echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
-  echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
-  echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
-
-  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
-  then
-      echo -e "  --> success" |  tee -a $out
-      marks=$(( marks + 1 ))
-  else
-      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
-  fi
-fi
-
-
-## final marks
-echo -e "Overall mark for the Preliminary Part" | tee -a $out
-echo -e " $marks" | tee -a $out
-
--- a/marking2/docdiff_test1.scala	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-
-import CW7a._
-
-assert(clean("ab a abc") == List("ab", "a", "abc"))
-assert(clean("ab*a abc1") == List("ab", "a", "abc1"))
--- a/marking2/docdiff_test2.scala	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-
-import CW7a._
-
-assert(occurrences(List("a", "b", "b", "c", "d")) == Map("a" -> 1, "b" -> 2, "c" -> 1, "d" -> 1))
-
-assert(occurrences(List("d", "b", "d", "b", "d")) == Map("d" -> 3, "b" -> 2))
-
-assert(occurrences(List("b", "b", "b", "b", "b")) == Map("b" -> 5))
-
-assert(occurrences(Nil) == Map())
--- a/marking2/docdiff_test3.scala	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-
-import CW7a._
-
-val urban_list1 = List("a", "b", "b", "c", "d")
-val urban_list2 = List("d", "b", "d", "b", "d")
-
-assert(prod(urban_list1, urban_list2) == 7)
-assert(prod(urban_list1, urban_list1) == 7)
-assert(prod(urban_list2, urban_list2) == 13)
-
-
-val urban_listA = List("a", "b", "b", "c", "d")
-val urban_listB = List("1", "2", "3", "4", "5")
-
-assert(prod(urban_listA, urban_listB) == 0)
--- a/marking2/docdiff_test4.scala	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-
-import CW7a._
-
-val urban_list1 = List("a", "b", "b", "c", "d")
-val urban_list2 = List("d", "b", "d", "b", "d")
-
-assert(overlap(urban_list1, urban_list2) == 0.5384615384615384)
-assert(overlap(urban_list1, urban_list1) == 1.0)
-assert(overlap(urban_list2, urban_list2) == 1.0)
--- a/marking2/mk	Mon Nov 30 12:58:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#!/bin/bash
-set -euo pipefail
-
-
-trap "exit" INT
-
-files=${1:-assignment2019scala-*/Part7}
-
-for sd in $files; do
-  cd $sd
-  echo $sd
-  touch .
-  cp ../../../../../marking2/docdiff_test.sh .
-  cp ../../../../../marking2/docdiff_test1.scala .
-  cp ../../../../../marking2/docdiff_test2.scala .
-  cp ../../../../../marking2/docdiff_test3.scala .
-  cp ../../../../../marking2/docdiff_test4.scala .
-  ./docdiff_test.sh output
-  rm docdiff_test.sh
-  rm docdiff_test1.scala
-  rm docdiff_test2.scala
-  rm docdiff_test3.scala
-  rm docdiff_test4.scala
-  cd ..
-  cd ..
-done
-
-
--- a/pre_marking1/collatz_test.sh	Mon Nov 30 12:58:37 2020 +0000
+++ b/pre_marking1/collatz_test.sh	Wed Dec 02 01:15:14 2020 +0000
@@ -19,7 +19,7 @@
 echo "The feedback for your submission for collatz.scala" >> $out
 echo "" >> $out
 
-# marks for CW6 basic part 
+# marks for CW6 preliminary part
 marks=$(( 0 ))
 
 # compilation tests
--- a/pre_marking1/mk	Mon Nov 30 12:58:37 2020 +0000
+++ b/pre_marking1/mk	Wed Dec 02 01:15:14 2020 +0000
@@ -1,5 +1,5 @@
-#!/bin/sh
-###set -e
+#!/bin/bash
+set -euo pipefail
 
 trap "exit" INT
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/docdiff.scala	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,117 @@
+// Preliminary Part about Code Similarity
+//========================================
+
+
+object CW7a { 
+
+//(1) Complete the clean function below. It should find
+//    all words in a string using the regular expression
+//    \w+  and the library function 
+//
+//         some_regex.findAllIn(some_string)
+//
+//    The words should be Returned as a list of strings.
+
+def clean(s: String) : List[String] = 
+  ("""\w+""".r).findAllIn(s).toList
+
+
+//(2) The function occurrences calculates the number of times  
+//    strings occur in a list of strings. These occurrences should 
+//    be calculated as a Map from strings to integers.
+
+def occurrences(xs: List[String]): Map[String, Int] =
+  (for (x <- xs.distinct) yield (x, xs.count(_ == x))).toMap
+
+//(3) This functions calculates the dot-product of two documents
+//    (list of strings). For this it calculates the occurrence
+//    maps from (2) and then multiplies the corresponding occurrences. 
+//    If a string does not occur in a document, the product is zero.
+//    The function finally sums up all products. 
+
+def prod(lst1: List[String], lst2: List[String]) : Int = {
+    val words = (lst1 ::: lst2).distinct
+    val occs1 = occurrences(lst1)
+    val occs2 = occurrences(lst2)
+    words.map{ w => occs1.getOrElse(w, 0) * occs2.getOrElse(w, 0) }.sum
+}
+
+//(4) Complete the functions overlap and similarity. The overlap of
+//    two documents is calculated by the formula given in the assignment
+//    description. The similarity of two strings is given by the overlap
+//    of the cleaned (see (1)) strings.  
+
+def overlap(lst1: List[String], lst2: List[String]) : Double = {
+    val m1 = prod(lst1, lst1)
+    val m2 = prod(lst2, lst2) 
+    prod(lst1, lst2).toDouble / (List(m1, m2).max)
+}
+
+def similarity(s1: String, s2: String) : Double =
+  overlap(clean(s1), clean(s2))
+
+
+/*
+
+
+val list1 = List("a", "b", "b", "c", "d") 
+val list2 = List("d", "b", "d", "b", "d")
+
+occurrences(List("a", "b", "b", "c", "d"))   // Map(a -> 1, b -> 2, c -> 1, d -> 1)
+occurrences(List("d", "b", "d", "b", "d"))   // Map(d -> 3, b -> 2)
+
+prod(list1,list2) // 7 
+
+overlap(list1, list2)   // 0.5384615384615384
+overlap(list2, list1)   // 0.5384615384615384
+overlap(list1, list1)   // 1.0
+overlap(list2, list2)   // 1.0
+
+// Plagiarism examples from 
+// https://desales.libguides.com/avoidingplagiarism/examples
+
+val orig1 = """There is a strong market demand for eco-tourism in
+Australia. Its rich and diverse natural heritage ensures Australia's
+capacity to attract international ecotourists and gives Australia a
+comparative advantage in the highly competitive tourism industry."""
+
+val plag1 = """There is a high market demand for eco-tourism in
+Australia. Australia has a comparative advantage in the highly
+competitive tourism industry due to its rich and varied natural
+heritage which ensures Australia's capacity to attract international
+ecotourists."""
+
+similarity(orig1, plag1)
+
+
+// Plagiarism examples from 
+// https://www.utc.edu/library/help/tutorials/plagiarism/examples-of-plagiarism.php
+
+val orig2 = """No oil spill is entirely benign. Depending on timing and
+location, even a relatively minor spill can cause significant harm to
+individual organisms and entire populations. Oil spills can cause
+impacts over a range of time scales, from days to years, or even
+decades for certain spills. Impacts are typically divided into acute
+(short-term) and chronic (long-term) effects. Both types are part of a
+complicated and often controversial equation that is addressed after
+an oil spill: ecosystem recovery."""
+
+val plag2 = """There is no such thing as a "good" oil spill. If the
+time and place are just right, even a small oil spill can cause damage
+to sensitive ecosystems. Further, spills can cause harm days, months,
+years, or even decades after they occur. Because of this, spills are
+usually broken into short-term (acute) and long-term (chronic)
+effects. Both of these types of harm must be addressed in ecosystem
+recovery: a controversial tactic that is often implemented immediately
+following an oil spill."""
+
+overlap(clean(orig2), clean(plag2))
+similarity(orig2, plag2)
+
+// The punchline: everything above 0.6 looks suspicious and 
+// should be looked at by staff.
+
+*/
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/docdiff_test.sh	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,170 @@
+#!/bin/zsh
+
+# to make the script fail safely
+set -euo pipefail
+
+
+out=${1:-output}
+
+echo "" > $out
+
+echo `date` >> $out
+echo -e "Below is the feedback and provisional marks for your submission" >> $out
+echo -e "for the Preliminary Part of Part 2 (Scala).  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
+
+echo -e "Below is the feedback for your submission docdiff.scala" >> $out
+echo -e "" >> $out
+
+# marks for CW7 preliminary part
+marks=$(( 0.0 ))
+
+
+# compilation tests
+
+function scala_compile {
+  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
+}
+
+# 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\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
+}
+
+
+### compilation test
+
+echo -e "docdiff.scala runs?" |  tee -a $out
+
+if (scala_compile docdiff.scala)
+then
+    echo -e "  --> success" |  tee -a $out
+    tsts=$(( 0 ))
+else
+    echo -e "  --> SCALA DID NOT RUN docdiff.scala\n" |  tee -a $out
+    tsts=$(( 1 )) 
+fi
+
+
+# var, .par return, ListBuffer test
+#
+
+if  [ $tsts -eq 0 ]
+then     
+   echo -e "docdiff.scala does not contain VARS, RETURNS etc?" |  tee -a $out
+
+   if (scala_vars docdiff.scala)
+   then
+      echo -e "  --> test failed\n" | tee -a $out  
+      tsts=$(( 1 ))
+   else
+      echo -e "  --> success" |  tee -a $out
+      tsts=$(( 0 )) 
+   fi
+else
+   tsts=$(( 1 ))  
+fi 
+
+echo >> $out
+
+
+### docdiff clean tests
+
+if [ $tsts -eq 0 ]
+then
+  echo -e "docdiff.scala tests:" |  tee -a $out
+  echo -e "  clean(\"ab a abc\") == List(\"ab\", \"a\", \"abc\")" |  tee -a $out
+  echo -e "  clean(\"ab*a abc1\") == List(\"ab\", \"a\", \"abc1\")" |  tee -a $out
+
+  if (scala_assert "docdiff.scala" "docdiff_test1.scala")
+  then
+      echo -e "  --> success" |  tee -a $out
+      marks=$(( marks + 0.5 ))
+  else
+      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
+  fi
+fi
+
+### docdiff occurrences tests
+
+if [ $tsts -eq 0 ]
+then
+  echo -e "  occurrences(List(\"a\", \"b\", \"b\", \"c\", \"d\")) == " |  tee -a $out
+  echo -e "      Map(\"a\" -> 1, \"b\" -> 2, \"c\" -> 1, \"d\" -> 1)" |  tee -a $out
+  echo -e "  " |  tee -a $out
+  echo -e "  occurrences(List(\"d\", \"b\", \"d\", \"b\", \"d\")) == " |  tee -a $out
+  echo -e "      Map(\"d\" -> 3, \"b\" -> 2)" |  tee -a $out
+  echo -e "  " |  tee -a $out
+  echo -e "  occurrences(Nil) == Map() " |  tee -a $out
+  echo -e "  " |  tee -a $out
+  echo -e "  occurrences(List(\"b\", \"b\", \"b\", \"b\", \"b\")) == Map(\"b\" -> 5)" |  tee -a $out
+
+  if (scala_assert "docdiff.scala" "docdiff_test2.scala") 
+  then
+      echo -e "  --> success" |  tee -a $out
+      marks=$(( marks + 1.0 ))
+  else
+      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
+  fi
+fi
+
+### docdiff prod tests
+
+if [ $tsts -eq 0 ]
+then
+  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
+  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
+  echo -e "  " |  tee -a $out
+  echo -e "  prod(l1, l2) == 7 " |  tee -a $out
+  echo -e "  prod(l1, l1) == 7 " |  tee -a $out
+  echo -e "  prod(l2, l2) == 13 " |  tee -a $out
+  echo -e "  " |  tee -a $out
+  echo -e "  val l3 = List(\"1\", \"2\", \"3\", \"4\", \"5\")" |  tee -a $out
+  echo -e "  prod(l1, l3) == 0 " |  tee -a $out
+
+  if (scala_assert "docdiff.scala" "docdiff_test3.scala") 
+  then
+      echo -e "  --> success" |  tee -a $out
+      marks=$(( marks + 1.0 ))
+  else
+      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
+  fi
+fi
+
+### docdiff overlap tests
+
+if [ $tsts -eq 0 ]
+then
+  echo -e "  val l1 = List(\"a\", \"b\", \"b\", \"c\", \"d\")" |  tee -a $out
+  echo -e "  val l2 = List(\"d\", \"b\", \"d\", \"b\", \"d\")" |  tee -a $out
+  echo -e "  " |  tee -a $out
+  echo -e "  overlap(l1, l2) == 0.5384615384615384 " |  tee -a $out
+  echo -e "  overlap(l1, l1) == 1.0 " |  tee -a $out
+  echo -e "  overlap(l2, l2) == 1.0 " |  tee -a $out
+
+  if (scala_assert "docdiff.scala" "docdiff_test4.scala") 
+  then
+      echo -e "  --> success" |  tee -a $out
+      marks=$(( marks + 0.5 ))
+  else
+      echo -e "  --> ONE OF THE TESTS FAILED\n" |  tee -a $out
+  fi
+fi
+
+
+## final marks
+echo -e "Overall mark for the Preliminary Part 2 (Scala)" | tee -a $out
+printf " %0.1f\n" $marks | tee -a $out
+
+
+#echo -e " $marks" | tee -a $out
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/docdiff_test1.scala	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,5 @@
+
+import CW7a._
+
+assert(clean("ab a abc") == List("ab", "a", "abc"))
+assert(clean("ab*a abc1") == List("ab", "a", "abc1"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/docdiff_test2.scala	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,10 @@
+
+import CW7a._
+
+assert(occurrences(List("a", "b", "b", "c", "d")) == Map("a" -> 1, "b" -> 2, "c" -> 1, "d" -> 1))
+
+assert(occurrences(List("d", "b", "d", "b", "d")) == Map("d" -> 3, "b" -> 2))
+
+assert(occurrences(List("b", "b", "b", "b", "b")) == Map("b" -> 5))
+
+assert(occurrences(Nil) == Map())
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/docdiff_test3.scala	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,15 @@
+
+import CW7a._
+
+val urban_list1 = List("a", "b", "b", "c", "d")
+val urban_list2 = List("d", "b", "d", "b", "d")
+
+assert(prod(urban_list1, urban_list2) == 7)
+assert(prod(urban_list1, urban_list1) == 7)
+assert(prod(urban_list2, urban_list2) == 13)
+
+
+val urban_listA = List("a", "b", "b", "c", "d")
+val urban_listB = List("1", "2", "3", "4", "5")
+
+assert(prod(urban_listA, urban_listB) == 0)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/docdiff_test4.scala	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,9 @@
+
+import CW7a._
+
+val urban_list1 = List("a", "b", "b", "c", "d")
+val urban_list2 = List("d", "b", "d", "b", "d")
+
+assert(overlap(urban_list1, urban_list2) == 0.5384615384615384)
+assert(overlap(urban_list1, urban_list1) == 1.0)
+assert(overlap(urban_list2, urban_list2) == 1.0)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pre_marking2/mk	Wed Dec 02 01:15:14 2020 +0000
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -euo pipefail
+
+
+trap "exit" INT
+
+files=${1:-*/pre2}
+
+for sd in $files; do
+  cd $sd
+  echo $sd
+  touch .
+  cp ../../../../../pre_marking2/docdiff_test.sh .
+  cp ../../../../../pre_marking2/docdiff_test1.scala .
+  cp ../../../../../pre_marking2/docdiff_test2.scala .
+  cp ../../../../../pre_marking2/docdiff_test3.scala .
+  cp ../../../../../pre_marking2/docdiff_test4.scala .
+  ./docdiff_test.sh output
+  rm docdiff_test.sh
+  rm docdiff_test1.scala
+  rm docdiff_test2.scala
+  rm docdiff_test3.scala
+  rm docdiff_test4.scala
+  cd ..
+  cd ..
+done
+
+
--- a/progs/lecture4.scala	Mon Nov 30 12:58:37 2020 +0000
+++ b/progs/lecture4.scala	Wed Dec 02 01:15:14 2020 +0000
@@ -249,6 +249,10 @@
 // Source.fromFile(name)(encoding)
 
 
+
+
+
+
 // Sudoku 
 //========
 
Binary file slides/slides03.pdf has changed
--- a/slides/slides03.tex	Mon Nov 30 12:58:37 2020 +0000
+++ b/slides/slides03.tex	Wed Dec 02 01:15:14 2020 +0000
@@ -354,10 +354,25 @@
 % \end{frame}
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-\begin{frame}<1-10>
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+\begin{frame}[t]
+\frametitle{Preliminary 1 (Scala)}
+
+Raw marks (298 submissions):\bigskip
+
+\begin{itemize}
+\item 3\%: \hspace{4mm}227
+\item 2\%: \hspace{4mm}35
+\item 1\%: \hspace{4mm}9
+\item 0\%: \hspace{4mm}27 
+\end{itemize}
+
+
 \end{frame}
 
-\end{document}
+
+\begin{frame}<1-20>
+\end{frame}
 
 
 \end{document}
Binary file slides/slides04.pdf has changed