Class: Mutineer::KillMatrix
- Inherits:
-
Object
- Object
- Mutineer::KillMatrix
- Defined in:
- lib/mutineer/kill_matrix.rb
Overview
Which tests kill which mutants, read from the Kills rows of a --matrix
run. Pure: it reads results and runs nothing, and it never touches the score.
A test is a [file, name, id] triple (see Kills); file and id identify it,
and every row names a test the same way (see Runner.share_tests). The tests it knows are
the ones that ran against at least one mutant of this run, so every answer
is relative to the run's mutants: a test of code outside the run's sources
kills nothing here.
- A blind test ran in at least one complete row and killed no mutant. A test seen only in incomplete rows is never called blind.
- A redundant test killed at least one mutant, and each mutant it killed has another killer. Each test is judged alone: two redundant tests can be the only killers of one mutant, so delete them one at a time. Finding the smallest set of tests that keeps every kill is a set-cover problem, out of scope here.
Kills in incomplete rows count, since they did happen. An incomplete row can miss kills, so when #complete? is false a blind test may have killed one of those mutants.
Instance Attribute Summary collapse
-
#rows ⇒ Array<Mutineer::Result>
readonly
The results that carry a Kills row, in run order.
Instance Method Summary collapse
-
#blind ⇒ Array<Array(String, String, String)>
Tests that ran in a complete row and killed no mutant.
-
#complete? ⇒ Boolean
True when every row is complete.
-
#incomplete_rows ⇒ Array<Mutineer::Result>
The rows that are not complete.
-
#initialize(results) ⇒ KillMatrix
constructor
A new instance of KillMatrix.
-
#kill_count(test) ⇒ Integer
How many mutants
testkilled. -
#redundant ⇒ Array<Array(String, String, String)>
Tests that killed a mutant, where every mutant they killed has another killer.
-
#tests ⇒ Array<Array(String, String, String)>
Every test that ran against at least one mutant, sorted by file, name and id.
Constructor Details
#initialize(results) ⇒ KillMatrix
Returns a new instance of KillMatrix.
33 34 35 36 37 |
# File 'lib/mutineer/kill_matrix.rb', line 33 def initialize(results) @rows = results.select(&:kills) @kill_counts = Hash.new(0) @rows.each { |r| r.kills.killed_by.each { |test| @kill_counts[test] += 1 } } end |
Instance Attribute Details
#rows ⇒ Array<Mutineer::Result> (readonly)
The results that carry a Mutineer::Kills row, in run order.
30 31 32 |
# File 'lib/mutineer/kill_matrix.rb', line 30 def rows @rows end |
Instance Method Details
#blind ⇒ Array<Array(String, String, String)>
Tests that ran in a complete row and killed no mutant.
71 72 73 74 75 76 |
# File 'lib/mutineer/kill_matrix.rb', line 71 def blind @blind ||= begin seen = @rows.select { |r| r.kills.complete }.flat_map { |r| r.kills.ran }.to_set tests.select { |test| kill_count(test).zero? && seen.include?(test) } end end |
#complete? ⇒ Boolean
True when every row is complete.
49 50 51 |
# File 'lib/mutineer/kill_matrix.rb', line 49 def complete? @rows.all? { |r| r.kills.complete } end |
#incomplete_rows ⇒ Array<Mutineer::Result>
The rows that are not complete.
56 57 58 |
# File 'lib/mutineer/kill_matrix.rb', line 56 def incomplete_rows @rows.reject { |r| r.kills.complete } end |
#kill_count(test) ⇒ Integer
How many mutants test killed.
64 65 66 |
# File 'lib/mutineer/kill_matrix.rb', line 64 def kill_count(test) @kill_counts[test] end |
#redundant ⇒ Array<Array(String, String, String)>
Tests that killed a mutant, where every mutant they killed has another killer.
81 82 83 84 85 86 |
# File 'lib/mutineer/kill_matrix.rb', line 81 def redundant @redundant ||= begin sole = @rows.filter_map { |r| r.kills.killed_by.first if r.kills.killed_by.size == 1 }.to_set tests.select { |test| kill_count(test).positive? && !sole.include?(test) } end end |
#tests ⇒ Array<Array(String, String, String)>
Every test that ran against at least one mutant, sorted by file, name and id.
42 43 44 |
# File 'lib/mutineer/kill_matrix.rb', line 42 def tests @tests ||= @rows.flat_map { |r| r.kills.ran + r.kills.killed_by }.uniq.sort end |