Class: Henitai::SurvivorSelector
- Inherits:
-
Object
- Object
- Henitai::SurvivorSelector
- Defined in:
- lib/henitai/survivor_selector.rb
Overview
Filters a mutant list to those that match a set of prior survivor stable IDs.
After calling #select, #unmatched_ids reports which survivor IDs had no corresponding mutant in the current generation. A high unmatched ratio indicates that the source has drifted and a full run is recommended.
Defined Under Namespace
Classes: SelectionError
Constant Summary collapse
- DRIFT_THRESHOLD =
0.5
Instance Method Summary collapse
- #drift_warning? ⇒ Boolean
-
#initialize(survivor_ids:) ⇒ SurvivorSelector
constructor
A new instance of SurvivorSelector.
- #select(mutants) ⇒ Object
- #unmatched_ids ⇒ Object
Constructor Details
#initialize(survivor_ids:) ⇒ SurvivorSelector
Returns a new instance of SurvivorSelector.
13 14 15 16 |
# File 'lib/henitai/survivor_selector.rb', line 13 def initialize(survivor_ids:) @survivor_ids = survivor_ids.to_set @unmatched_ids = nil end |
Instance Method Details
#drift_warning? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/henitai/survivor_selector.rb', line 30 def drift_warning? return false if @survivor_ids.empty? unmatched_ids.size.to_f / @survivor_ids.size > DRIFT_THRESHOLD end |
#select(mutants) ⇒ Object
18 19 20 21 22 |
# File 'lib/henitai/survivor_selector.rb', line 18 def select(mutants) current_index = mutants.to_h { |m| [m.stable_id, m] } matched_ids, @unmatched_ids = @survivor_ids.partition { |id| current_index.key?(id) } matched_ids.filter_map { |id| current_index[id] } end |
#unmatched_ids ⇒ Object
24 25 26 27 28 |
# File 'lib/henitai/survivor_selector.rb', line 24 def unmatched_ids raise SelectionError, "Call #select before accessing #unmatched_ids" if @unmatched_ids.nil? @unmatched_ids end |