简体   繁体   English

承保范围如何计算其百分比?

[英]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..? 我从运行覆盖率中得到了这个结果,我无法终生弄清楚如何计算覆盖率。

在此处输入图片说明

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: 更新:以下是pfind.py的详细信息: 在此处输入图片说明

coverage is counting each branch as two possible instructions and giving them the same weight as non-branching instructions. coverage将每个分支视为两个可能的指令,并赋予它们与非分支指令相同的权重。 Using this formula: 使用此公式:

(运行+部分)/(语句+分支)

Looking at results.py from the code, the coverage percentage is calculated in pc_covered , with the data obtained from ratio_covered function: 从代码中查看results.py ,覆盖率百分比是在pc_covered计算的,数据是从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 accounted twice, once as a statement and once as a branch. 如您所见,如果启用了分支覆盖,则每个分支将被会计两次,一次作为语句,一次作为分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM