Example #1
0
 def test_nobody_should_be_return_when_no_satisfied_condition(self):
     a_game = Game(board_size=3)
     a_game.play(Position(0, 0))
     a_game.play(Position(0, 1))
     a_game.play(Position(1, 0))
     a_game.play(Position(1, 1))
     self.assertEqual(Nobody(), a_game.who_is_winner())
Example #2
0
 def test_playerX_should_win_with_negative_diagonal(self):
     a_game = Game(board_size=3)
     a_game.play(Position(2, 0))
     a_game.play(Position(0, 1))
     a_game.play(Position(1, 1))
     a_game.play(Position(1, 2))
     a_game.play(Position(0, 2))
     self.assertEqual(PlayerX(), a_game.who_is_winner())
Example #3
0
 def test_X_should_win_if_fills_column_number_0(self):
     a_game = Game(board_size=3)
     a_game.play(Position(0, 0))
     a_game.play(Position(0, 1))
     a_game.play(Position(1, 0))
     a_game.play(Position(1, 1))
     a_game.play(Position(2, 0))
     self.assertEqual(PlayerX(), a_game.who_is_winner())
Example #4
0
 def test_for_draw_game_should_return_draw_result(self):
     a_game = Game(board_size=3)
     a_game.play(Position(0, 0))
     a_game.play(Position(0, 1))
     a_game.play(Position(0, 2))
     a_game.play(Position(1, 0))
     a_game.play(Position(1, 1))
     a_game.play(Position(2, 0))
     a_game.play(Position(1, 2))
     a_game.play(Position(2, 2))
     a_game.play(Position(2, 1))
     self.assertEqual(Draw(), a_game.who_is_winner())
Example #5
0
 def test_O_should_win_if_fills_row_number_1(self):
     a_game = Game(board_size=3)
     a_game.play(Position(0, 0))
     a_game.play(Position(1, 0))
     a_game.play(Position(0, 1))
     a_game.play(Position(1, 1))
     a_game.play(Position(2, 2))
     a_game.play(Position(1, 2))
     self.assertEqual(PlayerO(), a_game.who_is_winner())
Example #6
0
 def test_playerO_and_playerX_cant_play_in_same_position(self):
     a_game = Game(board_size=2)
     initial_position = Position(0, 0)
     a_game.play(initial_position)
     with self.assertRaises(PositionAlreadyTaken):
         a_game.play(initial_position)
Example #7
0
 def test_second_player_should_be_O(self):
     a_game = Game(board_size=2)
     a_game.play(Position(0, 0))
     self.assertEqual(PlayerO(), a_game.get_current_player())
Example #8
0
 def test_game_with_size_board_to_one_should_has_player_x_as_winner(self):
     a_game = Game(board_size=1)
     a_game.play(Position(0, 0))
     self.assertEqual(PlayerX(), a_game.who_is_winner())
Example #9
0
 def test_already_taken_position_should_raise(self):
     a_row = Board(2)
     a_row.put_mark_in_board(Position(1, 0), MarkX())
     with self.assertRaises(PositionAlreadyTaken):
         a_row.put_mark_in_board(Position(1, 0), MarkO())
Example #10
0
 def test_negative_row_number_should_raise_error(self):
     a_row = Board(2)
     with self.assertRaises(InvalidPosition):
         a_row.put_mark_in_board(Position(-1, 0), MarkX())
Example #11
0
 def test_update_board_with_X_should_not_be_equal_to_created_board(self):
     a_board = Board(2)
     a_board.put_mark_in_board(Position(1, 0), MarkX())
     self.assertNotEqual(Board(2), a_board)