Some checks failed
		
		
	
	Run unit tests / copyright_notice (pull_request) Successful in 1m50s
				
			Run unit tests / rubocop (pull_request) Failing after 2m12s
				
			Run unit tests / check-licenses (pull_request) Successful in 2m50s
				
			Run unit tests / unit_tests (pull_request) Successful in 3m48s
				
			Run unit tests / build-static-assets (pull_request) Successful in 1h45m6s
				
			
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | 
						|
 | 
						|
# frozen_string_literal: true
 | 
						|
 | 
						|
require 'rails_helper'
 | 
						|
 | 
						|
module Tables
 | 
						|
  RSpec.describe Shift do
 | 
						|
    describe '#each' do
 | 
						|
      let(:shifts) do
 | 
						|
        acc = []
 | 
						|
        described_class.new(initial_solution).each do |solution| # rubocop:disable Style/MapIntoArray -- #map is not implemented
 | 
						|
          acc << solution.tables.map(&:dup)
 | 
						|
        end
 | 
						|
        acc
 | 
						|
      end
 | 
						|
 | 
						|
      context 'when there are two tables with two people each' do
 | 
						|
        let(:initial_solution) do
 | 
						|
          Distribution.new(min_per_table: 2, max_per_table: 2, tables_arrangement_id: nil).tap do |distribution|
 | 
						|
            distribution.tables << Set[:a, :b].to_table
 | 
						|
            distribution.tables << Set[:c, :d].to_table
 | 
						|
          end
 | 
						|
        end
 | 
						|
 | 
						|
        it 'yields all possible shifts between the tables' do
 | 
						|
          expect(shifts).to contain_exactly(
 | 
						|
            [Set[:b], Set[:c, :d, :a]],
 | 
						|
            [Set[:a], Set[:c, :d, :b]],
 | 
						|
            [Set[:b, :a, :d], Set[:c]],
 | 
						|
            [Set[:b, :a, :c], Set[:d]]
 | 
						|
          )
 | 
						|
        end
 | 
						|
      end
 | 
						|
 | 
						|
      context 'when there are two tables with three people each' do
 | 
						|
        let(:initial_solution) do
 | 
						|
          Distribution.new(min_per_table: 3, max_per_table: 3, tables_arrangement_id: nil).tap do |distribution|
 | 
						|
            distribution.tables << Set[:a, :b, :c].to_table
 | 
						|
            distribution.tables << Set[:d, :e, :f].to_table
 | 
						|
          end
 | 
						|
        end
 | 
						|
 | 
						|
        it 'yields all possible shifts between the tables' do
 | 
						|
          expect(shifts).to contain_exactly(
 | 
						|
            [Set[:b, :c], Set[:d, :e, :f, :a]],
 | 
						|
            [Set[:c, :a], Set[:d, :e, :f, :b]],
 | 
						|
            [Set[:a, :b], Set[:d, :e, :f, :c]],
 | 
						|
            [Set[:a, :b, :c, :d], Set[:e, :f]],
 | 
						|
            [Set[:a, :b, :c, :e], Set[:d, :f]],
 | 
						|
            [Set[:a, :b, :c, :f], Set[:d, :e]]
 | 
						|
          )
 | 
						|
        end
 | 
						|
      end
 | 
						|
    end
 | 
						|
  end
 | 
						|
end
 |