Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit d7e6615

Browse files
committed
Updated tests and reference impl to solve issue 143
1 parent b162ef7 commit d7e6615

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

exercises/final_exam/assignment/functional_tests.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def check_guess(self, guess, word):
6565
# check for chars are wrong position
6666
for i, l in enumerate(guess):
6767
if l in word_list:
68-
result[i] = "O"
69-
word_list[word_list.index(l)] = " "
68+
if result[i] != "X":
69+
result[i] = "O"
70+
word_list[word_list.index(l)] = " "
7071

7172
return "".join(result)
7273

@@ -210,6 +211,14 @@ def test_check_guess_3(self, mock_input):
210211
"The result of the function check_guess is not correct. The function should return '_X__O' for a guess of 'carat' and the word 'taboo'.",
211212
)
212213

214+
result = user.check_guess("raver", "heres")
215+
expected_out = "O__X_"
216+
self.assertEqual(
217+
expected_out,
218+
result,
219+
"The result of the function check_guess is not correct. The function should return 'O__X_' for a guess of 'raver' and the word 'heres'.",
220+
)
221+
213222
@mock.patch("builtins.input", create=True)
214223
def test_check_guess_random_word(self, mock_input):
215224
mock_input.side_effect = ["world"] * 30

exercises/final_exam/assignment/reference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def check_guess(guess, word):
2424
# check for chars are wrong position
2525
for i, l in enumerate(guess):
2626
if l in word_list:
27-
result[i] = "O"
28-
word_list[word_list.index(l)] = " "
27+
if result[i] != "X":
28+
result[i] = "O"
29+
word_list[word_list.index(l)] = " "
2930

3031
return "".join(result)
3132

0 commit comments

Comments
 (0)