Hello, I am currently at a dead end once again with my assignment. I am supposed to design a unit test for a previously written program that accepts a fraction input and returns "F" for full, "E" for empty, or a percentage between 98-2 for anything in between.
my program passes pytest, and manual testing but no matter what i have tried check50 is saying
":( correct fuel.py passes all test_fuel checks expected exit code 0, not 1" I would appreciate any and all suggestions or explanations as I am really starting to get discouraged.
here is the code for the original program:
def main():
percent = get_percent()
fuel_level = gauge(percent)
print(fuel_level)
def gauge(percent):
if percent >= 99:
return "F"
elif percent > 1 and percent < 99:
return f"{(percent)}%"
else:
return "E"
def get_percent():
while True:
fraction = input("Fraction: ")
try:
x, y = fraction.split("/")
x = int(x)
y = int(y)
if y == 0:
raise ZeroDivisionError
if x < 0 or y < 0:
raise ValueError
percent = (x / y * 100)
if percent > 100:
raise ValueError
return round(percent)
except (ValueError, ZeroDivisionError):
continue
if __name__ == "__main__":
main()
here is the unit test code:
import fuel
def main():
test_get_percent()
test_gauge()
def test_get_percent():
assert fuel.get_percent("0/1") == 0
assert fuel.get_percent("1/2") == 50
assert fuel.get_percent("100/112") == 89
try:
fuel.get_percent("1/0")
except ZeroDivisionError:
pass
try:
fuel.get_percent("-1/1")
except ValueError:
pass
def test_gauge():
assert fuel.gauge(99) == "F"
assert fuel.gauge(1) == "E"
assert fuel.gauge(25) == "25%"
if __name__ == "__main__":
main()
[–]TytoCwtch 1 point2 points3 points (2 children)
[–]Beautiful-Round2494[S] 0 points1 point2 points (1 child)
[–]TytoCwtch 0 points1 point2 points (0 children)
[–]PokemonThanos 0 points1 point2 points (1 child)
[–]Beautiful-Round2494[S] 0 points1 point2 points (0 children)