Add basic statistics

This commit is contained in:
Markus Schirp 2012-11-22 02:51:16 +01:00
parent 3c1f5b3831
commit 334bf17d45
2 changed files with 75 additions and 6 deletions

View file

@ -4,6 +4,36 @@ module Mutant
class CLI < self class CLI < self
include Equalizer.new(:io) include Equalizer.new(:io)
class Stats
attr_reader :subject
attr_reader :mutation
attr_reader :kill
attr_reader :time
def initialize
@start = Time.now
@subject = @mutation = @kill = @time = 0
end
def runtime
Time.now - @start
end
def subject
@subject +=1
end
def alive
@mutation - @kill
end
def killer(killer)
@mutation +=1
@kill +=1 unless killer.fail?
@time += killer.runtime
end
end
# Reporter subject # Reporter subject
# #
# @param [Subject] subject # @param [Subject] subject
@ -13,6 +43,7 @@ module Mutant
# @api private # @api private
# #
def subject(subject) def subject(subject)
stats.subject
puts("Subject: #{subject.identification}") puts("Subject: #{subject.identification}")
end end
@ -51,15 +82,42 @@ module Mutant
# @api private # @api private
# #
def killer(killer) def killer(killer)
if killer.fail? stats.killer(killer)
failure(killer)
else color, word =
puts("Killed: #{killer.identification} (%02.2fs)" % killer.runtime) if killer.fail?
end [Color::RED, 'Alive']
else
[Color::GREEN, 'Killed']
end
puts(colorize(color, "#{word}: #{killer.identification} (%02.2fs)" % killer.runtime))
self self
end end
# Report errors
#
# @param [Enumerable<Killer>]
#
# @api private
#
# @return [self]
#
def errors(errors)
errors.each do |error|
failure(error)
end
puts
puts "subjects: #{stats.subject}"
puts "mutations: #{stats.mutation}"
puts "kills: #{stats.kill}"
puts "alive: #{stats.alive}"
puts "mtime: %02.2fs" % stats.time
puts "rtime: %02.2fs" % stats.runtime
end
# Return IO stream # Return IO stream
# #
# @return [IO] # @return [IO]
@ -68,6 +126,14 @@ module Mutant
# #
attr_reader :io attr_reader :io
# Retun stats
#
# @return [Stats]
#
# @api private
#
attr_reader :stats
private private
# Initialize reporter # Initialize reporter
@ -80,6 +146,7 @@ module Mutant
# #
def initialize(io) def initialize(io)
@io = io @io = io
@stats = Stats.new
end end
# Report failure on killer # Report failure on killer
@ -101,7 +168,7 @@ module Mutant
raise "Unable to create a diff" raise "Unable to create a diff"
end end
puts(diff) puts(diff)
puts puts("Took: (%02.2fs)" % killer.runtime)
end end
# Test for colored output # Test for colored output

View file

@ -50,6 +50,8 @@ module Mutant
reporter.config(config) reporter.config(config)
run run
reporter.errors(@errors)
end end
# Return reporter # Return reporter