-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy path__init__.py
75 lines (52 loc) · 2.45 KB
/
__init__.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
import check50
from re import escape
@check50.check()
def exists():
"""game.py exists"""
check50.exists("game.py")
# The hard-coded number 4 is the answer to the game (specified in test.py).
# This is the number that the user is trying to guess.
check50.include("testing.py")
@check50.check(exists)
def test_string_level():
"""game.py rejects non-numeric level"""
check50.run("python3 game.py").stdin("cat", prompt=True).reject()
@check50.check(exists)
def test_integer_level():
"""game.py rejects out-of-range level"""
check50.run("python3 game.py").stdin("0", prompt=True).reject()
@check50.check(exists)
def test_valid_level():
"""game.py accepts valid level"""
check50.run("python3 game.py").stdin("10", prompt=True).stdout(regex("Guess"), "Guess:", regex=True).kill()
@check50.check(test_valid_level)
def test_string_guess():
"""game.py rejects non-numeric guess"""
check50.run("python3 game.py").stdin("4", prompt=True).stdin("cat", prompt=True).reject()
@check50.check(test_valid_level)
def test_zero_guess():
"""game.py rejects non-positive guess"""
check50.run("python3 game.py").stdin("4", prompt=True).stdin("0", prompt=True).reject()
@check50.check(test_valid_level)
def test_out_of_range_large():
"""game.py rejects guess above specified range with \"Too large!\""""
output = "Too large!"
check50.run("python3 testing.py").stdin("4", prompt=True).stdin("8", prompt=True).stdout(regex(output), output, regex=True).reject()
@check50.check(test_valid_level)
def test_too_large():
"""game.py outputs \"Too large!\" when guess is too large"""
output = "Too large!"
check50.run("python3 testing.py").stdin("22", prompt=True).stdin("18", prompt=True).stdout(regex(output), output, regex=True).reject()
@check50.check(test_valid_level)
def test_just_right():
"""game.py outputs \"Just right!\" when guess is correct"""
output = "Just right!"
check50.run("python3 testing.py").stdin("6", prompt=True).stdin("4", prompt=True).stdout(regex(output), output, regex=True).exit()
@check50.check(test_valid_level)
def test_too_small():
"""game.py outputs \"Too small!\" when guess is too small"""
output = "Too small!"
check50.run("python3 testing.py").stdin("5", prompt=True).stdin("2", prompt=True).stdout(regex(output), output, regex=True).reject()
def regex(text):
"""match case-insensitively with any characters on either side"""
return fr'(?i)^.*{escape(text)}.*$'