2012-08-01 13:05:34 -04:00
|
|
|
module Mutant
|
2012-08-14 06:27:56 -04:00
|
|
|
# Abstract runner for mutant killers
|
|
|
|
class Killer
|
2012-08-02 19:28:15 -04:00
|
|
|
include Immutable, Abstract
|
2012-08-15 22:10:54 -04:00
|
|
|
extend MethodObject
|
2012-08-01 13:05:34 -04:00
|
|
|
|
2012-08-16 13:26:15 -04:00
|
|
|
# Test for kill failure
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [true]
|
|
|
|
# returns true when mutant was killed
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def fail?
|
|
|
|
!@killed
|
|
|
|
end
|
2012-08-01 13:05:34 -04:00
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return runtime of killer
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [Float]
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @api private
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
attr_reader :runtime
|
2012-08-01 13:05:34 -04:00
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return original source
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [String]
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-16 13:26:15 -04:00
|
|
|
# @api private
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def original_source
|
|
|
|
mutation.original_source
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return mutated source
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [String]
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-16 13:26:15 -04:00
|
|
|
# @api private
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def mutation_source
|
|
|
|
mutation.source
|
2012-08-01 13:05:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2012-08-16 13:26:15 -04:00
|
|
|
# Return mutation to kill
|
|
|
|
#
|
|
|
|
# @return [Mutation]
|
|
|
|
#
|
|
|
|
# @api private
|
2012-08-15 22:10:54 -04:00
|
|
|
attr_reader :mutation
|
|
|
|
private :mutation
|
2012-08-01 13:05:34 -04:00
|
|
|
|
2012-08-16 13:26:15 -04:00
|
|
|
# Initialize killer object
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @param [Mutation] mutation
|
2012-08-01 13:05:34 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def initialize(mutation)
|
|
|
|
@mutation = mutation
|
|
|
|
@mutation.insert
|
|
|
|
start_time = Time.now
|
2012-08-01 13:05:34 -04:00
|
|
|
@killed = run
|
2012-08-15 22:10:54 -04:00
|
|
|
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
|
|
|
|
#
|
2012-08-02 19:28:15 -04:00
|
|
|
abstract_method :run
|
2012-08-01 13:05:34 -04:00
|
|
|
end
|
|
|
|
end
|