diff --git a/checks/recursion/recursion8.py b/checks/recursion/recursion8.py index 1664069..9d27c52 100644 --- a/checks/recursion/recursion8.py +++ b/checks/recursion/recursion8.py @@ -3,13 +3,13 @@ two_level = {"value": 1, "children": [{"value": 2, "children": []}, {"value": 3, "children": []}]} deep = {"value": 1, "children": [{"value": 2, "children": [{"value": 3, "children": []}]}]} -assert tree_depth(single) == 1 -assert tree_depth(two_level) == 2 -assert tree_depth(deep) == 3 +assert tree_depth(single) == 1, f"tree_depth(single) should be 1, got {tree_depth(single)}" +assert tree_depth(two_level) == 2, f"tree_depth(two_level) should be 2, got {tree_depth(two_level)}" +assert tree_depth(deep) == 3, f"tree_depth(deep) should be 3, got {tree_depth(deep)}" -assert tree_search(leaf, 7) is True -assert tree_search(leaf, 99) is False -assert tree_search(two_level, 3) is True -assert tree_search(deep, 3) is True -assert tree_search(deep, 99) is False +assert tree_search(leaf, 7) is True, f"tree_search(leaf, 7) should be True, got {tree_search(leaf, 7)}" +assert tree_search(leaf, 99) is False, f"tree_search(leaf, 99) should be False, got {tree_search(leaf, 99)}" +assert tree_search(two_level, 3) is True, f"tree_search(two_level, 3) should be True, got {tree_search(two_level, 3)}" +assert tree_search(deep, 3) is True, f"tree_search(deep, 3) should be True, got {tree_search(deep, 3)}" +assert tree_search(deep, 99) is False, f"tree_search(deep, 99) should be False, got {tree_search(deep, 99)}" print("recursion8 ✓") diff --git a/tests/test_recursion8_assertions.py b/tests/test_recursion8_assertions.py new file mode 100644 index 0000000..86e3860 --- /dev/null +++ b/tests/test_recursion8_assertions.py @@ -0,0 +1,24 @@ +import ast +import pathlib + + +CHECK_PATH = pathlib.Path(__file__).resolve().parents[1] / "checks" / "recursion" / "recursion8.py" + + +def _assertion_messages(): + tree = ast.parse(CHECK_PATH.read_text()) + messages = [] + for node in ast.walk(tree): + if isinstance(node, ast.Assert): + messages.append(node.msg) + return messages + + +def test_recursion8_assertions_have_actionable_messages(): + messages = _assertion_messages() + assert messages, "recursion8.py should contain assertions" + for msg in messages: + assert msg is not None, "every assertion in recursion8.py must include a message" + assert isinstance(msg, ast.JoinedStr), ( + "assertion messages should be f-strings describing expected vs actual values" + )