Include additional specs
This commit is contained in:
parent
b21d323e36
commit
a38fefeb1f
@ -3,13 +3,6 @@ require 'rails_helper'
|
|||||||
module Tables
|
module Tables
|
||||||
RSpec.describe Swap do
|
RSpec.describe Swap do
|
||||||
describe '#each' 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
|
let(:swaps) do
|
||||||
acc = []
|
acc = []
|
||||||
described_class.new(initial_solution).each do |solution|
|
described_class.new(initial_solution).each do |solution|
|
||||||
@ -18,13 +11,45 @@ module Tables
|
|||||||
acc
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'yields all possible swaps between the tables' do
|
context 'when there are two tables with two people each' do
|
||||||
expect(swaps).to contain_exactly(
|
let(:initial_solution) do
|
||||||
[%i[a d], %i[c b]],
|
Distribution.new(min_per_table: 2, max_per_table: 2).tap do |distribution|
|
||||||
[%i[b c], %i[d a]],
|
distribution.tables << %i[a b]
|
||||||
[%i[a c], %i[d b]],
|
distribution.tables << %i[c d]
|
||||||
[%i[b d], %i[c a]]
|
end
|
||||||
)
|
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
|
||||||
|
|
||||||
|
context 'when there are two tables with three people each' do
|
||||||
|
let(:initial_solution) do
|
||||||
|
Distribution.new(min_per_table: 3, max_per_table: 3).tap do |distribution|
|
||||||
|
distribution.tables << %i[a b c]
|
||||||
|
distribution.tables << %i[d e f]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'yields all possible swaps between the tables' do
|
||||||
|
expect(swaps).to contain_exactly(
|
||||||
|
[%i[b c d], %i[e f a]],
|
||||||
|
[%i[b c e], %i[f d a]],
|
||||||
|
[%i[b c f], %i[d e a]],
|
||||||
|
[%i[c a d], %i[e f b]],
|
||||||
|
[%i[c a e], %i[f d b]],
|
||||||
|
[%i[c a f], %i[d e b]],
|
||||||
|
[%i[a b d], %i[e f c]],
|
||||||
|
[%i[a b e], %i[f d c]],
|
||||||
|
[%i[a b f], %i[d e c]]
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user