Sha256: 35f0cb8069d27f2523c6970287f43b796e21c00522e3102e6d7cefeddc26d6a4

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Coco

  # A very brief summary of the coverage result.
  #
  class Summary
    attr_reader :count, :uncovered_count

    def initialize(result, uncovered)
      @uncovered_count = uncovered.size
      @coverable_files = result.coverable_files
      @count = @coverable_files.size + @uncovered_count
    end

    def to_s
      "Cover #{'%.2f' % average}% | #{uncovered_count} uncovered | #{count} files"
    end

    # Public: Computes the average coverage rate.
    # The formula is simple:
    #
    # N = number of files
    # f = a file
    # average = sum(f_i%) / N
    #
    # In words: Take the sum of the coverage's percentage of all files
    # and divide this sum by the number of files.
    #
    # Returns the Float average rate of coverage.
    #
    def average
      files_present? ? sum / count : 0
    end

    private

    attr_reader :coverable_files

    # Returns the Float sum of all files' percentage.
    #
    def sum
      coverable_files.values.map do |hits|
        CoverageStat.real_percent(hits)
      end.reduce(&:+)
    end

    def files_present?
      count > 0
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coco-0.15.0 lib/coco/cover/summary.rb