class Mutiny::Mutants::MutationSet
Attributes
mutations[R]
Public Class Methods
new(*mutations)
click to toggle source
# File lib/mutiny/mutants/mutation_set.rb, line 9 def initialize(*mutations) @mutations = mutations end
Public Instance Methods
mutate(subjects)
click to toggle source
TODO : would performance improve by iterating over subjects than over operators? Probably could improve (more) if metamorpher also supported composite transformers so that several mutation operators could be matched simulatenously during a single AST traversal
# File lib/mutiny/mutants/mutation_set.rb, line 16 def mutate(subjects) mutants = MutantSet.new subjects.product(mutations).each do |subject, mutation| mutants.concat(mutate_one(subject, mutation)) end mutants end
Private Instance Methods
extract_position(change)
click to toggle source
# File lib/mutiny/mutants/mutation_set.rb, line 50 def extract_position(change) old_start = change.original_position.begin old_end = change.original_position.end new_start = change.original_position.begin new_end = change.original_position.begin + change.transformed_code.size - 1 { old: old_start..old_end, new: new_start..new_end } end
mutate_one(subject, mutation)
click to toggle source
# File lib/mutiny/mutants/mutation_set.rb, line 26 def mutate_one(subject, mutation) safely_mutate_file(subject.path, mutation).map do |code, position| Mutant.new( subject: subject, mutation_name: mutation.short_name, code: code, position: position ) end end
safely_mutate_file(path, mutation)
click to toggle source
# File lib/mutiny/mutants/mutation_set.rb, line 37 def safely_mutate_file(path, mutation) positions = [] code = mutation.mutate_file(path) do |change| positions << extract_position(change) end code.zip(positions) rescue msg = "Error encountered whilst mutating file at '#{path}' with #{mutation.name}" raise Mutation::Error, msg end