2012-08-01 19:05:34 +02:00
|
|
|
module Mutant
|
2012-11-22 00:10:50 +01:00
|
|
|
# Abstract base class for mutant killers
|
2012-08-14 12:27:56 +02:00
|
|
|
class Killer
|
2013-01-15 23:46:05 +01:00
|
|
|
include Adamantium::Flat, AbstractType, Equalizer.new(:strategy, :mutation, :killed?)
|
2013-02-01 23:39:00 +01:00
|
|
|
|
|
|
|
# Return strategy
|
|
|
|
#
|
|
|
|
# @return [Strategy]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :strategy
|
|
|
|
|
|
|
|
# Return mutation to kill
|
|
|
|
#
|
|
|
|
# @return [Mutation]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :mutation
|
|
|
|
|
|
|
|
# Initialize killer object
|
|
|
|
#
|
|
|
|
# @param [Strategy] strategy
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(strategy, mutation)
|
|
|
|
@strategy, @mutation = strategy, mutation
|
|
|
|
run_with_benchmark
|
|
|
|
end
|
2013-04-17 20:31:21 -07:00
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Test for kill failure
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [true]
|
2013-02-01 23:39:00 +01:00
|
|
|
# when killer succeeded
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [false]
|
2013-01-15 23:46:05 +01:00
|
|
|
# otherwise
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-01-15 23:46:05 +01: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
|
2012-08-16 04:10:54 +02:00
|
|
|
end
|
2012-08-01 19:05:34 +02:00
|
|
|
|
2012-08-16 04:10:54 +02:00
|
|
|
# Return runtime of killer
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [Float]
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @api private
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-10-26 11:24:29 +02:00
|
|
|
attr_reader :runtime
|
2012-08-01 19:05:34 +02:00
|
|
|
|
2012-08-16 04:10:54 +02:00
|
|
|
# Return mutated source
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [String]
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 19:26:15 +02:00
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def mutation_source
|
|
|
|
mutation.source
|
2012-08-01 19:05:34 +02:00
|
|
|
end
|
|
|
|
|
2012-12-07 17:14:18 +01:00
|
|
|
private
|
|
|
|
|
2012-11-22 00:10:50 +01:00
|
|
|
# Run with taking the time
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run_with_benchmark
|
2013-06-23 15:12:33 -07:00
|
|
|
times = Benchmark.measure do
|
|
|
|
@killed = run
|
|
|
|
end
|
|
|
|
@runtime = times.real
|
2012-08-01 19:05:34 +02:00
|
|
|
end
|
|
|
|
|
2013-02-01 23:39:00 +01:00
|
|
|
# Run killer
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
|
|
|
# @return [true]
|
2013-02-01 23:39:00 +01:00
|
|
|
# when mutant was killed
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
|
|
|
# @return [false]
|
2013-02-01 23:39:00 +01:00
|
|
|
# otherwise
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-03 01:28:15 +02:00
|
|
|
abstract_method :run
|
2012-12-29 20:12:48 +01:00
|
|
|
|
2013-06-14 20:54:02 +02:00
|
|
|
end # Killer
|
|
|
|
end # Mutant
|