diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-05-17 16:43:31 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 18:03:25 +0100 |
commit | d8d74ed55984d2ae39cbdb965dd42bba984735a9 (patch) | |
tree | 592cafc584e08ce997378f69f86ebf4d80d44674 /Scala/streams/src/test | |
parent | 12a9fca3908dc0b9bf7d51abd37db542b4600bb1 (diff) | |
download | coursera-d8d74ed55984d2ae39cbdb965dd42bba984735a9.zip coursera-d8d74ed55984d2ae39cbdb965dd42bba984735a9.tar.gz |
Scala : add streams assignment
Diffstat (limited to 'Scala/streams/src/test')
-rw-r--r-- | Scala/streams/src/test/scala/streams/BloxorzSuite.scala | 67 |
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) + } + } +} |