Main lesson not learned: instead of testing, prove correctness in high assurance code like this. Rigorously and formally.
Preferably even refine the proof to executable code.
(Yes, it would take somewhere on the order of 10k LOC to prove correctness of this 1k.)