Created
April 3, 2013 16:33
-
-
Save chbatey/5302877 to your computer and use it in GitHub Desktop.
A snippet from ScalaTest of 7 languages in 7 weeks Scala day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoardSuite extends FunSuite with BeforeAndAfter { | |
var board : Board = _ | |
before { | |
board = new Board | |
} | |
test("A board is initialized to blank") { | |
board.moves.foreach(row => row.foreach(box => assert(box === Player.B))) | |
} | |
test("Making the first move is marked X") { | |
board.move(1, 1) | |
assert(board.moves(1)(1) === Player.x) | |
} | |
test("Making the second move is marked o") { | |
board.move(1, 1) | |
board.move(1, 2) | |
assert(board.moves(2)(1) === Player.o) | |
} | |
test("Cant use the same place twice") { | |
board.move(1, 1) | |
intercept[RuntimeException] { | |
otherPlayersMove(1, 1) | |
} | |
} | |
test("No winner after no moves") { | |
val winner = board.winner() | |
println(board) | |
assert(winner === Player.B) | |
} | |
test("Win vertical line on left") { | |
board.move(0,0) | |
otherPlayersMove(1,0) | |
board.move(0,1) | |
otherPlayersMove(1,1) | |
board.move(0,2) | |
println(board) | |
assert(Player.x === board.winner) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment