Initialize Tables::WheelSwap class
This commit is contained in:
parent
185f359942
commit
e8a88b50e2
16
app/services/tables/wheel_swap.rb
Normal file
16
app/services/tables/wheel_swap.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
||||||
|
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Tables
|
||||||
|
class WheelSwap
|
||||||
|
private attr_reader :initial_solution
|
||||||
|
def initialize(initial_solution)
|
||||||
|
@initial_solution = initial_solution
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
@initial_solution.deep_dup
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
21
spec/services/tables/wheel_swap_spec.rb
Normal file
21
spec/services/tables/wheel_swap_spec.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
module Tables
|
||||||
|
RSpec.describe WheelSwap do
|
||||||
|
context "when the solution has three tables" do
|
||||||
|
let(:initial_solution) do
|
||||||
|
Distribution.new(min_per_table: 3, max_per_table: 3).tap do |distribution|
|
||||||
|
distribution.tables << Set[:a, :b, :c].to_table
|
||||||
|
distribution.tables << Set[:d, :e, :f].to_table
|
||||||
|
distribution.tables << Set[:g, :h, :i].to_table
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "swaps a random guest from each table with a guest from another table", :aggregate_failures do
|
||||||
|
result = described_class.new(initial_solution).call
|
||||||
|
|
||||||
|
expect(result.tables.size).to eq(3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user