4 ms·
How do you ensure that you don't put a typo in the unit test?
by throwway120385 2y ago
How do you ensure that you don't put a typo in the unit test?
- skybrian 2y agoHopefully, it wouldn't match the algorithm. It's implementing it two different ways and comparing the results. It's not a guarantee, since you could have implemented the wrong spec, but there's only so much you can do with internal consistency checks. But it would be better to compare to a known good function. It might be easier to add a dependency to do that in a test than in production code.
- lmm 2y agoIf you used the list of years in the test and the mathematical expression in the impl (or vice versa), then you know you didn't make the same mistake in both.