-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(8ball): Refactor to allow testing of choice logic
We parametrise the class with a source of randomness so it can be fixed with a seed in the tests
- Loading branch information
Showing
2 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from random import Random | ||
|
||
from discord import Intents | ||
from discord.ext.commands import Bot | ||
|
||
from cogs.commands.eightball import EightBall | ||
|
||
|
||
def test_eightball_no_question(): | ||
eightball = EightBall(Bot("/", intents=Intents()), Random(1), []) | ||
|
||
assert ( | ||
eightball.execute("test", []) | ||
== "test: You must pose the Magic 8-ball a dilemma!" | ||
) | ||
|
||
|
||
def test_eightball_question_with_fixed_randomness(): | ||
eightball = EightBall( | ||
Bot("/", intents=Intents()), Random(1), ["Yes", "No", "Maybe"] | ||
) | ||
|
||
answers = [ | ||
eightball.execute("test", ["Should", "I", "eat", "cake?"]) for i in range(0, 7) | ||
] | ||
|
||
assert answers == [ | ||
"test: Yes", | ||
"test: Maybe", | ||
"test: Yes", | ||
"test: No", | ||
"test: Yes", | ||
"test: No", | ||
"test: No", | ||
] |