Class: SixthSense::MutationMatrixMutantGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/sixth_sense/mutation_matrix_mutant_generator.rb

Constant Summary collapse

BUILTIN_OPERATORS =
%w[
  arithmetic_operator_replacement
  boolean_flip
  collection_literal_empty
  collection_literal_replacement
  comparison_operator_replacement
  condition_negation
  constant_replacement
  logical_operator_replacement
  loop_condition_negation
  method_call_replacement
  nil_replacement
  numeric_literal_decrement
  numeric_literal_increment
  numeric_literal_negation
  numeric_literal_one
  numeric_literal_zero
  predicate_method_replacement
  range_operator_replacement
  regexp_literal_empty
  return_value_nil
  string_literal_empty
  string_literal_replacement
  symbol_literal_replacement
].freeze
METHOD_REPLACEMENTS =
{
  "__send__" => %w[public_send],
  "all?" => %w[any? none?],
  "any?" => %w[all? empty? none?],
  "append" => %w[prepend],
  "assoc" => %w[rassoc],
  "at" => %w[fetch key?],
  "bytes" => %w[chars],
  "capitalize!" => %w[capitalize],
  "chars" => %w[bytes],
  "chomp!" => %w[chomp],
  "chop!" => %w[chop],
  "chunk" => %w[each],
  "chunk_while" => %w[each],
  "collect" => %w[each],
  "collect!" => %w[collect],
  "collect_concat" => %w[collect],
  "compact!" => %w[compact],
  "ceil" => %w[floor],
  "count" => %w[size length],
  "delete!" => %w[delete],
  "delete_if" => %w[reject],
  "detect" => %w[first last],
  "downcase" => %w[upcase],
  "downcase!" => %w[downcase],
  "drop" => %w[take],
  "each_cons" => %w[each],
  "each_key" => %w[each_value],
  "each_slice" => %w[each],
  "each_value" => %w[each_key],
  "each_with_index" => %w[each],
  "each_with_object" => %w[each],
  "empty?" => %w[any?],
  "encode!" => %w[encode],
  "end_with?" => %w[start_with?],
  "even?" => %w[odd?],
  "fetch" => %w[key?],
  "filter" => %w[reject],
  "filter!" => %w[filter],
  "filter_map" => %w[map],
  "find" => %w[first last],
  "first" => %w[last],
  "flat_map" => %w[map],
  "flatten!" => %w[flatten],
  "floor" => %w[ceil],
  "grep" => %w[grep_v],
  "grep_v" => %w[grep],
  "gsub" => %w[sub],
  "gsub!" => %w[gsub],
  "include?" => %w[exclude?],
  "is_a?" => %w[instance_of?],
  "keep_if" => %w[select],
  "key?" => %w[value?],
  "keys" => %w[values],
  "kind_of?" => %w[instance_of?],
  "last" => %w[first],
  "lstrip!" => %w[lstrip],
  "map" => %w[each],
  "map!" => %w[map],
  "match" => %w[match?],
  "max" => %w[first last min],
  "max_by" => %w[first last min_by],
  "merge!" => %w[merge],
  "method" => %w[public_method],
  "min" => %w[first last max],
  "min_by" => %w[first last max_by],
  "negative?" => %w[positive?],
  "none?" => %w[any? all?],
  "odd?" => %w[even?],
  "pop" => %w[shift],
  "positive?" => %w[negative?],
  "pred" => %w[succ],
  "prepend" => %w[append],
  "push" => %w[unshift],
  "rassoc" => %w[assoc],
  "reject" => %w[select],
  "reject!" => %w[reject],
  "reverse!" => %w[reverse],
  "reverse_each" => %w[each],
  "reverse_map" => %w[map each],
  "reverse_merge" => %w[merge],
  "rotate!" => %w[rotate],
  "rstrip!" => %w[rstrip],
  "sample" => %w[first last],
  "scrub!" => %w[scrub],
  "select" => %w[reject],
  "select!" => %w[select],
  "send" => %w[public_send __send__],
  "shift" => %w[pop],
  "shuffle!" => %w[shuffle],
  "slice_after" => %w[each],
  "slice_before" => %w[each],
  "slice_when" => %w[each],
  "size" => %w[length count],
  "sort!" => %w[sort],
  "sort_by" => %w[sort],
  "sort_by!" => %w[sort_by],
  "squeeze!" => %w[squeeze],
  "start_with?" => %w[end_with?],
  "strip" => %w[lstrip rstrip],
  "strip!" => %w[strip],
  "sub!" => %w[sub],
  "succ" => %w[pred],
  "swapcase!" => %w[swapcase],
  "take" => %w[drop],
  "to_a" => %w[to_ary],
  "to_f" => %w[to_i],
  "to_h" => %w[to_hash],
  "to_i" => %w[to_int],
  "to_s" => %w[to_str],
  "tr!" => %w[tr],
  "tr_s!" => %w[tr_s],
  "transform_keys" => %w[transform_values],
  "transform_keys!" => %w[transform_keys],
  "transform_values" => %w[transform_keys],
  "transform_values!" => %w[transform_values],
  "unicode_normalize!" => %w[unicode_normalize],
  "uniq!" => %w[uniq],
  "unshift" => %w[push],
  "upcase" => %w[downcase],
  "upcase!" => %w[upcase],
  "values" => %w[keys],
  "values_at" => %w[fetch_values],
  "zero?" => %w[nonzero?]
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config: {}) ⇒ MutationMatrixMutantGenerator

Returns a new instance of MutationMatrixMutantGenerator.



162
163
164
# File 'lib/sixth_sense/mutation_matrix_mutant_generator.rb', line 162

def initialize(config: {})
  @config = config
end

Instance Method Details

#generate(plan) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/sixth_sense/mutation_matrix_mutant_generator.rb', line 166

def generate(plan)
  generated = generate_mutants(plan)
  skipped, executable = generated.partition { |mutant| operator_excluded?(mutant.operator) }
  selected, sampling = select_mutants(executable)
  {
    mutants: skipped.map { |mutant| mark_skipped(mutant) } + selected,
    sampling: sampling.merge("excluded_count" => skipped.length)
  }
end