How does coverage calculate its interest?

I have this result from the launch of coverage, and I can’t understand for life how the coverage percentages are calculated.?

enter image description here

In this example, he explains branch coverage, but says nothing about percent coverage for the example.

update:. The following is information about pfind.py: enter image description here

+5
source share
1 answer

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

(run + partial) / (statements + branches)

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

 @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 counted twice, once as an operator and once as a branch.

+5
source

Source: https://habr.com/ru/post/1237811/


All Articles