Correct position for :single_team matches
This commit is contained in:
parent
36db03293e
commit
5f378f27b2
|
|
@ -45,12 +45,14 @@ class MatchService
|
||||||
end
|
end
|
||||||
|
|
||||||
# the start point is to compensate for all the teams that are already within a "normal" match
|
# the start point is to compensate for all the teams that are already within a "normal" match
|
||||||
startpoint = matches.size
|
i = team_offset = matches.size
|
||||||
until matches.size >= needed_games
|
until matches.size >= needed_games
|
||||||
# while we do not have enough matches in general we need to fill the array with "single team" matches
|
# while we do not have enough matches in general we need to fill the array with "single team" matches
|
||||||
i = matches.size + startpoint
|
match = Match.new state: :single_team,
|
||||||
match = Match.new state: :single_team, position: i, match_scores: [MatchScore.create(team: teams[i])]
|
position: i,
|
||||||
|
match_scores: [MatchScore.create(team: teams[i + team_offset])]
|
||||||
matches << match
|
matches << match
|
||||||
|
i += 1
|
||||||
end
|
end
|
||||||
matches
|
matches
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -117,5 +117,16 @@ RSpec.describe MatchService do
|
||||||
it 'raises an exception for for 0 teams' do
|
it 'raises an exception for for 0 teams' do
|
||||||
expect { MatchService.generate_matches([]) }. to raise_error 'Cannot generate Matches without teams'
|
expect { MatchService.generate_matches([]) }. to raise_error 'Cannot generate Matches without teams'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'generates matches with consecutive positions' do
|
||||||
|
MatchService.generate_matches(create_list(:team, 7)).sort_by(&:position).each_with_index do |match, i|
|
||||||
|
expect(match.position).to eq(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'places all given teams into the matches exactly once' do
|
||||||
|
teams = create_list(:team, 11)
|
||||||
|
expect(MatchService.generate_matches(teams).map(&:teams).flatten).to match_array(teams)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue