def state(): games = {"game2": Game(word="game2word", guesses=set(), client_ids={0})} history = { "game1": Event("game1word", "won"), "game0": Event("game0word", "lost") } return State(games, history, next_client_id=1)
def test_create_game(state): broadcasts, response = server.apply_command(state, command="create", args=["game3", "hangman"], client_id=0) assert Game(word="hangman", guesses=set(), client_ids=set()) == state.games['game3']
def test_leave_game(state): broadcasts, response = server.apply_command(state, command="leave", args=["game2"], client_id=0) assert Game(word="game2word", guesses=set(), client_ids=set()) == state.games['game2'] assert {} == broadcasts
def test_join_game(state): broadcasts, response = server.apply_command(state, command="join", args=["game2"], client_id=1) assert Game(word="game2word", guesses=set(), client_ids={0, 1}) == state.games['game2'] assert {} == broadcasts
def test_create_game_fails_when_game_already_exists(state): broadcasts, response = server.apply_command(state, command="create", args=["game2", "hangman"], client_id=0) assert Game(word="game2word", guesses=set(), client_ids={0}) == state.games['game2'] assert "error > game game2 already exists" == response
def test_guess_char(state): broadcasts, response = server.apply_command(state, command="guess", args=["game2", "w"], client_id=0) assert Game(word="game2word", guesses=set("w"), client_ids={0}) == state.games['game2'] assert {"game2": "game2: _____w___ (w) (lives: 8)"} == broadcasts
def test_leave_game_fails_for_game_not_joined(state): broadcasts, response = server.apply_command(state, command="leave", args=["game2"], client_id=1) assert Game(word="game2word", guesses=set(), client_ids={0}) == state.games['game2'] assert {} == broadcasts assert "error > not playing game game2"
def test_guess_fails_for_multiple_chars(state): broadcasts, response = server.apply_command(state, command="guess", args=["game2", "no"], client_id=0) assert Game(word="game2word", guesses=set(), client_ids={0}) == state.games['game2'] assert {} == broadcasts assert "error > can only guess one char at a time" == response