2012-12-07 09:59:37 -05:00
|
|
|
module Mutant
|
|
|
|
class Reporter
|
|
|
|
|
|
|
|
# Stats gathered while reporter is running
|
|
|
|
class Stats
|
|
|
|
|
|
|
|
# Return subject count
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-10 18:17:19 -05:00
|
|
|
attr_reader :subjects
|
2012-12-07 09:59:37 -05:00
|
|
|
|
|
|
|
# Return mutation count
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-10 18:17:19 -05:00
|
|
|
attr_reader :mutations
|
|
|
|
|
|
|
|
# Return skip count
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :noop_fails
|
2012-12-07 09:59:37 -05:00
|
|
|
|
|
|
|
# Return kill count
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-10 18:17:19 -05:00
|
|
|
attr_reader :kills
|
2012-12-07 09:59:37 -05:00
|
|
|
|
|
|
|
# Return mutation runtime
|
|
|
|
#
|
|
|
|
# @return [Float]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :time
|
|
|
|
|
2012-12-12 16:31:14 -05:00
|
|
|
# Initialize object
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-07 09:59:37 -05:00
|
|
|
def initialize
|
|
|
|
@start = Time.now
|
2012-12-10 18:17:19 -05:00
|
|
|
@noop_fails = @subjects = @mutations = @kills = @time = 0
|
2012-12-07 09:59:37 -05:00
|
|
|
end
|
|
|
|
|
2012-12-12 16:31:14 -05:00
|
|
|
# Return runtime in seconds
|
|
|
|
#
|
|
|
|
# @return [Float]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-07 09:59:37 -05:00
|
|
|
def runtime
|
|
|
|
Time.now - @start
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:31:14 -05:00
|
|
|
# Count subject
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-07 09:59:37 -05:00
|
|
|
def subject
|
2012-12-10 18:17:19 -05:00
|
|
|
@subjects +=1
|
|
|
|
self
|
2012-12-07 09:59:37 -05:00
|
|
|
end
|
|
|
|
|
2012-12-12 16:31:14 -05:00
|
|
|
# Return number of mutants alive
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-07 09:59:37 -05:00
|
|
|
def alive
|
2012-12-10 18:17:19 -05:00
|
|
|
@mutations - @kills
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:31:14 -05:00
|
|
|
# Count noop mutation fail
|
|
|
|
#
|
|
|
|
# @param [Killer] killer
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-10 18:17:19 -05:00
|
|
|
def noop_fail(killer)
|
|
|
|
@noop_fails += 1
|
|
|
|
@time += killer.runtime
|
|
|
|
self
|
2012-12-07 09:59:37 -05:00
|
|
|
end
|
|
|
|
|
2012-12-12 16:31:14 -05:00
|
|
|
# Count killer
|
|
|
|
#
|
|
|
|
# @param [Killer] killer
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-07 09:59:37 -05:00
|
|
|
def killer(killer)
|
2012-12-10 18:17:19 -05:00
|
|
|
@mutations +=1
|
|
|
|
@kills +=1 unless killer.fail?
|
2012-12-07 09:59:37 -05:00
|
|
|
@time += killer.runtime
|
2012-12-10 18:17:19 -05:00
|
|
|
self
|
2012-12-07 09:59:37 -05:00
|
|
|
end
|
|
|
|
|
2012-12-10 18:17:19 -05:00
|
|
|
end
|
2012-12-07 09:59:37 -05:00
|
|
|
end
|
|
|
|
end
|