bc1d56d1a4
P0.6: gcov infrastructure P1: extract_structure output expansion (11 new feature fields) P2: Confusion group rule engine (8 pairs + contradiction + backtrack) P3: 4-factor confidence calculation + quality gate update P4: 33+2 COBOL program type test samples (22 files, 7 categories) P5: parametrized/ test data generation engine P6: japanese_data.py lookup tables P7-10: Type-specific test suites (~159 parametrized tests) P11: Full classification pipeline (classify_program) + orchestrator integration P12: Documentation (module-interfaces, test-plan v3.0, coverage-matrix) Architecture decisions: - classification_pipeline/ merged to hina/pipeline/ - parametrized/ as independent module - japanese_data.py as root-level file - hina/__all__ only exports classify_program() Co-Authored-By: Claude <noreply@anthropic.com>
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""覆盖率比较 — 静态覆盖率 vs 动态覆盖率差异分析。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def compare_coverage(
|
|
program_name: str,
|
|
static: dict[str, Any],
|
|
dynamic: dict[str, Any],
|
|
) -> dict[str, Any]:
|
|
"""比较静态覆盖率和动态覆盖率之间的差异。
|
|
|
|
静态覆盖率: 基于源码结构分析的理论覆盖范围。
|
|
动态覆盖率: 基于 gcov 实际执行数据的覆盖范围。
|
|
|
|
Args:
|
|
program_name: 程序名称
|
|
static: 静态覆盖率数据
|
|
{"branch_rate": float, "paragraph_rate": float,
|
|
"total_branches": int, "covered_branches": int, ...}
|
|
dynamic: 动态覆盖率数据
|
|
{"gcov_cov": float, "covered_branches": int,
|
|
"total_branches": int, "misleading_branches": list, ...}
|
|
|
|
Returns:
|
|
dict: {
|
|
"program": str, # 程序名称
|
|
"static": {"branch_rate": float, "paragraph_rate": float},
|
|
"dynamic": {"gcov_cov": float},
|
|
"gap": float, # static - dynamic 的差异
|
|
"misleading_branches": list, # 可能导致误导的分支列表
|
|
}
|
|
"""
|
|
static_branch_rate = static.get("branch_rate", 0.0)
|
|
static_para_rate = static.get("paragraph_rate", 0.0)
|
|
dynamic_cov = dynamic.get("gcov_cov", 0.0)
|
|
|
|
# 静态综合覆盖率
|
|
static_combined = static_branch_rate * 0.5 + static_para_rate * 0.5
|
|
|
|
# 差距: 静态覆盖率 - 动态覆盖率
|
|
gap = round(static_combined - dynamic_cov, 4)
|
|
|
|
# 误导性分支: 静态认为已覆盖但动态未覆盖的分支
|
|
misleading_branches = dynamic.get("misleading_branches", [])
|
|
|
|
return {
|
|
"program": program_name,
|
|
"static": {
|
|
"branch_rate": static_branch_rate,
|
|
"paragraph_rate": static_para_rate,
|
|
},
|
|
"dynamic": {
|
|
"gcov_cov": dynamic_cov,
|
|
},
|
|
"gap": gap,
|
|
"misleading_branches": misleading_branches,
|
|
}
|