-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy path__init__.py
58 lines (42 loc) · 1.24 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
import check50
import check50.c
import re
@check50.check()
def exists():
"""hello.c exists"""
check50.exists("hello.c")
@check50.check(exists)
def compiles():
"""hello.c compiles"""
check50.c.compile("hello.c", lcs50=True)
@check50.check(compiles)
def mario():
"""responds to name Mario"""
check_name("Mario")
@check50.check(compiles)
def peach():
"""responds to name Peach"""
check_name("Peach")
@check50.check(compiles)
def bowser():
"""responds to name Bowser"""
check_name("Bowser")
def check_name(name):
# Define expected, actual outputs
expected = f"hello, {name}\n"
actual = check50.run("./hello").stdin(name).stdout()
# Check output
if not re.match(regex(name), actual):
try:
last_character = actual[-1]
except IndexError:
raise check50.Mismatch(expected=expected, actual=actual)
if last_character != "\n":
raise check50.Mismatch(
expected=expected,
actual=actual,
help=r"Forgot to print a newline at the end of your output?",
)
raise check50.Mismatch(expected=expected, actual=actual)
def regex(string):
return f"^[Hh]ello, {re.escape(string)}\n$"