3 ms·
You can only be sure if you verified every year and didn't miss a typo. Having a test that straightforwardly checks every year individually would be more useful
by skybrian 2y ago
You can only be sure if you verified every year and didn't miss a typo. Having a test that straightforwardly checks every year individually would be more useful, since then you know if you changed anything, and can double-check just the changes.
Although, I suppose it doesn't matter all that much which is which, as long as they're not both written the same way.
- lanstin 2y agoUnless there's something about leap years that you don't understand and miss in both tests and implementation. Not an impossible situation.
- throwway120385 2y agoHow 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.