fix(curriculum): add test for falsy value in lab travel weather planner (#65986)

This commit is contained in:
Aditya Singh
2026-02-23 22:15:54 +05:30
committed by GitHub
parent cb87d5d552
commit 09979d9ada
@@ -146,6 +146,65 @@ You should use the `print()` function to display the result.
({ test: () => runPython(`assert _Node(_code).block_has_call("print")`) })
```
When `distance_mi` is a falsy value, the program should print `False`.
```js
({ test: () => runPython(`
import ast, io, contextlib
VARIABLES = {
"distance_mi",
"is_raining",
"has_bike",
"has_car",
"has_ride_share_app"
}
def run_case(env, expected):
tree = ast.parse(_code)
tree.body = [
node for node in tree.body
if not (
isinstance(node, ast.Assign)
and isinstance(node.targets[0], ast.Name)
and node.targets[0].id in VARIABLES
)
]
clean_code = compile(tree, "<ast>", "exec")
buffer = io.StringIO()
with contextlib.redirect_stdout(buffer):
exec(clean_code, env)
assert buffer.getvalue().strip() == expected
run_case(
{
"distance_mi": 0,
"is_raining": False,
"has_bike": True,
"has_car": True,
"has_ride_share_app": True
},
"False"
)
run_case(
{
"distance_mi": 0.0,
"is_raining": False,
"has_bike": True,
"has_car": True,
"has_ride_share_app": True
},
"False"
)
`) })
```
When the distance is `1` mile or less and it is not raining, the program should print `True`.
```js