Return a valid list of matches for 1 team

This commit is contained in:
Daniel Schädler 2019-04-18 14:19:50 +02:00
parent 38425df823
commit a30ff860e9
2 changed files with 8 additions and 5 deletions

View File

@ -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)

View File

@ -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