Skip to content

Commit

Permalink
Merge pull request cs50#207 from cs50/curiouskiwi-plates
Browse files Browse the repository at this point in the history
Update plates check
  • Loading branch information
CarterZenke authored Nov 27, 2023
2 parents f4b6579 + 8371bdc commit b2bec75
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions plates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def test_cs50():
"""input of CS50 yields output of Valid"""
input = "CS50"
output = "Valid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# Ready Player One
Expand All @@ -22,7 +24,9 @@ def test_ECTO88():
"""input of ECTO88 yields output of Valid"""
input = "ECTO88"
output = "Valid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# Ferris Buehler's Day Off
Expand All @@ -31,7 +35,9 @@ def test_NRVOUS():
"""input of NRVOUS yields output of Valid"""
input = "NRVOUS"
output = "Valid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# Tests for Zero as first number
Expand All @@ -40,16 +46,31 @@ def test_CS05():
"""input of CS05 yields output of Invalid"""
input = "CS05"
output = "Invalid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# First two chars are not letters
@check50.check(exists)
def test_50():
"""input of 50 yields output of Invalid"""
input = "50"
output = "Invalid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()



# Numbers before letters (after the first 2 letters)
@check50.check(exists)
def test_CS50P2():
"""input of CS50P2 yields output of Invalid"""
input = "CS50P2"
output = "Invalid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# Non-alphanumeric characters (after the first 2 letters)
Expand All @@ -58,7 +79,9 @@ def test_PI3_14():
"""input of PI3.14 yields output of Invalid"""
input = "PI3.14"
output = "Invalid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# Length (too short)
Expand All @@ -67,7 +90,9 @@ def test_445108():
"""input of H yields output of Invalid"""
input = "H"
output = "Invalid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


# Length (too long) (Back to the Future)
Expand All @@ -76,9 +101,11 @@ def test_OUTATIME():
"""input of OUTATIME yields output of Invalid"""
input = "OUTATIME"
output = "Invalid"
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(regex(output), output, regex=True).exit()
check50.run("python3 plates.py").stdin(input, prompt=True).stdout(
regex(output), output, regex=True
).exit()


def regex(text):
"""match case-insensitively, allowing for only spaces on either side"""
return fr'(?i)^\s*{escape(text)}\s*$'
return rf"(?i)^\s*{escape(text)}\s*$"

0 comments on commit b2bec75

Please sign in to comment.