Sha256: f69f60ed3b9e53be7191e2c1470cab3138f2c8a3224e13b2d5555b6e7720389a

Contents?: true

Size: 1.83 KB

Versions: 35

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

# An array of SimpleCov SourceFile instances with additional collection helper
# methods for calculating coverage across them etc.
module SimpleCov
  class FileList < Array
    # Returns the count of lines that have coverage
    def covered_lines
      return 0.0 if empty?
      map { |f| f.covered_lines.count }.inject(:+)
    end

    # Returns the count of lines that have been missed
    def missed_lines
      return 0.0 if empty?
      map { |f| f.missed_lines.count }.inject(:+)
    end

    # Returns the count of lines that are not relevant for coverage
    def never_lines
      return 0.0 if empty?
      map { |f| f.never_lines.count }.inject(:+)
    end

    # Returns the count of skipped lines
    def skipped_lines
      return 0.0 if empty?
      map { |f| f.skipped_lines.count }.inject(:+)
    end

    # Computes the coverage based upon lines covered and lines missed for each file
    # Returns an array with all coverage percentages
    def covered_percentages
      map(&:covered_percent)
    end

    # Finds the least covered file and returns that file's name
    def least_covered_file
      sort_by(&:covered_percent).first.filename
    end

    # Returns the overall amount of relevant lines of code across all files in this list
    def lines_of_code
      covered_lines + missed_lines
    end

    # Computes the coverage based upon lines covered and lines missed
    # @return [Float]
    def covered_percent
      return 100.0 if empty? || lines_of_code.zero?
      Float(covered_lines * 100.0 / lines_of_code)
    end

    # Computes the strength (hits / line) based upon lines covered and lines missed
    # @return [Float]
    def covered_strength
      return 0.0 if empty? || lines_of_code.zero?
      Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code)
    end
  end
end

Version data entries

35 entries across 23 versions & 3 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/simplecov-0.17.1/lib/simplecov/file_list.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/simplecov-0.16.1/lib/simplecov/file_list.rb