Generate a valid tournament like at bpwstr
This commit is contained in:
parent
bb61d514a0
commit
a74236982d
|
|
@ -7,13 +7,23 @@ FactoryBot.define do
|
|||
user
|
||||
transient do
|
||||
teams_count { 8 }
|
||||
teams { nil }
|
||||
playoff_teams_amount { 4 }
|
||||
instant_finalists_amount { 4 }
|
||||
intermediate_round_participants_amount { 0 }
|
||||
end
|
||||
after(:create) do |tournament, evaluator|
|
||||
tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament)
|
||||
tournament.playoff_teams_amount = (tournament.teams.size / 2)
|
||||
tournament.instant_finalists_amount = (tournament.playoff_teams_amount / 2)
|
||||
tournament.intermediate_round_participants_amount = ((tournament.playoff_teams_amount -
|
||||
tournament.instant_finalists_amount) * 2)
|
||||
if evaluator.teams.present?
|
||||
tournament.teams = evaluator.teams
|
||||
else
|
||||
tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament)
|
||||
end
|
||||
tournament.playoff_teams_amount = evaluator.playoff_teams_amount
|
||||
tournament.instant_finalists_amount = evaluator.instant_finalists_amount
|
||||
tournament.intermediate_round_participants_amount = evaluator.intermediate_round_participants_amount
|
||||
if tournament.playoff_teams_amount != tournament.instant_finalists_amount + tournament.intermediate_round_participants_amount / 2
|
||||
raise 'playoff_teams_amount must be equal to instant_finalists_amount + intermediate_round_participants_amount / 2'
|
||||
end
|
||||
tournament.save!
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -200,9 +200,9 @@ RSpec.describe GroupStageService do
|
|||
groups = teams.each_slice(4).to_a
|
||||
|
||||
# iterate over all groups and number the teams in their name
|
||||
groups.each do |group|
|
||||
group.each_with_index do |team, i|
|
||||
team.name = "#{team.name} #{i}"
|
||||
groups.each_with_index do |group, group_index|
|
||||
group.each_with_index do |team, team_index|
|
||||
team.name = "#{team.name} #{group_index} #{team_index}"
|
||||
team.save!
|
||||
end
|
||||
end
|
||||
|
|
@ -210,8 +210,12 @@ RSpec.describe GroupStageService do
|
|||
# Generate the group stage
|
||||
@group_stage = GroupStageService.generate_group_stage(groups)
|
||||
|
||||
@tournament = create(:prepared_group_stage_tournament, group_stage: @group_stage)
|
||||
|
||||
@tournament = create(:prepared_group_stage_tournament,
|
||||
group_stage: @group_stage,
|
||||
teams: teams,
|
||||
playoff_teams_amount: 16,
|
||||
instant_finalists_amount: 16,
|
||||
intermediate_round_participants_amount: 0)
|
||||
# iterate over all groups and update the matches within to all be decided
|
||||
@group_stage.groups.each do |group|
|
||||
group.matches.each do |match|
|
||||
|
|
|
|||
Loading…
Reference in New Issue