summaryrefslogtreecommitdiffstats
path: root/Scala/streams/src/test/scala/streams/BloxorzSuite.scala
diff options
context:
space:
mode:
Diffstat (limited to 'Scala/streams/src/test/scala/streams/BloxorzSuite.scala')
-rw-r--r--Scala/streams/src/test/scala/streams/BloxorzSuite.scala67
1 files changed, 67 insertions, 0 deletions
diff --git a/Scala/streams/src/test/scala/streams/BloxorzSuite.scala b/Scala/streams/src/test/scala/streams/BloxorzSuite.scala
new file mode 100644
index 0000000..3f9329b
--- /dev/null
+++ b/Scala/streams/src/test/scala/streams/BloxorzSuite.scala
@@ -0,0 +1,67 @@
+package streams
+
+import org.scalatest.FunSuite
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import Bloxorz._
+
+@RunWith(classOf[JUnitRunner])
+class BloxorzSuite extends FunSuite {
+
+ trait SolutionChecker extends GameDef with Solver with StringParserTerrain {
+ /**
+ * This method applies a list of moves `ls` to the block at position
+ * `startPos`. This can be used to verify if a certain list of moves
+ * is a valid solution, i.e. leads to the goal.
+ */
+ def solve(ls: List[Move]): Block =
+ ls.foldLeft(startBlock) { case (block, move) => move match {
+ case Left => block.left
+ case Right => block.right
+ case Up => block.up
+ case Down => block.down
+ }
+ }
+ }
+
+ trait Level1 extends SolutionChecker {
+ /* terrain for level 1*/
+
+ val level =
+ """ooo-------
+ |oSoooo----
+ |ooooooooo-
+ |-ooooooooo
+ |-----ooToo
+ |------ooo-""".stripMargin
+
+ val optsolution = List(Right, Right, Down, Right, Right, Right, Down)
+ }
+
+ test("terrain function level 1") {
+ new Level1 {
+ assert(terrain(Pos(0,0)), "0,0")
+ assert(!terrain(Pos(4,11)), "4,11")
+ }
+ }
+
+ test("findChar level 1") {
+ new Level1 {
+ assert(startPos == Pos(1,1))
+ }
+ }
+
+ test("optimal solution for level 1") {
+ new Level1 {
+ assert(solve(solution) == Block(goal, goal))
+ }
+ }
+
+ test("optimal solution length for level 1") {
+ new Level1 {
+ assert(solution.length == optsolution.length)
+ }
+ }
+}