Return a valid list of matches for 1 team
This commit is contained in:
parent
38425df823
commit
a30ff860e9
|
|
@ -6,11 +6,18 @@ class MatchService
|
|||
# @param teams [Array] the teams to generate matches with
|
||||
# @return [Array] the generated matches
|
||||
def self.generate_matches(teams)
|
||||
if teams.size < 2
|
||||
if teams.empty?
|
||||
# should be prevented by controller
|
||||
return
|
||||
end
|
||||
|
||||
if teams.size == 1
|
||||
matches = []
|
||||
match = Match.new state: :single_team, position: 1, match_scores: [MatchScore.create(team: teams.first)]
|
||||
matches << match
|
||||
return matches
|
||||
end
|
||||
|
||||
# normal_games = number of matches with two teams attending
|
||||
# needed_games = number of matches to generate in total for the given number of teams
|
||||
if Utils.po2?(teams.size)
|
||||
|
|
|
|||
|
|
@ -117,9 +117,5 @@ RSpec.describe MatchService do
|
|||
it 'generates no matches for 0 teams' do
|
||||
expect(MatchService.generate_matches([])). to eq(nil)
|
||||
end
|
||||
|
||||
it 'generates no matches for 1 team' do
|
||||
expect(MatchService.generate_matches(build_list(:team, 1))). to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue