You're developing a knock-off Scrabble game. You've implemented a Scrabble
class that initializes with a specific list of characters, ['s', 'a', 'r', 'b', 'k', 'r', 'e']
. It has a play_word(self, word: str)
method that doesn't do anything, but it does throw an error if the word you try to play can't be formed from the list of letters
.
For example,
-
Instantiate a new Scrabble game
-
Play a valid word
-
Play an invalid word
Write a test to confirm that playing an invalid word raises the correct ScrabbleWordException
.
Directory Structure¶
Solution¶
Explanation¶
-
First we need to import
pytest
andscrabble
stuff. -
Instantiate a new Scrabble instance.
-
Make sure the preset letters are what we believe them to be!
-
Use
pytest.raises()
to confirm thatscrabble.play_word('meatloaf')
generates aScrabbleWordException
with an error message like "can't form the word 'meatloaf'".