Class: ActiveMutator::Fingerprint

Inherits:
Data
  • Object
show all
Defined in:
lib/active_mutator/fingerprint.rb

Overview

Line-number-independent identity for a mutant, used by the acceptance ledger. ordinal disambiguates byte-identical mutants within one subject (e.g. the two > in a > 0 && b > 0) by source order — without it, accepting one would silently accept both.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



6
7
8
# File 'lib/active_mutator/fingerprint.rb', line 6

def description
  @description
end

#fileObject (readonly)

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



6
7
8
# File 'lib/active_mutator/fingerprint.rb', line 6

def file
  @file
end

#ordinalObject (readonly)

Returns the value of attribute ordinal

Returns:

  • (Object)

    the current value of ordinal



6
7
8
# File 'lib/active_mutator/fingerprint.rb', line 6

def ordinal
  @ordinal
end

#original_snippetObject (readonly)

Returns the value of attribute original_snippet

Returns:

  • (Object)

    the current value of original_snippet



6
7
8
# File 'lib/active_mutator/fingerprint.rb', line 6

def original_snippet
  @original_snippet
end

#subjectObject (readonly)

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



6
7
8
# File 'lib/active_mutator/fingerprint.rb', line 6

def subject
  @subject
end

Class Method Details

.for_mutations(mutations, root:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_mutator/fingerprint.rb', line 7

def self.for_mutations(mutations, root:)
  counters = Hash.new(0)
  mutations.sort_by { |m| [m.subject.name, m.edit.range.begin] }.to_h do |m|
    key = [m.subject.name, m.description, m.original_snippet]
    ordinal = counters[key]
    counters[key] += 1
    [m, new(file: m.subject.file.delete_prefix("#{root}/"),
            subject: m.subject.name,
            description: m.description,
            original_snippet: m.original_snippet,
            ordinal: ordinal)]
  end
end