Set your name in
UserPreferences Referenced by ExcusesForNotDoin...
JSPWiki v2.0.36
|
HowDoYouWriteUnitTestsFor a Mandelbrot generator? This one is quite straightforward, once you realise that (what with the ongoing triumph of raster graphics over vector) complicated graphical output is trivial numeric output. Years ago, before XP hit the news, KeithB worked for a guy who demanded thorough automated unit testing of all the code written for him. Test first wasn't on the agenda, but very tight coupling of testing and coding in very short iterations was. We were working on a tool that would generate overlays for maps showing signal strength contours for mobile phone networks. Graphical output, right? Hard to test, right? Wrong. Each pixel in the output raster represents a rectangular area in the terrain, and the colour of the pixels maps onto (it so happend) the calculated signal strength at the north western corner of that area. So testing this code doesn't require eyeballing the map overlay. It involves concocting interesting terrains, calculating the signal strength at interesting pixels, then pulling the corresponding values out of the raster. Very easy, and very effective. And the same can be done with the Mandelbrot generator. I seem to remember that the "default" Mandelbrot algorithm has very different behaviour for starting values of z depending on the value of magnitude(z) <=2, so that's two test cases right there. And so on. HowDoYouWriteUnitTestsFor main methods? Mock the execution environment. If you even need to do that: most main methods are (or should be) nugatory. HowDoYouWriteUnitTestsFor...
|