Exemplo n.º 1
0
def test_reversi_put():
    game = Reversi()
    game.reset()
    assert game.put(2, 4)
    assert game.history[-1] == [(3, 4), (2, 4)]
    assert not game.put(2, 4)
    assert not game.put(0, 0)
    assert not game.put((0, 0))  # Tuple unpacking test
    assert game.put((2, 3))
Exemplo n.º 2
0
def test_reversi_hash():
    import random
    game = Reversi()
    s = set()
    s.add(game)
    assert len(s) == 1
    for i in range(12):
        game.put(random.choice(game.getAvailables()))
        assert game not in s
        s.add(game)
Exemplo n.º 3
0
def test_reversi_copy():
    game = Reversi()
    game.reset()
    game.put(2, 4)
    other = game.copy()
    assert game is not other
    assert game.board == other.board
    assert all(a is not b for a, b in zip(game.board, other.board))
    assert game.current == other.current
    assert game.history == other.history
    assert all(a is not b for a, b in zip(game.history, other.history))
Exemplo n.º 4
0
def test_reversi_undo():
    game_1, game_2 = Reversi(), Reversi()
    game_1.reset()
    game_2.reset()
    assert game_1.board == game_2.board
    assert game_1.history == game_2.history == []
    assert game_1.undo() == (False, 0)
    game_1.put(2, 4)
    assert game_1.board != game_2.board
    assert game_1.history != game_2.history
    assert game_1.undo() == (True, 2)
    assert game_1.board == game_2.board
    assert game_1.history == game_2.history

    game_1.history.append([])
    game_1.toggle()
    assert game_1.undo() == (True, 0)
Exemplo n.º 5
0
def test_reversi_lastChess():
    game = Reversi()
    game.reset()
    assert game.lastChess is None
    game.put(2, 4)
    assert game.lastChess == (2, 4)