424
|
1 |
import M5b._
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
|
463
|
3 |
import io.Source
|
|
4 |
import scala.util._
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
|
463
|
6 |
def urban_load_bff(name: String) : String =
|
|
7 |
Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
|
463
|
9 |
import scala.concurrent._
|
|
10 |
import scala.concurrent.duration._
|
|
11 |
import ExecutionContext.Implicits.global
|
|
12 |
import scala.language.postfixOps
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
|
463
|
14 |
lazy val f = Future {
|
|
15 |
assert(optimise(urban_load_bff("benchmark.bf")).length == 181)
|
|
16 |
assert(optimise(urban_load_bff("sierpinski.bf")).length == 110)
|
|
17 |
|
|
18 |
assert(run3("[-]", Map(0 -> 100)) == Map(0 -> 0))
|
|
19 |
assert(run3("[->+<]", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10))
|
|
20 |
assert(run3("[>>+>>+<<<<-]", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42))
|
|
21 |
val hw_urban2 = """+++++[->++++++++++<]>--<+++[->>++++++++++
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
<<]>>++<<----------[+>.>.<+<]"""
|
463
|
23 |
assert(run3(hw_urban2) == Map(0 -> 0, 1 -> 58, 2 -> 32))
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
|
463
|
25 |
val hw_urban3 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.
|
392
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."""
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
|
463
|
28 |
assert(run3(hw_urban3) == Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87))
|
|
29 |
|
|
30 |
}
|
|
31 |
|
|
32 |
Await.result(f, 32 second)
|
|
33 |
|