jeudi 13 octobre 2016

Best practice Unit Testing Operators

So i wrote my own struct, basically a insanely huge number with double precision. This struct has implemenations for compare, + - / * >= <= == != explicit casts to int float double and back, unary minus, lerp, the whole shebang.

Now i want to use this in a project and it seems to be running into some logic errors. So my idea was: Unit test ALL the things!

Great, except that unit tests as they are recommended would involve me writing a metric shit ton of tests for the simplest of things.

Example: My struct takes 2 variables, both can be NAN, +Inf, -Inf, 0, -anything, + anything, and then they can be "in precision" for the double part of it. This is something to check if specific numbers (1 really big and 1 really small) can be added up or not due to double precision limits.

I came up with at least 19 different inputs, which can each be combined with each of the other ones to form 19^2 unit test. Roughly 350 combinations (probably less i can safely skip some in some cases) If i really want to cover each and every possibility for input.

And this is for each and every operation i need to write them over and over again.

I can't imagine this is the way to go, right? There has to be something i am either missing, or a practice i am not following.

Does anyone have a suggestion on how to improve these massive amounts of tests?

Aucun commentaire:

Enregistrer un commentaire