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
|
2012-11-26 11:30:00 +01:00
|
|
|
include Adamantium::Flat, AbstractType
|
2012-11-21 22:55:53 +01: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]
|
|
|
|
# returns true when mutant was killed
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def fail?
|
|
|
|
!@killed
|
|
|
|
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 original 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 original_source
|
|
|
|
mutation.original_source
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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-11-22 00:10:50 +01:00
|
|
|
# Return strategy
|
|
|
|
#
|
|
|
|
# @return [Strategy]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :strategy
|
|
|
|
|
2012-11-21 22:55:53 +01:00
|
|
|
# Return name of killer
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.type
|
|
|
|
self::TYPE
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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 19:26:15 +02:00
|
|
|
# Return mutation to kill
|
|
|
|
#
|
|
|
|
# @return [Mutation]
|
|
|
|
#
|
|
|
|
# @api private
|
2012-08-20 17:53:41 +02:00
|
|
|
#
|
2012-11-21 22:28:08 +01:00
|
|
|
attr_reader :mutation
|
2012-08-01 19:05:34 +02:00
|
|
|
|
2012-12-07 17:14:18 +01:00
|
|
|
private
|
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Initialize killer object
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @param [Mutation] mutation
|
2012-08-01 19:05:34 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-11-22 00:10:50 +01: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
|
2012-08-16 04:10:54 +02:00
|
|
|
start_time = Time.now
|
2012-08-01 19:05:34 +02:00
|
|
|
@killed = run
|
2012-08-16 04:10:54 +02:00
|
|
|
end_time = Time.now
|
|
|
|
@runtime = end_time - start_time
|
2012-08-01 19:05:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Run test
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true when mutant was killed
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-03 01:28:15 +02:00
|
|
|
abstract_method :run
|
2012-08-01 19:05:34 +02:00
|
|
|
end
|
|
|
|
end
|