Class: DecisionAgent::Testing::TestCoverageAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/testing/test_coverage_analyzer.rb

Overview

Analyzes test coverage of rules and conditions

Instance Method Summary collapse

Constructor Details

#initializeTestCoverageAnalyzer

Returns a new instance of TestCoverageAnalyzer.



36
37
38
39
40
41
# File 'lib/decision_agent/testing/test_coverage_analyzer.rb', line 36

def initialize
  @executed_rules = Set.new
  @executed_conditions = Set.new
  @rule_evaluation_count = {}
  @condition_evaluation_count = {}
end

Instance Method Details

#analyze(results, agent = nil) ⇒ CoverageReport

Analyze coverage from test results

Parameters:

  • Test results from batch execution

  • (defaults to: nil)

    The agent used for testing (to get all available rules)

Returns:

  • Coverage report



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/decision_agent/testing/test_coverage_analyzer.rb', line 47

def analyze(results, agent = nil)
  reset

  # Track which rules and conditions were executed
  results.each do |result|
    next unless result.success?

    result.evaluations.each do |evaluation|
      track_evaluation(evaluation)
    end
  end

  # Get all available rules from agent if provided
  all_rules = agent ? extract_rules_from_agent(agent) : []
  all_conditions = agent ? extract_conditions_from_agent(agent) : []

  generate_report(all_rules, all_conditions)
end

#coverage_percentageFloat

Get coverage percentage

Returns:

  • Coverage percentage (0.0 to 1.0)



68
69
70
71
72
73
74
75
# File 'lib/decision_agent/testing/test_coverage_analyzer.rb', line 68

def coverage_percentage
  return 0.0 if @executed_rules.empty?

  total = @rule_evaluation_count.size
  return 0.0 if total.zero?

  @executed_rules.size.to_f / total
end