Skip to content

Commit c7bda72

Browse files
yothenbergpybites
authored andcommitted
I fixed a bug that was mutating the draw list during validation. (pybites#154)
I added a test to check for a mutated draw during validation.
1 parent cf6a0d8 commit c7bda72

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

02/game.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ def input_word(draw):
2828

2929

3030
def _validation(word, draw):
31+
unused_letters = list(draw) # copied because we are mutating the list
3132
for char in word.upper():
32-
if char in draw:
33-
draw.remove(char)
33+
if char in unused_letters:
34+
unused_letters.remove(char)
3435
else:
3536
raise ValueError("{} is not a valid word!".format(word))
3637
if not word.lower() in DICTIONARY:

02/test_game.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ def test_get_possible_dict_words(self):
4040
self.assertEqual(len(words), 137)
4141

4242
def test_validation(self):
43-
draw = list('garytev'.upper())
43+
letters = list('garytev'.upper())
44+
draw = list(letters)
4445
word = 'GARYTEV'
4546
self.assertRaises(ValueError, _validation, word, draw)
4647
word = 'F'
4748
self.assertRaises(ValueError, _validation, word, draw)
4849
word = 'GARETTA'
4950
self.assertRaises(ValueError, _validation, word, draw)
51+
self.assertEqual(letters, draw)
5052

5153
if __name__ == "__main__":
5254
unittest.main()

0 commit comments

Comments
 (0)