Code

The harness and the verdict

Three files, as in lesson 7: the harness, the test, and two lines of main.go.

dcbench.go adds two commands. algo dc runs all four algorithms on the same order and prints the numbers; algo stable is the eight-row demonstration you will see in the next step.

As in lesson 7, every measurement checks the result firstisSortedByTitle. The speed of an incorrect sort means nothing.

dcsort_test.go — the verdict. Two of its tests are unusual:

TestQuickSortIsNotStable asserts a defect. It is the same shape as lesson 7's selection-sort test: if your quicksort ever comes out stable, the test will say so — and then it is worth checking what that cost.

TestNaivePivotIsQuadraticOnSortedInput asserts a worst case. Not "slow", but exactly n(n−1)/2. That line exists so the failure stays written down instead of being quietly fixed and forgotten.