Class: SixthSense::Analyzers::AdequacyCoverage
- Inherits:
-
SixthSense::Analyzer
- Object
- SixthSense::Analyzer
- SixthSense::Analyzers::AdequacyCoverage
- Defined in:
- lib/sixth_sense/analyzers/adequacy_coverage.rb
Instance Method Summary collapse
-
#analyze(test_file, context) ⇒ Object
Paper basis: Zhu/Hall/May 1997 (doi:10.1145/267580.267590) surveys coverage adequacy criteria; branch coverage is preferred when present.
Methods inherited from SixthSense::Analyzer
analyzer_id, axis, inherited, level, reference, references
Instance Method Details
#analyze(test_file, context) ⇒ Object
Paper basis: Zhu/Hall/May 1997 (doi:10.1145/267580.267590) surveys coverage adequacy criteria; branch coverage is preferred when present.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sixth_sense/analyzers/adequacy_coverage.rb', line 25 def analyze(test_file, context) coverage = context.coverage_map_for(test_file) return unmeasured(confidence: :low) unless coverage branch_ratio = coverage.branch_coverage_ratio line_ratio = coverage.line_coverage_ratio ratio = branch_ratio || line_ratio return unmeasured(confidence: :low) unless ratio score = (score_ratio(ratio, context) * 100.0).round(2) confidence = branch_ratio ? :medium : :low findings = [] if ratio < 0.8 findings << finding( rule_id: "low_coverage", severity: :warning, location: test_file.test_cases.first&.location, message: "Coverage ratio is #{(ratio * 100).round(1)}%.", suggestion: "Add tests for unexecuted branches before relying on adequacy scores." ) end result(score: score, findings: findings, confidence: confidence) end |