From 41589af738f4608eac8884af46aad9f367ff9e6a Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Thu, 1 Aug 2024 19:17:03 +0200 Subject: [PATCH] Add test with a table with three uneven groups --- spec/services/tables/discomfort_calculator_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/services/tables/discomfort_calculator_spec.rb b/spec/services/tables/discomfort_calculator_spec.rb index 28e52fe..3764e7e 100644 --- a/spec/services/tables/discomfort_calculator_spec.rb +++ b/spec/services/tables/discomfort_calculator_spec.rb @@ -139,6 +139,20 @@ module Tables expect(calculator.send(:cohesion_penalty)).to eq(4 * 1 + 4 * Rational(1, 2) + 4 * Rational(2, 3)) end end + + context 'when the table contains six guests of three unevenly split groups' do + let(:table) do + [ + create_list(:guest, 3, affinity_group_list: ['family']), + create_list(:guest, 2, affinity_group_list: ['friends']), + create_list(:guest, 1, affinity_group_list: ['work']) + ].flatten + end + + it 'returns the sum of the penalties for each pair of guests' do + expect(calculator.send(:cohesion_penalty)).to eq(6 * 1 + 2 * Rational(1, 2) + 3 * Rational(2, 3)) + end + end end end end