class SuperDiff::RSpec::OperationTreeBuilders::CollectionContainingExactly
Public Class Methods
applies_to?(expected, actual)
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 5 def self.applies_to?(expected, actual) SuperDiff::RSpec.a_collection_containing_exactly_something?(expected) && actual.is_a?(::Array) end
new(actual:, **)
click to toggle source
Calls superclass method
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 10 def initialize(actual:, **) super populate_pairings_maximizer_in_expected_with(actual) end
Protected Instance Methods
build_operation_tree()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 37 def build_operation_tree OperationTrees::Array.new([]) end
unary_operations()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 17 def unary_operations operations = [] (0...actual.length).reject do |index| indexes_in_actual_but_not_in_expected.include?(index) end.each do |index| add_noop_to(operations, index) end indexes_in_actual_but_not_in_expected.each do |index| add_insert_to(operations, index) end indexes_in_expected_but_not_in_actual.each do |index| add_delete_to(operations, index) end operations end
Private Instance Methods
add_delete_to(operations, index)
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 58 def add_delete_to(operations, index) value = expected.expected[index] operations << ::SuperDiff::Operations::UnaryOperation.new( name: :delete, collection: collection, key: index, value: value, index: index, ) end
add_insert_to(operations, index)
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 69 def add_insert_to(operations, index) value = actual[index] operations << ::SuperDiff::Operations::UnaryOperation.new( name: :insert, collection: collection, key: index, value: value, index: index, ) end
add_noop_to(operations, index)
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 47 def add_noop_to(operations, index) value = actual[index] operations << ::SuperDiff::Operations::UnaryOperation.new( name: :noop, collection: collection, key: index, value: value, index: index, ) end
collection()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 80 def collection actual + values_in_expected_but_not_in_actual end
indexes_in_actual_but_not_in_expected()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 90 def indexes_in_actual_but_not_in_expected @indexes_in_actual_but_not_in_expected ||= pairings_maximizer_best_solution.unmatched_actual_indexes end
indexes_in_expected_but_not_in_actual()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 95 def indexes_in_expected_but_not_in_actual pairings_maximizer_best_solution.unmatched_expected_indexes end
pairings_maximizer_best_solution()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 99 def pairings_maximizer_best_solution expected.__send__(:best_solution) end
populate_pairings_maximizer_in_expected_with(actual)
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 43 def populate_pairings_maximizer_in_expected_with(actual) expected.matches?(actual) end
values_in_expected_but_not_in_actual()
click to toggle source
# File lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb, line 84 def values_in_expected_but_not_in_actual indexes_in_expected_but_not_in_actual.map do |index| expected.expected[index] end end