wedding-planner/spec/services/tables/discomfort_calculator_spec.rb

52 lines
1.5 KiB
Ruby
Raw Normal View History

require 'rails_helper'
module Tables
2024-07-31 22:53:19 +02:00
RSpec.describe DiscomfortCalculator do
let(:calculator) { described_class.new(table) }
describe '#cohesion_penalty' do
context 'when the table contains just two guests' do
let(:table) do
[
create(:guest, affinity_group_list: ['family']),
create(:guest, affinity_group_list: ['friends'])
]
end
before do
allow(AffinityGroupsHierarchy.instance).to receive(:distance).and_return(distance)
end
context 'when they belong to the same group' do
let(:distance) { 0 }
it { expect(calculator.send(:cohesion_penalty)).to eq(0) }
end
context 'when they belong to completely unrelated groups' do
let(:distance) { nil }
it { expect(calculator.send(:cohesion_penalty)).to eq(1) }
end
context 'when they belong to groups at a distance of 1' do
let(:distance) { 1 }
it { expect(calculator.send(:cohesion_penalty)).to eq(0.5) }
end
context 'when they belong to groups at a distance of 2' do
let(:distance) { 2 }
it { expect(calculator.send(:cohesion_penalty)).to eq(Rational(2, 3)) }
end
context 'when they belong to groups at a distance of 3' do
let(:distance) { 3 }
it { expect(calculator.send(:cohesion_penalty)).to eq(Rational(3, 4)) }
end
end
end
end
end