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