cw5_marking/c6.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 compilation
import scala.util.{Try, Success, Failure}

//println("TEST1")

val res = {
  if (os.exists(os.pwd / "sqr.ll")) 
    os.proc("lli", "sqr.ll").call(cwd = os.pwd, check = false)
  else throw new Exception("No CLASS file found")
}

//println("TEST2")

/*
if (res.exitCode != 0) {
  throw new Exception("Unsuccessful call")
}
*/

def pp(s1: String, s2: String) = {
  val s1a = s1.replace("\n","").replace(" ","")
  val s2a = s2.replace("\n","")
  s1a == s2a
}

//println("TEST3")

val out = "Squares0149162536496481100"
val out2 = "\"Squares\"0149162536496481100"


//println("TEST4")

Try(res.out.text()) match {
  case Success(v) if (pp(v, out) || pp(v, out2)) => println(s"   Success. Printed out the correct output.\n")
  case Success(v) => println(s"   Printed out wrong or no output.\n${v}") ; throw new Exception("Wrong Output")
  case Failure(e) => println(s"   Fail. Printed ${res.out.text()} instead\n") ; throw(e)
}