Catching tons of bugs with unit tests

Captain's Log: Stardate 77633.7

Over the last few days I've been adding tons of unit tests, which in turn have found tons of bugs, which I've been fixing. It really is still amazing to me how much unit tests can help simply by forcing you to think through all the edge cases with a higher level of precision. But also of course they can just catch things that you never even thought about. I've found bugs via a combination of both of these things.

One bug I was really pleased to catch had to do with the geometric logic for intersecting various primitives, in this case intersecting a plane and a sphere. This is used when checking whether a sphere is inside a frustum, which is needed to determine which objects are inside the selection when the user drags a box. These kinds of bugs are a huge pain to track down without tests, because they tend to only happen in weird edge cases, and then they're difficult to reproduce.

Unit tests also caught a bug where I was testing for "is this float infinity" incorrectly. This is actually pretty important, because some GUI elements have infinity as an acceptable value, for example a compressor's ratio is allowed to be negative infinity. My buggy test said that NaN was infinity, which means that NaNs could have crept in, which is one of my worst nightmares.

But the real value of the tests is not just catching bugs, but is in speeding up future work. I'm super excited to know that I can modify all this code with MUCH more confidence that I didn't break anything. A really good read on this topic is https://www.antithesis.com/blog/is_something_bugging_you/. I have an idea for how to accomplish something similar for Anukari... we'll see. 😄


© 2024 Anukari LLC, All Rights Reserved
Contact Us|Legal