Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does coverage calculate its percentages?

I have this result from running coverage, and I can't for the life of me figure out how the coverage percentages are calculated..?

enter image description here

In this example it explains branch coverage, but doesn't say anything about coverage percentages for the example.

update: here are the details for pfind.py: enter image description here

like image 948
thebjorn Avatar asked Dec 10 '15 00:12

thebjorn


1 Answers

coverage is counting each branch as two possible instructions and giving them the same weight as non-branching instructions. Using this formula:

(run+partial)/(statements+branches)

Looking at results.py from the code, the coverage percentage is calculated in pc_covered, with the data obtained from ratio_covered function:

@property
def ratio_covered(self):
    """Return a numerator and denominator for the coverage ratio."""
    numerator = self.n_executed + self.n_executed_branches
    denominator = self.n_statements + self.n_branches
    return numerator, denominator

As you can see, if branch coverage is enabled each branch will be accounted twice, once as a statement and once as a branch.

like image 151
memoselyk Avatar answered Oct 12 '22 23:10

memoselyk