Lesson 6 · Testing and Swapping — Knowledge ChecksAnswer key
On a clear grid, why check the step count rather than the exact path?
Multiple routes can tie for shortest. What must match is the optimal length; the specific cells may legitimately differ between the two algorithms.
In a for/else loop, when does the else block run?
The else clause of a for loop runs only when the loop completes normally. A break skips it — perfect for 'passed unless we found a problem' checks.
How many lines of the Navigator's own code change to use Dijkstra instead of Manhattan?
The Navigator calls compute_path the same way regardless. Only the two setup lines (import + constructor) change — the whole point of a shared interface.
The swap works because Dijkstra is 'better' than Manhattan. True or false?
Swappability comes from interface compatibility (same method name, params, return type), not from which class is 'better.' A worse class with the same interface would swap just as cleanly.