diff -r 1e6eca42d90b -r 8778d23fef92 cw3_marking/c4.sc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cw3_marking/c4.sc Mon Feb 03 12:34:38 2025 +0000 @@ -0,0 +1,19 @@ +// for testing evaluation + +import scala.util.{Try, Success, Failure} +import $file.cw034_add +import cw034_add._ + +val str = os.read(os.pwd / "primes.while") +val resmap = Map("end" -> 100, "n" -> 100, "f" -> 4, "tmp" -> 1) + +def mapeq[A, B](m1: Map[A, B], m2: Map[A, B]) : Boolean = { + m1.keySet.forall(k => m1(k) == m2(k)) +} + + +Try(test_string(str)) match { + case Success(v) if mapeq(resmap, v) => Console.println(s" Generated the correct result $v") + case Success(v) => Console.println(s" Generated $v\n instead of\n $resmap\n.") ; throw new Exception("Different") + case Failure(e) => Console.println(s" Exception raised.") ; throw(e) +}