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
|
# @param teams [Array] the teams to generate matches with
|
||||||
# @return [Array] the generated matches
|
# @return [Array] the generated matches
|
||||||
def self.generate_matches(teams)
|
def self.generate_matches(teams)
|
||||||
if teams.size < 2
|
if teams.empty?
|
||||||
# should be prevented by controller
|
# should be prevented by controller
|
||||||
return
|
return
|
||||||
end
|
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
|
# normal_games = number of matches with two teams attending
|
||||||
# needed_games = number of matches to generate in total for the given number of teams
|
# needed_games = number of matches to generate in total for the given number of teams
|
||||||
if Utils.po2?(teams.size)
|
if Utils.po2?(teams.size)
|
||||||
|
|
|
||||||
|
|
@ -117,9 +117,5 @@ RSpec.describe MatchService do
|
||||||
it 'generates no matches for 0 teams' do
|
it 'generates no matches for 0 teams' do
|
||||||
expect(MatchService.generate_matches([])). to eq(nil)
|
expect(MatchService.generate_matches([])). to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'generates no matches for 1 team' do
|
|
||||||
expect(MatchService.generate_matches(build_list(:team, 1))). to eq(nil)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue