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

issue189 fix #62

Open
wants to merge 1 commit into
base: 2024/x
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
14 changes: 8 additions & 6 deletions half/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,34 @@ def compiles():
@check50.check(compiles)
def simple():
"""Bill of $50, with 10% tax and 20% tip, creates output of $33.00"""
check_half(bill="50", tax="10", tip="20", expected="33.00")
check_half(bill="50", tax="10", tip="20", expected="$33.00")


@check50.check(compiles)
def decimal_tax():
"""Bill of $50, with 12.5% tax and 20% tip, creates output of $33.75"""
check_half(bill="50", tax="12.5", tip="20", expected="33.75")
check_half(bill="50", tax="12.5", tip="20", expected="$33.75")


@check50.check(compiles)
def rounding_up():
"""Bill of $100, with 12.5% tax and 15% tip, creates output of $64.69"""
check_half(bill="100", tax="12.5", tip="15", expected="64.69")
check_half(bill="100", tax="12.5", tip="15", expected="$64.69")


@check50.check(compiles)
def rounding_down():
"""Bill of $96.40, with 13% tax and 14% tip, creates output of $62.09"""
check_half(bill="96.40", tax="13", tip="14", expected="62.09")
check_half(bill="96.40", tax="13", tip="14", expected="$62.09")


# Helpers
def regex(input):
"""Match with any non-numeric characters on either end of input"""
return rf'^\D*\${re.escape(input)}\D*$'
return rf"^\D*{re.escape(input)}\D*$"


def check_half(bill: str, tax: str, tip: str, expected: str):
check50.run("./half").stdin(bill).stdin(tax).stdin(tip).stdout(regex(expected), expected, regex=True)
check50.run("./half").stdin(bill).stdin(tax).stdin(tip).stdout(
regex(expected), expected, regex=True
)