Sha256: cc43bb658923f9d4c75fac6fbddb612c5228978338e61dbd22e7468832826d75

Contents?: true

Size: 1.78 KB

Versions: 20

Compression:

Stored size: 1.78 KB

Contents

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mutant-0.3.0.beta21 lib/mutant/killer.rb
mutant-0.3.0.beta20 lib/mutant/killer.rb
mutant-0.3.0.beta19 lib/mutant/killer.rb
mutant-0.3.0.beta18 lib/mutant/killer.rb
mutant-0.3.0.beta17 lib/mutant/killer.rb
mutant-0.3.0.beta16 lib/mutant/killer.rb
mutant-0.3.0.beta15 lib/mutant/killer.rb
mutant-0.3.0.beta14 lib/mutant/killer.rb
mutant-0.3.0.beta13 lib/mutant/killer.rb
mutant-0.3.0.beta12 lib/mutant/killer.rb
mutant-0.3.0.beta11 lib/mutant/killer.rb
mutant-0.3.0.beta10 lib/mutant/killer.rb
mutant-0.3.0.beta9 lib/mutant/killer.rb
mutant-0.3.0.beta8 lib/mutant/killer.rb
mutant-0.3.0.beta7 lib/mutant/killer.rb
mutant-0.3.0.beta6 lib/mutant/killer.rb
mutant-0.3.0.beta5 lib/mutant/killer.rb
mutant-0.3.0.beta4 lib/mutant/killer.rb
mutant-0.3.0.beta3 lib/mutant/killer.rb
mutant-0.3.0.beta2 lib/mutant/killer.rb