cw5_marking/c2.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 tokenisation

import scala.util.{Try, Success, Failure}
import $file.cw05_add
import cw05_add._

// programs to test (and number of toplevel definitions)
val uprogs = List(("fact.fun",  5), 
                  ("hanoi.fun", 2),
		  ("mand.fun", 11), 
		  ("sqr.fun",   4)) 

for ((file, no) <- uprogs) {

  print(s"Testing Parsing of $file ")
  val str = os.read(os.pwd / file)
  

  Try(test_string(str).length) match {
    case Success(v) if v == no => println(s"--> Success. Parsed $no top-level definitions.")
    case Success(v) => println(s"--> Success? Parsed $v top-level definitions (should be $no).")// ; throw new Exception("Different")
    case Failure(e) => println(s"--> FAIL. Exception raised.") ; throw(e)
  }
}