From d8d74ed55984d2ae39cbdb965dd42bba984735a9 Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Fri, 17 May 2013 16:43:31 +0200 Subject: Scala : add streams assignment --- .../src/test/scala/streams/BloxorzSuite.scala | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Scala/streams/src/test/scala/streams/BloxorzSuite.scala (limited to 'Scala/streams/src/test') 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) + } + } +} -- cgit v1.2.3