free_mutant/lib/mutant/killer.rb

153 lines
2.4 KiB
Ruby
Raw Normal View History

2012-08-01 13:05:34 -04:00
module Mutant
2012-11-21 18:10:50 -05:00
# Abstract base class for mutant killers
class Killer
2013-01-15 17:46:05 -05:00
include Adamantium::Flat, AbstractType, Equalizer.new(:strategy, :mutation, :killed?)
2012-08-16 13:26:15 -04:00
# Test for kill failure
2012-08-01 13:05:34 -04:00
#
# @return [true]
2013-01-15 17:46:05 -05:00
# when mutant was killed
2012-08-01 13:05:34 -04:00
#
# @return [false]
2013-01-15 17:46:05 -05:00
# otherwise
2012-08-01 13:05:34 -04:00
#
# @api private
#
2013-01-15 17:46:05 -05:00
def success?
mutation.success?(self)
end
memoize :success?
# Test if mutant was killed
#
# @return [true]
# if mutant was killed
#
# @return [false]
# otherwise
#
# @api private
#
def killed?
@killed
end
2012-08-01 13:05:34 -04:00
# Return runtime of killer
2012-08-01 13:05:34 -04:00
#
# @return [Float]
2012-08-01 13:05:34 -04:00
#
# @api private
2012-08-01 13:05:34 -04:00
#
attr_reader :runtime
2012-08-01 13:05:34 -04:00
2013-01-15 17:46:05 -05:00
# Return configuration
2012-08-01 13:05:34 -04:00
#
2013-01-15 17:46:05 -05:00
# @return [Configuration]
2012-08-01 13:05:34 -04:00
#
2012-08-16 13:26:15 -04:00
# @api private
#
2013-01-15 17:46:05 -05:00
def configuration
strategy.configuration
end
# Return mutated source
2012-08-01 13:05:34 -04:00
#
# @return [String]
2012-08-01 13:05:34 -04:00
#
2012-08-16 13:26:15 -04:00
# @api private
#
def mutation_source
mutation.source
2012-08-01 13:05:34 -04:00
end
# Return name of killer
#
# @return [String]
#
# @api private
#
def self.type
self::TYPE
end
2013-01-15 17:46:05 -05:00
# Return strategy
#
# @return [Strategy]
#
# @api private
#
attr_reader :strategy
# Return identification
#
# @return [String]
#
# @api private
#
def identification
"#{type}:#{mutation.identification}".freeze
end
memoize :identification
# Return mae of killer
#
# @return [String]
#
# @api private
#
def type
self.class.type
end
2012-08-16 13:26:15 -04:00
# Return mutation to kill
#
# @return [Mutation]
#
# @api private
#
attr_reader :mutation
2012-08-01 13:05:34 -04:00
private
2012-08-16 13:26:15 -04:00
# Initialize killer object
2012-08-01 13:05:34 -04:00
#
# @param [Mutation] mutation
2012-08-01 13:05:34 -04:00
#
# @return [undefined]
#
# @api private
#
2012-11-21 18:10:50 -05:00
def initialize(strategy, mutation)
@strategy, @mutation = strategy, mutation
run_with_benchmark
end
# Run with taking the time
#
# @return [undefined]
#
# @api private
#
def run_with_benchmark
start_time = Time.now
2012-08-01 13:05:34 -04:00
@killed = run
end_time = Time.now
@runtime = end_time - start_time
2012-08-01 13:05:34 -04:00
end
# Run test
#
# @return [true]
# returns true when mutant was killed
#
# @return [false]
# returns false otherwise
#
# @api private
#
abstract_method :run
2012-08-01 13:05:34 -04:00
end
end