free_mutant/lib/mutant/runner/config.rb

145 lines
2.6 KiB
Ruby
Raw Normal View History

# encoding: utf-8
module Mutant
class Runner
2013-04-20 14:50:36 -04:00
# Runner for object config
class Config < self
2014-05-11 10:27:40 -04:00
# The expected coverage precision
COVERAGE_PRECISION = 1
register Mutant::Config
# Run runner for object
#
# @param [Config] config
# @param [Object] object
#
# @return [Runner]
#
# @api private
#
def self.run(config)
handler = lookup(config.class)
handler.new(config)
end
# Return subject runners
#
# @return [Enumerable<Runner::Subject>]
#
# @api private
#
attr_reader :subjects
2013-03-27 10:52:02 -04:00
# Return failed subjects
#
# @return [Enumerable<Subject>]
#
# @api private
#
def failed_subjects
subjects.reject(&:success?)
2013-03-27 10:52:02 -04:00
end
memoize :failed_subjects
# Test if run was successful
#
# @return [true]
# if run was successful
#
# @return [false]
# otherwise
#
# @api private
#
def success?
coverage.round(COVERAGE_PRECISION) == config.expected_coverage.round(COVERAGE_PRECISION)
2013-03-27 10:52:02 -04:00
end
memoize :success?
2013-04-20 14:50:36 -04:00
# Return strategy
#
# @return [Strategy]
#
# @api private
#
def strategy
config.strategy
end
# Return coverage
#
# @return [Float]
#
# @api private
#
def coverage
return 0.0 if amount_mutations.zero? && amount_kills.zero?
(amount_kills.to_f / amount_mutations) * 100
end
memoize :coverage
# Return amount of kills
#
# @return [Fixnum]
#
# @api private
#
def amount_kills
mutations.select(&:success?).length
end
memoize :amount_kills
# Return mutations
#
# @return [Array<Mutation>]
#
# @api private
#
def mutations
subjects.map(&:mutations).flatten
end
memoize :mutations
# Return amount of mutations
#
# @return [Fixnum]
#
# @api private
#
def amount_mutations
mutations.length
end
private
2013-03-27 10:52:02 -04:00
# Run config
#
# @return [undefined]
#
# @api private
#
2013-04-20 20:48:58 -04:00
def run_subjects
2013-04-20 14:50:36 -04:00
strategy = self.strategy
2013-03-27 10:52:02 -04:00
strategy.setup
2014-05-11 10:25:11 -04:00
@subjects = visit_collection(config.subjects)
2013-03-27 10:52:02 -04:00
strategy.teardown
2013-04-20 20:48:58 -04:00
end
# Run with strategy management
#
# @return [undefined]
#
# @api private
#
def run
run_subjects
@end = Time.now
reporter.report(self)
end
2013-06-14 14:54:02 -04:00
end # Config
end # Runner
end # Mutant