-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pyrdle.py
147 lines (118 loc) · 4.47 KB
/
test_pyrdle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# test_pyrdle 2024-01-21 8:32 p.m.
# Tom Legrady - [email protected]
# (c) 2024 Tom Legrady - All Rights Reserved
#
#
import pyrdle
from icecream import ic
ic.configureOutput(includeContext=True)
def main():
test_fetch_word()
test_validate_user_keypress()
test_process_guess()
test_eval_letters()
test_handle_game_over()
test_won_or_lost()
test_out_of_guesses()
test_game_solved()
def test_fetch_word():
gfw = pyrdle.Game()
gfw.fetch_word()
word = gfw.secret_word
assert len(word) == 6
assert word.isalpha()
assert word.isupper()
def test_validate_user_keypress():
gvuk = pyrdle.Game()
assert gvuk.user_input_text.get() == ""
gvuk.user_input_text.set("1")
gvuk.validate_user_keypress()
assert gvuk.user_input_text.get() == ""
gvuk.user_input_text.set("^")
gvuk.validate_user_keypress()
assert gvuk.user_input_text.get() == ""
gvuk.user_input_text.set("A")
gvuk.validate_user_keypress()
assert gvuk.user_input_text.get() == "A"
gvuk.user_input_text.set("Ab")
gvuk.validate_user_keypress()
assert gvuk.user_input_text.get() == "AB"
def test_process_guess():
gpg = pyrdle.Game()
gpg.secret_word = "SECRET"
gpg.eval_letters("CHERRY")
gpg.eval_letters("VICTOR")
gpg.current_guess = 1
assert gpg.alphabet.get() == "AB D FG JKLMN PQ S U WX Z"
gpg.user_input_text.set("NEWEST")
gpg.process_guess()
assert gpg.alphabet.get() == "AB D FG JKLM PQ U X Z"
assert gpg.current_guess == 2
assert gpg.evalbox[1].get() == "NEWEST"
assert gpg.evalbox[1].tag_names(1.0) == ("centered", "lightgrey")
assert gpg.evalbox[1].tag_names(1.1) == ("centered", "green")
assert gpg.evalbox[1].tag_names(1.2) == ("centered", "lightgrey")
assert gpg.evalbox[1].tag_names(1.3) == ("centered", "yellow")
assert gpg.evalbox[1].tag_names(1.4) == ("centered", "yellow")
assert gpg.evalbox[1].tag_names(1.5) == ("centered", "green")
def test_eval_letters():
gel = pyrdle.Game()
gel.secret_word = "SECRET"
gel.eval_letters("CHERRY")
assert gel.alphabet.get() == "AB D FG IJKLMNOPQ STUVWX Z"
assert gel.evalbox[gel.current_guess].get() == "CHERRY"
assert gel.evalbox[gel.current_guess].tag_names() == (
"sel",
"centered",
"lightgrey",
"yellow",
"green",
)
assert gel.evalbox[gel.current_guess].tag_names(1.0) == ("centered", "yellow")
assert gel.evalbox[gel.current_guess].tag_names(1.1) == ("centered", "lightgrey")
assert gel.evalbox[gel.current_guess].tag_names(1.2) == ("centered", "yellow")
assert gel.evalbox[gel.current_guess].tag_names(1.3) == ("centered", "green")
assert gel.evalbox[gel.current_guess].tag_names(1.4) == ("centered", "yellow")
assert gel.evalbox[gel.current_guess].tag_names(1.5) == ("centered", "lightgrey")
assert gel.evalbox[gel.current_guess].tag_names(1.6) == ("centered",)
def test_game_solved():
ggs = pyrdle.Game()
ggs.secret_word = "SECRET"
assert not ggs.game_solved("CHERRY")
assert ggs.game_solved("SECRET")
def test_won_or_lost():
gwol = pyrdle.Game()
gwol.secret_word = "SECRET"
assert gwol.score == {"losses": 0, "wins": 0}
assert gwol.score_display.cget("text") == "Won: 0 Lost: 0"
assert gwol.window["background"] == "#9abdf5"
gwol.gui_update_win_loss("CHERRY")
assert gwol.score == {"losses": 1, "wins": 0}
assert gwol.score_display.cget("text") == "Won: 0 Lost: 1"
assert gwol.window["background"] == "red"
gwol.gui_update_win_loss("SECRET")
assert gwol.score == {"losses": 1, "wins": 1}
assert gwol.score_display.cget("text") == "Won: 1 Lost: 1"
assert gwol.window["background"] == "green"
def test_handle_game_over():
ghgo = pyrdle.Game()
ghgo.secret_word = "VICTOR"
ghgo.handle_game_over("VICTOR", testing=True)
assert ghgo.window["background"] == "#9abdf5"
assert ghgo.alphabet.get() == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
assert ghgo.user_input_text.get().strip() == ""
assert ghgo.evalbox[0].get() == ""
assert ghgo.evalbox[1].get() == ""
assert ghgo.evalbox[2].get() == ""
assert ghgo.evalbox[3].get() == ""
assert ghgo.evalbox[4].get() == ""
assert ghgo.evalbox[5].get() == ""
assert ghgo.secret_word != "VICTOR"
assert ghgo.current_guess == 0
def test_out_of_guesses():
goog = pyrdle.Game()
assert not goog.out_of_guesses()
goog.current_guess = 5
assert goog.out_of_guesses()
if __name__ == "__main__":
main()