Initial tests for the swap class
This commit is contained in:
parent
8c4e6a0109
commit
2dd11bb83d
@ -7,6 +7,7 @@ module Tables
|
|||||||
def initialize(min_per_table:, max_per_table:)
|
def initialize(min_per_table:, max_per_table:)
|
||||||
@min_per_table = min_per_table
|
@min_per_table = min_per_table
|
||||||
@max_per_table = max_per_table
|
@max_per_table = max_per_table
|
||||||
|
@tables = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def random_distribution(people)
|
def random_distribution(people)
|
||||||
|
33
spec/services/tables/swap_spec.rb
Normal file
33
spec/services/tables/swap_spec.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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' do
|
||||||
|
expect(swaps.count).to eq(4)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'swaps the people' do
|
||||||
|
expect(swaps).to include([%i[a d], %i[c b]])
|
||||||
|
expect(swaps).to include([%i[b c], %i[d a]])
|
||||||
|
expect(swaps).to include([%i[a c], %i[d b]])
|
||||||
|
expect(swaps).to include([%i[b d], %i[c a]])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user