Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue283 fix #290

Open
wants to merge 1 commit into
base: 2022/python
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions coke/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import check50
from re import escape

# adds case insensitivity
case_insensitive_prefix = "(?i)"

@check50.check()
def exists():
Expand All @@ -13,52 +15,52 @@ def test_25():
"""coke accepts 25 cents"""
input = "25"
output = "Amount Due: 25\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(output, regex=True).kill()
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).kill()


@check50.check(exists)
def test_10():
"""coke accepts 10 cents"""
input = "10"
output = "Amount Due: 40\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(output, regex=True).kill()
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).kill()


@check50.check(exists)
def test_1():
"""coke accepts 5 cents"""
input = "5"
output = "Amount Due: 45\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(output, regex=True).kill()
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).kill()


@check50.check(exists)
def test_invalid():
"""coke rejects invalid amount of cents"""
input = "30"
output = "Amount Due: 50\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(output, regex=True).kill()
check50.run("python3 coke.py").stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).kill()


@check50.check(exists)
def test_multiple():
"""coke accepts continued input"""
input = "10"
output = "Amount Due: 30\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdin(input, prompt=True).stdout(output, regex=True).kill()
check50.run("python3 coke.py").stdin(input, prompt=True).stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).kill()


@check50.check(exists)
def test_terminate():
"""coke terminates at 50 cents"""
input = "10"
output = "Change Owed: 0\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdin(input, prompt=True).stdin(input, prompt=True).stdin(input, prompt=True).stdin(input, prompt=True).stdout(output, regex=True).exit()
check50.run("python3 coke.py").stdin(input, prompt=True).stdin(input, prompt=True).stdin(input, prompt=True).stdin(input, prompt=True).stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).exit()


@check50.check(exists)
def test_change():
"""coke provides correct change"""
input = "25"
output = "Change Owed: 10\n"
check50.run("python3 coke.py").stdin(input, prompt=True).stdin("10", prompt=True).stdin(input, prompt=True).stdout(output, regex=True).exit()
check50.run("python3 coke.py").stdin(input, prompt=True).stdin("10", prompt=True).stdin(input, prompt=True).stdout(case_insensitive_prefix + output, output, regex=True).exit()