8447cd4790
* Use the real time temporarily to be consistent with the other places in the code that measure time. When those other areas can be wrapped in a Benchmark.measure block all the benchmarks will be updated to use cpu time, not real (elapsed) time like now.
111 lines
1.8 KiB
Ruby
111 lines
1.8 KiB
Ruby
module Mutant
|
|
# Abstract base class for mutant killers
|
|
class Killer
|
|
include Adamantium::Flat, AbstractType, Equalizer.new(:strategy, :mutation, :killed?)
|
|
|
|
# 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
|
|
|
|
# Test for kill failure
|
|
#
|
|
# @return [true]
|
|
# when killer succeeded
|
|
#
|
|
# @return [false]
|
|
# otherwise
|
|
#
|
|
# @api private
|
|
#
|
|
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
|
|
|
|
# Return runtime of killer
|
|
#
|
|
# @return [Float]
|
|
#
|
|
# @api private
|
|
#
|
|
attr_reader :runtime
|
|
|
|
# Return mutated source
|
|
#
|
|
# @return [String]
|
|
#
|
|
# @api private
|
|
#
|
|
def mutation_source
|
|
mutation.source
|
|
end
|
|
|
|
private
|
|
|
|
# Run with taking the time
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def run_with_benchmark
|
|
times = Benchmark.measure do
|
|
@killed = run
|
|
end
|
|
@runtime = times.real
|
|
end
|
|
|
|
# Run killer
|
|
#
|
|
# @return [true]
|
|
# when mutant was killed
|
|
#
|
|
# @return [false]
|
|
# otherwise
|
|
#
|
|
# @api private
|
|
#
|
|
abstract_method :run
|
|
|
|
end # Killer
|
|
end # Mutant
|