예제 #1
0
def test_move_into_unclaimed():
    engine = TicTacToe()
    engine.move(PLAYER_X, 0)

    assert_equal(engine.winner, None)
    assert_equal(engine.squares, [PLAYER_X, None, None, None, None, None, None, None, None])
    assert_equal(engine.moves, [(PLAYER_X, 0)])
예제 #2
0
def test_move_wins():
    engine = TicTacToe()

    engine.move(PLAYER_X, 0)
    engine.move(PLAYER_O, 3)
    assert_equal(engine.winner, None)

    engine.move(PLAYER_X, 1)
    engine.move(PLAYER_O, 4)
    assert_equal(engine.winner, None)

    engine.move(PLAYER_X, 2)
    engine.move(PLAYER_O, 5)
    assert_equal(engine.winner, PLAYER_X)
예제 #3
0
def test_load():
    engine = TicTacToe.load(FINISH_GAMESTATE)

    assert_equal(engine.winner, PLAYER_O)
    assert_equal(engine.squares, [PLAYER_X, PLAYER_X, PLAYER_O, PLAYER_O, PLAYER_O, PLAYER_O, PLAYER_X, PLAYER_X, None])

    assert_equal(
        engine.moves,
        [
            (PLAYER_X, 7),
            (PLAYER_O, 3),
            (PLAYER_X, 6),
            (PLAYER_O, 2),
            (PLAYER_X, 0),
            (PLAYER_O, 4),
            (PLAYER_X, 1),
            (PLAYER_O, 5),
        ],
    )
예제 #4
0
def test_unplayable():
    engine = TicTacToe.load(FINISH_GAMESTATE)
    assert_equal(engine.playable(0), False)
예제 #5
0
def test_playable():
    engine = TicTacToe.load(FINISH_GAMESTATE)
    assert_equal(engine.playable(8), True)
예제 #6
0
def test_dump():
    engine = TicTacToe()
    assert_equal(engine.dump(), EMPTY_GAMESTATE)
예제 #7
0
def test_move_cats():
    engine = TicTacToe()
    [engine.move(p, sq) for p, sq in build_move_list([0, 4, 8, 7, 1, 2, 6, 3, 5])]

    assert_equal(engine.winner, "cats")
예제 #8
0
def test_not_winner():
    engine = TicTacToe()
    [engine.move(p, sq) for p, sq in build_move_list([0, 4, 8, 6, 2])]

    assert_equal(engine.is_winner(PLAYER_X, 7), False)
예제 #9
0
def test_move_out_of_bounds():
    engine = TicTacToe()
    engine.move(PLAYER_X, 9)
예제 #10
0
def test_move_into_claimed():
    engine = TicTacToe()
    engine.move(PLAYER_X, 0)
    engine.move(PLAYER_O, 0)