Code

The harness and the one hard limit

Three files: the harness, the tests, and two new commands.

command what it does
algo route one route: BFS against Dijkstra, and the two frontiers
algo frontier the same over every destination — so the ratio is a claim, not an anecdote

The tests

test what it requires
TestBothFrontiersReturnTheSameCost both frontiers return an identical cost for every destination, and the path adds up to it
TestFewestHopsIsNotCheapest BFS's route is never cheaper and sometimes dearer
TestTheHeapHoldsStaleEntries the heap holds more entries than it settles nodes
TestDijkstraIsWrongOnNegativeWeights with a negative edge the answer is wrong

The first matters most, not for what it checks but for what it licenses. Step 5 compares two frontiers — and the comparison only means anything if they give the same answer. So that is checked first.

The third protects step 2's decision:

629 pushes settled 562 nodes: 67 stale entries skipped (1.12 pushes per node)

1.12 pushes per node. If you ever get exactly 1.00, you have implemented decrease-key — a different structure with a different cost — and the test will say so.

The fourth test — Dijkstra's one hard limit

In step 2 the proof rested on an assumption: no edge is negative. Here is what happens without it.

   0 ──1── 2               the direct route, cost 1
   0 ──2── 1 ──(−5)── 2    the detour, cost 2 + (−5) = −3
Dijkstra answered 1; the true cheapest route costs -3

Node 2 is reached at 1 and settled before node 1 is popped at all — so the cheaper detour is never considered.

There is no error, no loop, no slowdown. Just a wrong answer, delivered with exactly as much confidence as a right one. In lesson 11 the degenerate tree was slow and correct; this is the other way round.

The test requires it to stay that way — so that nobody "fixes" Dijkstra by pretending it handles negative costs. Other algorithms do that (Bellman–Ford), and they cost more.