free_mutant/lib/mutant/killer.rb

124 lines
1.9 KiB
Ruby
Raw Normal View History

# encoding: utf-8
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-07-28 13:56:02 -04:00
include Adamantium::Flat, AbstractType
include Equalizer.new(:strategy, :mutation, :killed?)
2013-02-01 17:39:00 -05: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
@killed = run
2013-02-01 17:39:00 -05:00
end
2013-04-17 23:31:21 -04:00
2012-08-16 13:26:15 -04:00
# Test for kill failure
2012-08-01 13:05:34 -04:00
#
# @return [true]
2013-02-01 17:39:00 -05:00
# when killer succeeded
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 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
private
# Return subject
#
# @return [Subject]
#
# @api private
#
def subject
mutation.subject
end
2013-02-01 17:39:00 -05:00
# Run killer
2012-08-01 13:05:34 -04:00
#
# @return [true]
2013-02-01 17:39:00 -05:00
# when mutant was killed
2012-08-01 13:05:34 -04:00
#
# @return [false]
2013-02-01 17:39:00 -05:00
# otherwise
2012-08-01 13:05:34 -04:00
#
# @api private
#
abstract_method :run
2014-01-17 18:15:42 -05:00
# Null killer that never kills a mutation
class Null < self
private
# Run killer
#
# @return [true]
# when mutant was killed
#
# @return [false]
# otherwise
#
# @api private
#
def run
false
end
end
2013-06-14 14:54:02 -04:00
end # Killer
end # Mutant