require 'rails_helper' module Tables RSpec.describe Swap do describe '#each' do let(:initial_solution) do Distribution.new(min_per_table: 2, max_per_table: 2).tap do |distribution| distribution.tables << %i[a b] distribution.tables << %i[c d] end end let(:swaps) do acc = [] described_class.new(initial_solution).each do |solution| acc << solution.tables.map(&:dup) end acc end it 'yields all possible swaps between the tables' do expect(swaps).to contain_exactly( [%i[a d], %i[c b]], [%i[b c], %i[d a]], [%i[a c], %i[d b]], [%i[b d], %i[c a]] ) end end end end