cw3_marking/c4.sc
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 03 Feb 2025 13:25:59 +0000
changeset 980 0c491eff5b01
parent 978 8778d23fef92
permissions -rw-r--r--
updated

// 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)
}