Open
Description
Preconditions
- Have a
test_fuel.py
, which passes the check50 validation:import pytest from fuel import convert, gauge @pytest.mark.parametrize( "input, expected", [ ("3/4", 75), ], ) def test_convert(input, expected): assert convert(input) == expected @pytest.mark.parametrize( "input", [ "10/3", ], ) def test_convert_value_error(input): with pytest.raises(ValueError): assert convert(input) @pytest.mark.parametrize( "input", [ "0/0" ], ) def test_convert_zero_division(input): with pytest.raises(ZeroDivisionError): convert(input) @pytest.mark.parametrize( "input,expected", [ (75, "75%"), (33, "33%"), (67, "67%"), (0, "E"), (1, "E"), (100, "F"), (99, "F"), (101, "F"), (-1, "E"), ], ) def test_gauge(input, expected): assert gauge(input) == expected
Steps to reproduce:
- Add following test to your
test_fuel.py
:@pytest.mark.parametrize( "input", [ "10/3", "-1/100" ], ) def test_convert_value_error(input): with pytest.raises(ValueError): assert convert(input)
- Run
check50 cs50/problems/2022/python/tests/fuel
Expected result
- The check50 validation should pass
Actual result
-
The problem description for PSET 5 Refueling has the following description:
-
The check50 validation fails at step 2
:( correct fuel.py passes all test_fuel checks
If user attempts to add a test for the requirementthe nearest int between 0 and 100, inclusive.
:def convert(input: str) -> int: # Will raise ValueError if int() conversion fails # Will raise ValueError if too many values to unpack dividend, divisor = (int(value) for value in input.split("/")) if dividend > divisor: raise ValueError("Dividend can not be larger than divisor.") result = round((dividend / divisor) * 100) if result not in range(0, 101): raise ValueError("Result must be an int between 0 and 100, inclusive.") return result
Metadata
Metadata
Assignees
Labels
No labels