main_marking5/bf_test6.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 26 Apr 2024 17:37:56 +0100
changeset 488 5deaf53c2faa
parent 463 0315d9983cd0
permissions -rw-r--r--
updated

import M5b._

import io.Source
import scala.util._

def urban_load_bff(name: String) : String = 
  Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")

import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
import scala.language.postfixOps 

lazy val f = Future {
  assert(optimise(urban_load_bff("benchmark.bf")).length == 181)
  assert(optimise(urban_load_bff("sierpinski.bf")).length == 110)

  assert(run3("[-]", Map(0 -> 100)) == Map(0 -> 0))
  assert(run3("[->+<]", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10))
  assert(run3("[>>+>>+<<<<-]", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42))
  val hw_urban2 = """+++++[->++++++++++<]>--<+++[->>++++++++++
                  <<]>>++<<----------[+>.>.<+<]"""
  assert(run3(hw_urban2) == Map(0 -> 0, 1 -> 58, 2 -> 32))

  val hw_urban3 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.
                   +++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."""

  assert(run3(hw_urban3) == Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87))

}

Await.result(f, 32 second)