Swiddis / word-debt-bot

A Discord bot for running a little reading game.
MIT License
2 stars 2 forks source link

(New PR) Added leaderboard functionally and unit tests #17

Closed Gregory-Nitch closed 6 months ago

Gregory-Nitch commented 6 months ago

Targets Issue Leaderboard command #5

To avoid any further unnecessary notifications with actions taken to remedy the prior pull request I just created a new branch and properly pointed to dev as its upstream branch then applied changes too it. Afterwards I tested the functionally again and ran the unit tests again with working results.

Again, sorry for the confusion.

Implements

leaderboard() function in game_commands.py

create_leaderboard() method in core.py

test_game_rejects_invalid_leaderboard_length() in test_game.py

test_game_rejects_invalid_leaderboard_sorting() in test_game.py

test_game_produces_valid_leaderboard() in test_game.py

test_request_leaderboard_no_register() in test_game_commands.py

test_request_leaderboard_no_game() in test_game_commands.py

The default values for the leaderboard command are 'debt' and 5 therefore sending a bot message with the top 5 users based on debt, but users can input cranes and any other length.

Achieved functionality:

>.leaderboard
1. user1 - 10,000 debt - 0 cranes
2. user2 - 8,989 debt - 2 cranes

>.leaderboard cranes
1. user2 - 8,989 debt - 2 cranes
2. user1 - 10,000 debt - 0 cranes

>.leaderboard debt 1
1. user1 - 10,000 debt - 0 cranes

Though with this solution it requires the user to enter a sorting type if they wish to enter a leaderboard length requirement.

Unit Tests

test_game.py

test_game_rejects_invalid_leaderboard_length() Checks proper rejection of a requested leaderboard length < 1.

test_game_rejects_invalid_leaderboard_sorting() Checks proper rejection of an invalid sorting key, ie != "debt" or "cranes".

test_game_produces_valid_leaderboard() Checks proper leaderboard layout given 1 player and test values.

test_game_commands_cog.py

test_request_leaderboard_no_register() Checks command properly informs users if no one has registered and a leaderboard cannot be made.

test_request_leaderboard_no_game() Checks command properly informs users when the game has not been properly loaded.

-Greg