Class: Minitest::Cc::FileArray

Inherits:
Array
  • Object
show all
Defined in:
lib/minitest/cc/file_array.rb

Overview

model for a file

Instance Method Summary collapse

Instance Method Details

#branches_averageFloat

Calculate the branches average of the self array

Returns:

  • (Float)

    percent of branches executed



22
23
24
25
26
27
28
29
# File 'lib/minitest/cc/file_array.rb', line 22

def branches_average
  branches = reduce(0) { |sum, v| sum + v.branches.to_i }

  return 0.0 if branches.zero?

  branches_executed = reduce(0) { |sum, v| sum + v.branches_executed.to_i }
  branches_executed * 100.0 / branches
end

#lines_averageFloat

Calculate the lines average of the self array

Returns:

  • (Float)

    percent of lines executed



10
11
12
13
14
15
16
17
# File 'lib/minitest/cc/file_array.rb', line 10

def lines_average
  lines = reduce(0) { |sum, v| sum + v.lines.to_i }

  return 0.0 if lines.zero?

  lines_executed = reduce(0) { |sum, v| sum + v.lines_executed.to_i }
  lines_executed * 100.0 / lines
end

#methods_averageFloat

Calculate the methods average of the self array

Returns:

  • (Float)

    percent of methods executed



34
35
36
37
38
39
40
41
# File 'lib/minitest/cc/file_array.rb', line 34

def methods_average
  methods = reduce(0) { |sum, v| sum + v.methods.to_i }

  return 0.0 if methods.zero?

  methods_executed = reduce(0) { |sum, v| sum + v.methods_executed.to_i }
  methods_executed * 100.0 / methods
end

#total_coverage_percentFloat

Calculate total average of coverage

Returns:

  • (Float)

    percent of coverage



46
47
48
49
50
# File 'lib/minitest/cc/file_array.rb', line 46

def total_coverage_percent
  (lines_average + branches_average + methods_average) / 3
rescue ZeroDivisionError
  0.0
end