file to be tested: '''
def main():
use_input = input("Greeting: ").strip()
x = value(use_input.lower())
print(f"${x}")
def value(greeting):
# if greeting starts with hello , $0
if greeting[0:5] == "hello":
return 0
# if greeting starts with h , $20
elif greeting[0] == "h":
return 20
# else, $100
else:
return 100
if __name__ == "__main__":
main()
''' file which is doing the testing: '''
from bank import value
def test_greeting_charge():
assert value("hello") == 0
assert value("hi") == 20
assert value(" ") == 100
assert value("test") == 100
assert value("hi where is 100th st?") == 20
assert value("oloo") == 100
try:
assert value("Hi") == 20
except AssertionError:
print("Hi is capitalized so assertionerror")
if __name__ == "__main__":
main()
''' cs50s check output (4th condition is the concern):
:) test_bank.py exist
:) correct bank.py passes all test_bank checks
:) test_bank catches bank.py with incorrect values
:( test_bank catches bank.py without case-insensitivity
expected exit code 1, not 0
:) test_bank catches bank.py not allowing for entire phrase
I really dont understand what I need to do to fix my code, pytest is working fine but the actual check for the problem fails the fourth condition
file to be tested: '''
def main():
use_input = input("Greeting: ").strip()
x = value(use_input.lower())
print(f"${x}")
def value(greeting):
# if greeting starts with hello , $0
if greeting[0:5] == "hello":
return 0
# if greeting starts with h , $20
elif greeting[0] == "h":
return 20
# else, $100
else:
return 100
if __name__ == "__main__":
main()
''' file which is doing the testing: '''
from bank import value
def test_greeting_charge():
assert value("hello") == 0
assert value("hi") == 20
assert value(" ") == 100
assert value("test") == 100
assert value("hi where is 100th st?") == 20
assert value("oloo") == 100
try:
assert value("Hi") == 20
except AssertionError:
print("Hi is capitalized so assertionerror")
if __name__ == "__main__":
main()
''' cs50s check output (4th condition is the concern):
:) test_bank.py exist
:) correct bank.py passes all test_bank checks
:) test_bank catches bank.py with incorrect values
:( test_bank catches bank.py without case-insensitivity
expected exit code 1, not 0
:) test_bank catches bank.py not allowing for entire phrase
I really dont understand what I need to do to fix my code, pytest is working fine but the actual check for the problem fails the fourth condition
Share Improve this question asked Mar 28 at 0:40 Cyrus ValiCyrus Vali 372 bronze badges 2 |1 Answer
Reset to default 0BTW the code I got working (special thx to @jasonharper):
from bank import value
def test_greeting_charge():
assert value("hello") == 0
assert value("hi") == 20
assert value(" ") == 100
assert value("test") == 100
assert value("hi where is 100th st?") == 20
assert value("oloo") == 100
assert value("Hi") == 20
if __name__ == "__main__":
main()
value("Hi")
test can never actually generate an error; it might (or might not) print a message, but execution continues in any case. I'm not sure why you wrote that test differently than the rest - just test that the expression has the proper value (which appears to be 100). – jasonharper Commented Mar 28 at 0:52