From 021b82b28e148dadf58bd97f37ee93b989e00990 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 11:34:26 +0100 Subject: [PATCH] Use average discomfort instead of sum --- app/services/tables/discomfort_calculator.rb | 2 +- spec/services/tables/discomfort_calculator_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/services/tables/discomfort_calculator.rb b/app/services/tables/discomfort_calculator.rb index 0d40670..9942bf0 100644 --- a/app/services/tables/discomfort_calculator.rb +++ b/app/services/tables/discomfort_calculator.rb @@ -8,7 +8,7 @@ module Tables end def calculate - table_size_penalty + cohesion_penalty + table_size_penalty + 10 * (cohesion_penalty * 1.0 / table.size) end private diff --git a/spec/services/tables/discomfort_calculator_spec.rb b/spec/services/tables/discomfort_calculator_spec.rb index b7a3030..eab291b 100644 --- a/spec/services/tables/discomfort_calculator_spec.rb +++ b/spec/services/tables/discomfort_calculator_spec.rb @@ -10,6 +10,19 @@ module Tables let(:work) { create(:group, name: 'work') } let(:school) { create(:group, name: 'school') } + describe '#calculate' do + before do + allow(calculator).to receive(:table_size_penalty).and_return(2) + allow(calculator).to receive(:cohesion_penalty).and_return(3) + end + + let(:table) { Table.new(create_list(:guest, 6)) } + + it 'returns the sum of the table size penalty and the average cohesion penalty' do + expect(calculator.calculate).to eq(2 + 10 * 3 / 6.0) + end + end + describe '#table_size_penalty' do before do table.min_per_table = 5