-cov LOC is inadequate for 1 liner branching; need a metric based on branching
Timothee Cour
thelastmammoth at gmail.com
Sun Feb 11 23:01:02 UTC 2018
> -cov coverage percentage is the line coverage, not the sequence point coverage [...]
> makes it fuzzy in proportion to how many lines contain multiple sequence points
Based on your comment I'm pretty sure you're still not getting my
point, so apologies if I was unclear and let me try to explain better:
it's not about `line coverage` vs `sequence point coverage`, as that
difference is not very large (indeed, just 'fuzzy').
It's about `line coverage` vs `branch coverage` (see exact definition
in linked article), that difference is very large in practice.
here's my example, but more concretely explained:
```
void main(int a){
if(a>0){
statement1(); // line 3
statement2(); // line 4
...
statement100(); // line 102
} else{
statement101(); // line 104
}
}
unittest{ fun(1); }
```
* line coverage is around 99%.
* sequence point coverage is also 99% (and would be close to that if
some lines had multiple statements)
* branch coverage is 50%.
This is not an artificial example, this is the common case.
What's more, code instrumentation to enable branch coverage is not
more complex to implement compared to line coverage (I would even
venture it's less complex and less costly).
On Sun, Feb 11, 2018 at 2:32 PM, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 2/11/2018 1:55 PM, Timothee Cour wrote:
>>
>> I think you're missing my main point: it's explained here
>>
>> https://www.ncover.com/support/docs/extras/code-coverage/understanding-branch-coverage
>> but the gist is that line based coverage is over-counting:
>> ```
>> if(A)
>> // 100 lines of code
>> else
>> // 1 line of code
>> ```
>> gives a line coverage of ~ 99% vs a branch coverage of ~50%
>> (assuming `else` branch never covered in unittests)
>>
>> What matters as far as bugs are concerned is that 50% of cases are
>> covered. Increasing the size of the `if(A)` branch increases line
>> coverage (which is irrelevant) but not branch coverage.
>
>
> I understand that point. The -cov coverage percentage is the line coverage,
> not the sequence point coverage. (Hence it will never be greater than 100%,
> and it will never underestimate the coverage. It would be more accurately
> termed an "upper bound" on the coverage.)
>
> And yes, that makes it fuzzy in proportion to how many lines contain
> multiple sequence points. Eliminating that fuzziness does require a vast
> increase in the complexity of the -cov implementation.
More information about the Digitalmars-d
mailing list