def test_create_game_already_in_game(self): first_game = Game._create_game(self.alice) second_game = Game._create_game(self.alice) self.assertEquals(first_game.turn, None) self.assertEquals(first_game.player1, self.alice) self.assertEquals(first_game.player2, None) self.assertEquals(first_game.winner, None) self.assertEquals(Game.current_game(self.alice), second_game) self.assertEquals(second_game.turn, None) self.assertEquals(second_game.player1, self.alice) self.assertEquals(second_game.player2, None) self.assertEquals(second_game.winner, None)
def test_winning_move_diagonal_upper_left(self): """ 000A000 00AB000 0AAA000 ABBB000 BAAA000 ABBB00B """ game = Game._create_game(self.alice) game.join(self.bob) game.move(self.alice, 0) game.move(self.bob, 0) game.move(self.alice, 0) game.move(self.bob, 1) game.move(self.alice, 1) game.move(self.bob, 1) game.move(self.alice, 1) game.move(self.bob, 2) game.move(self.alice, 2) game.move(self.bob, 2) game.move(self.alice, 2) game.move(self.bob, 6) game.move(self.alice, 2) game.move(self.bob, 3) game.move(self.alice, 3) game.move(self.bob, 3) game.move(self.alice, 3) game.move(self.bob, 3) self.assertEqual(game.winner, None) game.move(self.alice, 3) self.assertEqual(game.winner, self.alice)
def test_winning_move_diagonal_upper_right(self): """ 000A000 000BA00 000AAA0 000BBBA 000AAAB B00BBBA """ game = Game._create_game(self.alice) game.join(self.bob) game.move(self.alice, 6) game.move(self.bob, 6) game.move(self.alice, 6) game.move(self.bob, 5) game.move(self.alice, 5) game.move(self.bob, 5) game.move(self.alice, 5) game.move(self.bob, 4) game.move(self.alice, 4) game.move(self.bob, 4) game.move(self.alice, 4) game.move(self.bob, 0) game.move(self.alice, 4) game.move(self.bob, 3) game.move(self.alice, 3) game.move(self.bob, 3) game.move(self.alice, 3) game.move(self.bob, 3) self.assertEqual(game.winner, None) game.move(self.alice, 3) self.assertEqual(game.winner, self.alice)
def test_stalemate(self): """ BBBABBB AAABAAA BBBABBB AAABAAA BBBABBB AAABAAA """ game = Game._create_game(self.alice) game.join(self.bob) for _ in range(3): game.move(self.alice, 0) game.move(self.bob, 0) game.move(self.alice, 1) game.move(self.bob, 1) game.move(self.alice, 2) game.move(self.bob, 2) game.move(self.alice, 4) game.move(self.bob, 3) game.move(self.alice, 3) game.move(self.bob, 4) game.move(self.alice, 5) game.move(self.bob, 5) game.move(self.alice, 6) game.move(self.bob, 6) self.assertEqual(game.stalemate, True) self.assertEqual(game.winner, None)
def test_move_taking_turns(self): game = Game._create_game(self.alice) game.join(self.bob) self.assertEquals(game.turn, self.alice) game.move(self.alice, 0) self.assertEquals(game.turn, self.bob) game.move(self.bob, 1) self.assertEquals(game.turn, self.alice)
def test_get_with_token(self): game = Game._create_game(self.alice) game.join(self.bob) column = Column.objects.get(game=game, index=0) slot = Slot.objects.get(column=column, index=Game.row_count - 1) slot.player = self.alice slot.save() self.assertEquals(game.get_board()[Game.row_count - 1][0], self.alice)
def test_create_game(self): game = Game._create_game(self.alice) self.assertEquals(game.turn, None) self.assertEquals(game.player1, self.alice) self.assertEquals(game.player2, None) self.assertEquals(game.winner, None) self.assertEquals(Column.objects.filter(game=game).count(), Game.column_count) for col in Column.objects.filter(game=game): self.assertEquals(Slot.objects.filter(column=col).count(), Game.row_count)
def test_move_full_column(self): game = Game._create_game(self.alice) game.join(self.bob) game.move(self.alice, 0) game.move(self.bob, 0) game.move(self.alice, 0) game.move(self.bob, 0) game.move(self.alice, 0) game.move(self.bob, 0) self.assertRaises(IllegalMove, game.move, self.alice, 0)
def test_winning_move_horizontal(self): game = Game._create_game(self.alice) game.join(self.bob) game.move(self.alice, 0) game.move(self.bob, 0) game.move(self.alice, 1) game.move(self.bob, 1) game.move(self.alice, 2) game.move(self.bob, 2) game.move(self.alice, 3) self.assertEqual(game.winner, self.alice)
def test_move_stacking_tokens(self): game = Game._create_game(self.alice) game.join(self.bob) game.move(self.alice, 0) game.move(self.bob, 0) game.move(self.alice, 0) board = game.get_board() self.assertEquals(board[Game.row_count - 1][0], self.alice) self.assertEquals(board[4][0], self.bob) self.assertEquals(board[3][0], self.alice) self.assertEquals(game.winner, None) self.assertEquals(game.stalemate, False)
def test_move(self): game = Game._create_game(self.alice) game.join(self.bob) game.move(self.alice, 0) self.assertEquals(game.get_board()[Game.row_count - 1][0], self.alice)
def test_get_board_empty(self): game = Game._create_game(self.alice) game.join(self.bob) for row in game.get_board(): for col in row: self.assertEquals(col, None)
def test_move_one_player(self): game = Game._create_game(self.alice) self.assertRaises(IllegalMove, game.move, self.alice, 0)
def test_join_full_game(self): game = Game._create_game(self.alice) game.join(self.bob) self.assertRaises(GameFull, game.join, self.casey)
def test_join_game(self): game = Game._create_game(self.alice) game.join(self.bob) self.assertEquals(game.turn, self.alice) self.assertEquals(game.player1, self.alice) self.assertEquals(game.player2, self.bob)
def test_move_not_your_turn(self): game = Game._create_game(self.alice) game.join(self.bob) self.assertRaises(IllegalMove, game.move, self.bob, 0)
def test_move_invalid_player(self): game = Game._create_game(self.alice) game.join(self.bob) self.assertRaises(IllegalMove, game.move, self.casey, 0)
def test_move_invalid_column(self): game = Game._create_game(self.alice) game.join(self.bob) self.assertRaises(IllegalMove, game.move, self.alice, 7)