Skip to main content
Module 5 · Pathfinding Around Obstacles

Lesson 5-6 · Testing and Swapping — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. Why are the five property checks stronger than comparing with one expected path?

    1. A.They check that a path is valid, and they accept every correct answer instead of just one✓
    2. B.They run faster
    3. C.They do not need to know the destination
    4. D.They are not stronger — an exact match is always better

    An exact match passes only the path you wrote down, even if your expectation was wrong. The properties check validity directly, and any shortest path passes.

  2. A planner returns [(0,1), (0,3)] for (0,0) to (0,3). Which property fails, and what does the FAIL line say?

    1. A.Property 3: "step (0, 3) is not next to (0, 1)"✓
    2. B.Property 1: the first step is not next to the start
    3. C.Property 2: the last step is not the destination
    4. D.Nothing fails — it reaches the destination

    (0,1) and (0,3) are two apart. The first step is fine, the last step is the destination, but the middle is a gap — and the step count (2 instead of 3) fails too.

  3. Inside run_path_test, what does `path = planner(start, destination)` do when the harness was called with run_all_tests("BFS", compute_bfs_path)?

    1. A.Calls compute_bfs_path(start, destination) — whichever planner was handed in✓
    2. B.Calls every planner in the file
    3. C.Looks up a planner named "BFS"
    4. D.Causes an error, because planner is a parameter

    planner is a parameter holding a function. Calling it calls the function that was passed in. Hand it compute_manhattan_path instead and the same line tests Manhattan.

  4. With planner objects, why does the harness keep its own record of what it blocked instead of reading planner.blocked?

    1. A.The harness is not supposed to know what is inside a planner — and Manhattan has no blocked list at all✓
    2. B.Objects cannot have lists
    3. C.planner.blocked is always empty
    4. D.It does read planner.blocked — the text is wrong

    The whole point of the swap is that the harness only uses the three shared methods. Reaching inside one planner would tie the harness to that planner.