Sha256: 04a176fa40773434f5e7273e37b1020aade66c16f3e44ba2c90a96f5bc69b381

Contents?: true

Size: 1.89 KB

Versions: 13

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8

module Mutant
  # Abstract base class for mutant killers
  class Killer
    include Adamantium::Flat, AbstractType
    include 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
      @killed = run
    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 mutated source
    #
    # @return [String]
    #
    # @api private
    #
    def mutation_source
      mutation.source
    end

  private

    # Return subject
    #
    # @return [Subject]
    #
    # @api private
    #
    def subject
      mutation.subject
    end

    # Run killer
    #
    # @return [true]
    #   when mutant was killed
    #
    # @return [false]
    #   otherwise
    #
    # @api private
    #
    abstract_method :run

    # 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
  end # Killer
end # Mutant

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mutant-0.5.12 lib/mutant/killer.rb
mutant-0.5.11 lib/mutant/killer.rb
mutant-0.5.10 lib/mutant/killer.rb
mutant-0.5.9 lib/mutant/killer.rb
mutant-0.5.8 lib/mutant/killer.rb
mutant-0.5.7 lib/mutant/killer.rb
mutant-0.5.6 lib/mutant/killer.rb
mutant-0.5.5 lib/mutant/killer.rb
mutant-0.5.4 lib/mutant/killer.rb
mutant-0.5.3 lib/mutant/killer.rb
mutant-0.5.2 lib/mutant/killer.rb
mutant-0.5.1 lib/mutant/killer.rb
mutant-0.5.0 lib/mutant/killer.rb