Permalink
Browse files

more Game tests

  • Loading branch information...
1 parent 2846cfd commit 2030f3c04cdf3951ff39fbe72f2ee07e7b78828e @sl4m committed Nov 25, 2010
Showing with 45 additions and 1 deletion.
  1. +1 −1 TicTacToe-Core/Game.st
  2. +44 −0 TicTacToe-Core/GameTest.st
View
@@ -77,7 +77,7 @@ Object subclass: Game [
whileFalse: [
self makeMove: self currentPlayer.
].
- self endOfPlay.
+ self endOfPlay.
]
endOfPlay [
View
@@ -64,4 +64,48 @@ TicTacToeTestCase subclass: GameTestCase [
game makeMove: human.
self assert: ((game currentPlayer) = negamax).
]
+
+ testDisplayEndMessageWhenSomeoneIsWinner [
+ board move: 1 piece: 'O'.
+ board move: 2 piece: 'O'.
+ board move: 3 piece: 'O'.
+
+ game displayEndMessage.
+ self assert: ((fakeStdOut message) = 'The winner is O!!!').
+ ]
+
+ testDisplayEndMessageWhenGameIsDraw [
+ game displayEndMessage.
+ self assert: ((fakeStdOut message) = 'The game is a draw.').
+ ]
+
+ testEndOfPlayWhenSomeoneIsWinner [
+ board move: 1 piece: 'X'.
+ board move: 2 piece: 'X'.
+ board move: 3 piece: 'X'.
+
+ game endOfPlay.
+ self assert: ((fakeStdOut message) = 'The winner is X!!!Do you want to play again? (''y'' or ''n'') ').
+ ]
+
+ testEndOfPlayWhenGameIsDraw [
+ game endOfPlay.
+ self assert: ((fakeStdOut message) = 'The game is a draw.Do you want to play again? (''y'' or ''n'') ')
+ ]
+
+ testPlayOnLastMove [
+ board move: 1 piece: 'X'.
+ board move: 2 piece: 'O'.
+ board move: 3 piece: 'X'.
+ board move: 4 piece: 'O'.
+ board move: 5 piece: 'O'.
+ board move: 6 piece: 'X'.
+ board move: 7 piece: 'X'.
+ board move: 9 piece: 'O'.
+
+ fakeStdIn nextLine: '8'.
+ game play.
+ self assert: (board isGameOver).
+ self assert: ((board winner) = (board noWinner)).
+ ]
]

0 comments on commit 2030f3c

Please sign in to comment.