Compare commits
No commits in common. "51922b4f1527b0e454e1aca0a74777d9f4af37bf" and "5dce77c29ddf37a5a1e7f9e237aec37106688b46" have entirely different histories.
51922b4f15
...
5dce77c29d
@ -73,63 +73,5 @@ module Tables
|
|||||||
it { expect(calculator.send(:table_size_penalty)).to eq(10) }
|
it { expect(calculator.send(:table_size_penalty)).to eq(10) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#cohesion_penalty' do
|
|
||||||
let(:calculator) { described_class.new(table:, hierarchy:) }
|
|
||||||
let(:table) { Table.new(guests) }
|
|
||||||
|
|
||||||
context 'when all guests belong to the same group' do
|
|
||||||
let(:guests) { create_list(:guest, 6, group: family) }
|
|
||||||
let(:hierarchy) { instance_double(AffinityGroupsHierarchy, discomfort: 0) }
|
|
||||||
|
|
||||||
it 'returns 0 as cohesion penalty' do
|
|
||||||
expect(calculator.send(:cohesion_penalty)).to eq(0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when guests belong to two different groups with discomfort 1' do
|
|
||||||
let(:guests) do
|
|
||||||
create_list(:guest, 3, group: family) +
|
|
||||||
create_list(:guest, 3, group: friends)
|
|
||||||
end
|
|
||||||
let(:hierarchy) do
|
|
||||||
instance_double(AffinityGroupsHierarchy, discomfort: 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'calculates the correct cohesion penalty' do
|
|
||||||
# 3 from family, 3 from friends: 3*3*1 = 9 discomfort
|
|
||||||
expect(calculator.send(:cohesion_penalty)).to eq(10 * (9.0 / 6))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when guests belong to three groups with different discomforts' do
|
|
||||||
let(:guests) do
|
|
||||||
create_list(:guest, 2, group: family) +
|
|
||||||
create_list(:guest, 2, group: friends) +
|
|
||||||
create_list(:guest, 2, group: work)
|
|
||||||
end
|
|
||||||
let(:hierarchy) do
|
|
||||||
instance_double(AffinityGroupsHierarchy)
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(hierarchy).to receive(:discomfort).with(family.id, friends.id).and_return(0.5)
|
|
||||||
allow(hierarchy).to receive(:discomfort).with(family.id, work.id).and_return(1)
|
|
||||||
allow(hierarchy).to receive(:discomfort).with(friends.id, work.id).and_return(0.2)
|
|
||||||
allow(hierarchy).to receive(:discomfort).with(friends.id, family.id).and_return(0.5)
|
|
||||||
allow(hierarchy).to receive(:discomfort).with(work.id, family.id).and_return(1)
|
|
||||||
allow(hierarchy).to receive(:discomfort).with(work.id, friends.id).and_return(0.2)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'calculates the correct cohesion penalty' do
|
|
||||||
# pairs: (family, friends): 2*2*0.5 = 2
|
|
||||||
# (family, work): 2*2*1 = 4
|
|
||||||
# (friends, work): 2*2*0.2 = 0.8
|
|
||||||
# total discomfort = 2 + 4 + 0.8 = 6.8
|
|
||||||
|
|
||||||
expect(calculator.send(:cohesion_penalty)).to eq(10 * (6.8 / 6))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user