I’m using some old C# code (specifically this Fortune’s Voronoi graph algorithm) in a Unity3D project and I wanted to update it to use proper generics, refactor and generally clean things up.
Ideally, I’d do this without breaking anything; the code works and its implementation of the algorithm is sound. Unit tests would obviously help me refactor this without screwing it up.
Unfortunately I really don’t understand the math or the algorithm, and the code is dense and comment-free.
How can I write unit tests for code like this?
Unit testing is all about input and output of methods.
So you could just single out methods, execute them with several sets of parameters, and store the result.
Then in your Unit Tests, you execute the same methods, with the same sets of parameters, and you know what to expect as output. If the output changes, you broke something.