4 ms·
Consider a line like: value = 1 / input; You can get "100% coverage" if you test that with `input = 1`, but unless you check with `input = 0` you're missi
by gregmac 8y ago
Consider a line like:
value = 1 / input;
You can get "100% coverage" if you test that with `input = 1`, but unless you check with `input = 0` you're missing a quite important logical check.
- akvadrako 8y agoNot really - internally inputs 0 and 1 use different branches.
- RussianCow 8y agoThat's not a branch; otherwise you would have an infinite (or impossibly large) number of branches for just that one line of code. A branch is when you execute one set of code upon a given condition, and another if that condition is not met.
- qznc 8y agoIt depends on the language. In C it is not a branch because division by zero is undefined and not a path you consider. In Java you can argue that there are two branches. One branch that throws an exception and one that does not.
- zaphar 8y agoNo coverage reporting library will attempt to tell you that kind of coverage. You are essentially in violent agreement with the op but turning it into an argument by using different words for the same concept.
- akvadrako 8y agoI didn't say every number is a different branch. But on many processors, divide by zero triggers an interrupt. That's semantically the same as a branch.
- breckuh 8y agoCan't you just have a NonZeroInt type?
- whyonearth 8y agoOnly if your language supports dependent types.