Tests. After my chat with @AdminDev and @anotherriddle I started to think about tests. Designing tests does not come naturally to me, but thankfully the blocks of code I need to test are still reasonably small.
Testing remains an alien concept to me because in my day job (I am an EE, sorta) most of the code I write integrates with some piece of hardware. Mocking Databases is easy compared to mocking a camera on the end of a USB pipe.
But mercifully this project doesn’t have any IO (yet, I dread having to test the result of the images) so I started by writing a test for the hit detection I built yesterday. Its a simple test that hard codes an object and compares it to a hard coded incident ray.
The test immediately highlighted a bug - in the random number generator*, so time to write more tests… and fix the bug. The bug was an overflow, intended, but Rust will panic if an integer overflows, so we need to tell rust we are OK with the values wrapping around using the
After this I wrote 6 more tests for the Sampler.
*HQZ uses its own random number generation to create a sequence of numbers that change slowly.