Example #1
0
    def test_large_voting_result(
        caplog: pytest.LogCaptureFixture,
        large_game_roles: tuple[Role, ...],
        large_individual_preds: tuple[tuple[Role, ...], ...],
    ) -> None:
        """Should get voting results from the individual predictions."""
        player_list = tuple(Player(i) for i in range(len(large_game_roles)))

        result = one_night.get_voting_result(player_list,
                                             large_individual_preds)

        assert result == (
            (
                Role.VILLAGER,
                Role.MASON,
                Role.MASON,
                Role.MINION,
                Role.VILLAGER,
                Role.DRUNK,
                Role.TANNER,
                Role.TROUBLEMAKER,
                Role.VILLAGER,
                Role.WOLF,
                Role.WOLF,
                Role.HUNTER,
                Role.INSOMNIAC,
                Role.SEER,
                Role.ROBBER,
            ),
            (10, ),
            (10, 10, 7, 5, 7, 10, 7, 10, 6, 10, 3, 10),
        )
        verify_output_string(
            caplog, "\nVote Array: [0, 0, 0, 1, 0, 1, 1, 3, 0, 0, 6, 0]\n")
Example #2
0
    def test_constructor() -> None:
        """Should initialize a Player."""
        player_index = 5

        empty_player = Player(player_index)

        assert empty_player.role is Role.NONE
        assert empty_player.statements == ()
Example #3
0
    def test_vote_right(small_game_roles: tuple[str, ...]) -> None:
        """
        If no Wolves are found, players should vote for the person to their right.
        """
        prediction = (Role.VILLAGER, Role.SEER, Role.ROBBER)

        result = [Player(i).vote(prediction) for i in range(const.NUM_PLAYERS)]

        assert result == [1, 2, 0]
Example #4
0
    def test_small_voting_result(caplog: pytest.LogCaptureFixture,
                                 small_game_roles: tuple[Role, ...]) -> None:
        """Should get voting results from the individual predictions."""
        indiv_preds = (
            (Role.VILLAGER, Role.SEER, Role.ROBBER), ) * len(small_game_roles)
        player_list = tuple(Player(i) for i in range(len(small_game_roles)))

        result = one_night.get_voting_result(player_list, indiv_preds)

        assert result == ((Role.VILLAGER, Role.SEER, Role.ROBBER), (0, 1, 2),
                          (1, 2, 0))
        verify_output_string(caplog, "\nVote Array: [1, 1, 1]\n")
Example #5
0
    def test_vote_for_wolf(medium_game_roles: tuple[str, ...]) -> None:
        """If a player suspects a Wolf, they should vote for that player."""
        prediction = (
            Role.SEER,
            Role.WOLF,
            Role.TROUBLEMAKER,
            Role.DRUNK,
            Role.MINION,
            Role.ROBBER,
        )

        result = Player(2).vote(prediction)

        assert result == 1
Example #6
0
    def test_interactive_vote(monkeypatch: pytest.MonkeyPatch,
                              medium_game_roles: tuple[str, ...]) -> None:
        """Prompt the user for their vote."""
        player_index = 2
        const.IS_USER[player_index] = True
        prediction = (
            Role.SEER,
            Role.TROUBLEMAKER,
            Role.DRUNK,
            Role.MINION,
            Role.ROBBER,
            Role.WOLF,
        )
        monkeypatch.setattr("builtins.input", lambda x: "4")

        result = Player(player_index).vote(prediction)

        assert result == 4
Example #7
0
    def test_medium_voting_result(caplog: pytest.LogCaptureFixture,
                                  medium_game_roles: tuple[Role, ...]) -> None:
        """Should get voting results from the individual predictions."""
        indiv_preds = (
            (
                Role.SEER,
                Role.WOLF,
                Role.TROUBLEMAKER,
                Role.DRUNK,
                Role.MINION,
                Role.ROBBER,
            ),
            (
                Role.WOLF,
                Role.SEER,
                Role.ROBBER,
                Role.MINION,
                Role.TROUBLEMAKER,
                Role.DRUNK,
            ),
            (
                Role.SEER,
                Role.WOLF,
                Role.TROUBLEMAKER,
                Role.DRUNK,
                Role.MINION,
                Role.ROBBER,
            ),
            (
                Role.WOLF,
                Role.MINION,
                Role.TROUBLEMAKER,
                Role.DRUNK,
                Role.SEER,
                Role.ROBBER,
            ),
            (
                Role.WOLF,
                Role.MINION,
                Role.TROUBLEMAKER,
                Role.DRUNK,
                Role.SEER,
                Role.ROBBER,
            ),
        )
        player_list = tuple(Player(i) for i in range(len(medium_game_roles)))

        result = one_night.get_voting_result(player_list, indiv_preds)

        assert result == (
            (
                Role.SEER,
                Role.WOLF,
                Role.TROUBLEMAKER,
                Role.DRUNK,
                Role.MINION,
                Role.ROBBER,
            ),
            (0, ),
            (1, 0, 1, 0, 0),
        )
        verify_output_string(caplog, "\nVote Array: [3, 2, 0, 0, 0]\n")