Code

The harness and the tests

Three files in one step: the harness, the tests, and three new commands in main.go.

command what it does
algo alpha step 1's answer: the walk, Min/Max, a range
algo tree the tree against lesson 10's hash index and lesson 1's linear scan
algo shape the same library, two insertion orders

The tests (bst_test.go) check six things:

test what it requires
TestTreeStoresAndFinds finds everything stored, misses what was not
TestTreeDuplicateKeysReplace an equal key replaces (as in lesson 10)
TestKeysComeBackSorted Keys() IS sorted; Min/Max match the ends
TestRangeReturnsOnlyTheBand a range returns only its band and visits fewer than all nodes
TestShuffledInsertStaysLogarithmic random insertion keeps the depth logarithmic
TestSortedInsertDegeneratesIntoAList sorted insertion gives Height() == n

The third one should look familiar. In lesson 10 the test demanded that Keys() was not sorted, because a hash index cannot promise order. Here it demands that it is. The same test with the sign reversed: two promises, two structures.

The last one is another defect-pinning test, like lesson 7's selection sort, lesson 8's quicksort and lesson 9's unstable pass. It requires sorted insertion to produce a tree of height exactly n.

If it ever starts failing, you have built something other than a plain BST. In lesson 12 you will do precisely that, on purpose; until then it protects step 7's demonstration.