2025-01-13 20:38:47 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2025-01-13 21:37:02 +01:00
|
|
|
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
2024-10-28 22:07:35 +00:00
|
|
|
|
2024-12-28 18:37:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-08-01 18:27:41 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
module Tables
|
|
|
|
RSpec.describe DiscomfortCalculator do
|
2024-11-10 11:22:51 +01:00
|
|
|
let(:calculator) { described_class.new(table:) }
|
2024-08-01 18:27:41 +00:00
|
|
|
|
2024-11-01 12:04:15 +01:00
|
|
|
let(:family) { create(:group, name: 'family') }
|
|
|
|
let(:friends) { create(:group, name: 'friends') }
|
|
|
|
let(:work) { create(:group, name: 'work') }
|
|
|
|
let(:school) { create(:group, name: 'school') }
|
|
|
|
|
2024-11-10 11:34:26 +01:00
|
|
|
describe '#calculate' do
|
|
|
|
before do
|
2024-12-28 18:07:22 +01:00
|
|
|
allow(calculator).to receive_messages(table_size_penalty: 2, cohesion_discomfort: 3)
|
2024-11-10 11:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:table) { Table.new(create_list(:guest, 6)) }
|
|
|
|
|
2024-12-16 18:52:34 +01:00
|
|
|
it 'returns the sum of the table size penalty and the average cohesion penalty', :aggregate_failures do
|
|
|
|
expect(calculator.calculate).to eq(7)
|
|
|
|
expect(calculator.breakdown).to eq(table_size_penalty: 2, cohesion_penalty: 5)
|
2024-11-10 11:34:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-10 11:22:51 +01:00
|
|
|
describe '#table_size_penalty' do
|
|
|
|
before do
|
|
|
|
table.min_per_table = 5
|
|
|
|
table.max_per_table = 7
|
|
|
|
end
|
2024-12-28 18:07:22 +01:00
|
|
|
|
2024-11-10 11:22:51 +01:00
|
|
|
context 'when the number of guests is in the lower bound' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 5)) }
|
|
|
|
|
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the number of guests is within the table size limits' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 6)) }
|
|
|
|
|
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the number of guests is in the upper bound' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 7)) }
|
|
|
|
|
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the number of guests is one unit below the lower bound' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 4)) }
|
|
|
|
|
2024-11-10 18:40:26 +01:00
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(5) }
|
2024-11-10 11:22:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the number of guests is two units below the lower bound' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 3)) }
|
|
|
|
|
2024-11-10 18:40:26 +01:00
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(10) }
|
2024-11-10 11:22:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the number of guests is one unit above the upper bound' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 8)) }
|
|
|
|
|
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(5) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the number of guests is two units above the upper bound' do
|
|
|
|
let(:table) { Table.new(create_list(:guest, 9)) }
|
|
|
|
|
|
|
|
it { expect(calculator.send(:table_size_penalty)).to eq(10) }
|
|
|
|
end
|
|
|
|
end
|
2024-08-01 18:27:41 +00:00
|
|
|
end
|
|
|
|
end
|