1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Added logic for 32 man bracket

This commit is contained in:
2024-12-23 22:12:44 -05:00
parent 4f0f69223d
commit 13bb8067fb
8 changed files with 513 additions and 93 deletions

View File

@@ -168,7 +168,7 @@ class Tournament < ApplicationRecord
def double_elim_number_of_wrestlers_error
error_string = ""
if self.tournament_type == "Double Elimination 1-6" or self.tournament_type == "Double Elimination 1-8"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 16}
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 32}
weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 4}
weights_with_too_many_wrestlers.each do |weight|
error_string = error_string + " The weight class #{weight.max} has more than 16 wrestlers."

View File

@@ -15,60 +15,27 @@ class DoubleEliminationGenerateLoserNames
case bracket_size
when 4
[
{
conso_round: @tournament.total_rounds,
conso_bracket_position: "3/4",
championship_round: 1,
championship_bracket_position: "Semis",
cross_bracket: false,
both_wrestlers: true
}
# have to use total rounds here because if other weights have bigger brackets, then the finals round 3/4 won't be round 2
{ conso_round: @tournament.total_rounds, conso_bracket_position: "3/4", championship_round: 1, championship_bracket_position: "Semis", cross_bracket: false, both_wrestlers: true }
]
when 8
[
{
conso_round: 2,
conso_bracket_position: "Conso Quarter",
championship_round: 1,
championship_bracket_position: "Quarter",
cross_bracket: false,
both_wrestlers: true
},
{
conso_round: 3,
conso_bracket_position: "Conso Semis",
championship_round: 2,
championship_bracket_position: "Semis",
cross_bracket: true,
both_wrestlers: false
}
{ conso_round: 2, conso_bracket_position: "Conso Quarter", championship_round: 1, championship_bracket_position: "Quarter", cross_bracket: false, both_wrestlers: true },
{ conso_round: 3, conso_bracket_position: "Conso Semis", championship_round: 2, championship_bracket_position: "Semis", cross_bracket: true, both_wrestlers: false }
]
when 16
[
{
conso_round: 2,
conso_bracket_position: "Conso",
championship_round: 1,
championship_bracket_position: "Bracket",
cross_bracket: false,
both_wrestlers: true
},
{
conso_round: 3,
conso_bracket_position: "Conso",
championship_round: 2,
championship_bracket_position: "Quarter",
cross_bracket: true,
both_wrestlers: false
},
{
conso_round: 5,
conso_bracket_position: "Conso Semis",
championship_round: 4,
championship_bracket_position: "Semis",
cross_bracket: false,
both_wrestlers: false
}
{ conso_round: 2, conso_bracket_position: "Conso", championship_round: 1, championship_bracket_position: "Bracket", cross_bracket: false, both_wrestlers: true },
{ conso_round: 3, conso_bracket_position: "Conso", championship_round: 2, championship_bracket_position: "Quarter", cross_bracket: true, both_wrestlers: false },
{ conso_round: 5, conso_bracket_position: "Conso Semis", championship_round: 4, championship_bracket_position: "Semis", cross_bracket: false, both_wrestlers: false }
]
when 32
[
{ conso_round: 2, conso_bracket_position: "Conso", championship_round: 1, championship_bracket_position: "Bracket", cross_bracket: false, both_wrestlers: true },
{ conso_round: 3, conso_bracket_position: "Conso", championship_round: 2, championship_bracket_position: "Bracket", cross_bracket: true, both_wrestlers: false },
{ conso_round: 5, conso_bracket_position: "Conso", championship_round: 4, championship_bracket_position: "Quarter", cross_bracket: false, both_wrestlers: false },
{ conso_round: 7, conso_bracket_position: "Conso Semis", championship_round: 6, championship_bracket_position: "Semis", cross_bracket: true, both_wrestlers: false },
]
else
nil

View File

@@ -10,38 +10,62 @@ class DoubleEliminationMatchGeneration
end
def define_bracket_matches(bracket_size)
# Use a hash instead of Struct
# Use detailed hashes for rounds, number of matches, and bracket positions
case bracket_size
when 4
{
round_one_matchups: [[1, 4, "Semis"], [2, 3, "Semis"]],
championship_rounds: [[2, 1, "1/2"]],
consolation_rounds: [[2, 1, "3/4"]]
round_one_matchups: [
{ seeds: [1, 4], bracket_position: "Semis" }, { seeds: [2, 3], bracket_position: "Semis" }
],
championship_rounds: [
{ round: 2, number_of_matches: 1, bracket_position: "1/2" }
],
consolation_rounds: [
{ round: 2, number_of_matches: 1, bracket_position: "3/4" }
]
}
when 8
{
round_one_matchups: [
[1, 8, "Quarter"], [4, 5, "Quarter"], [3, 6, "Quarter"], [2, 7, "Quarter"]
{ seeds: [1, 8], bracket_position: "Quarter" }, { seeds: [4, 5], bracket_position: "Quarter" },
{ seeds: [3, 6], bracket_position: "Quarter" }, { seeds: [2, 7], bracket_position: "Quarter" }
],
championship_rounds: [
[2, 2, "Semis"], [4, 1, "1/2"]
{ round: 2, number_of_matches: 2, bracket_position: "Semis" }, { round: 4, number_of_matches: 1, bracket_position: "1/2" }
],
consolation_rounds: [
[2, 2, "Conso Quarter"], [3, 2, "Conso Semis"], [4, 1, "3/4"]
{ round: 2, number_of_matches: 2, bracket_position: "Conso Quarter" }, { round: 3, number_of_matches: 2, bracket_position: "Conso Semis" }, { round: 4, number_of_matches: 1, bracket_position: "3/4" }
]
}
when 16
{
round_one_matchups: [
[1, 16, "Bracket"], [8, 9, "Bracket"], [5, 12, "Bracket"], [4, 13, "Bracket"],
[3, 14, "Bracket"], [6, 11, "Bracket"], [7, 10, "Bracket"], [2, 15, "Bracket"]
{ seeds: [1, 16], bracket_position: "Bracket" }, { seeds: [8, 9], bracket_position: "Bracket" }, { seeds: [5, 12], bracket_position: "Bracket" }, { seeds: [4, 13], bracket_position: "Bracket" },
{ seeds: [3, 14], bracket_position: "Bracket" }, { seeds: [6, 11], bracket_position: "Bracket" },{ seeds: [7, 10], bracket_position: "Bracket" }, { seeds: [2, 15], bracket_position: "Bracket" }
],
championship_rounds: [
[2, 4, "Quarter"], [4, 2, "Semis"], [6, 1, "1/2"]
{ round: 2, number_of_matches: 4, bracket_position: "Quarter" }, { round: 4, number_of_matches: 2, bracket_position: "Semis" }, { round: 6, number_of_matches: 1, bracket_position: "1/2" }
],
consolation_rounds: [
[2, 4, "Conso"], [3, 4, "Conso"], [4, 2, "Conso Quarter"],
[5, 2, "Conso Semis"], [6, 1, "3/4"]
{ round: 2, number_of_matches: 4, bracket_position: "Conso" }, { round: 3, number_of_matches: 4, bracket_position: "Conso" }, { round: 4, number_of_matches: 2, bracket_position: "Conso Quarter" },
{ round: 5, number_of_matches: 2, bracket_position: "Conso Semis" }, { round: 6, number_of_matches: 1, bracket_position: "3/4" }
]
}
when 32
{
round_one_matchups: [
{ seeds: [1, 32], bracket_position: "Bracket" }, { seeds: [16, 17], bracket_position: "Bracket" }, { seeds: [9, 24], bracket_position: "Bracket" }, { seeds: [8, 25], bracket_position: "Bracket" },
{ seeds: [5, 28], bracket_position: "Bracket" }, { seeds: [12, 21], bracket_position: "Bracket" }, { seeds: [13, 20], bracket_position: "Bracket" }, { seeds: [4, 29], bracket_position: "Bracket" },
{ seeds: [3, 30], bracket_position: "Bracket" }, { seeds: [14, 19], bracket_position: "Bracket" }, { seeds: [11, 22], bracket_position: "Bracket" }, { seeds: [6, 27], bracket_position: "Bracket" },
{ seeds: [7, 26], bracket_position: "Bracket" }, { seeds: [10, 23], bracket_position: "Bracket" }, { seeds: [15, 18], bracket_position: "Bracket" }, { seeds: [2, 31], bracket_position: "Bracket" }
],
championship_rounds: [
{ round: 2, number_of_matches: 8, bracket_position: "Bracket" }, { round: 4, number_of_matches: 4, bracket_position: "Quarter" },
{ round: 6, number_of_matches: 2, bracket_position: "Semis" }, { round: 8, number_of_matches: 1, bracket_position: "1/2" }
],
consolation_rounds: [
{ round: 2, number_of_matches: 8, bracket_position: "Conso" }, { round: 3, number_of_matches: 8, bracket_position: "Conso" }, { round: 4, number_of_matches: 4, bracket_position: "Conso" }, { round: 5, number_of_matches: 4, bracket_position: "Conso" },
{ round: 6, number_of_matches: 2, bracket_position: "Conso Quarter" }, { round: 7, number_of_matches: 2, bracket_position: "Conso Semis" }, { round: 8, number_of_matches: 1, bracket_position: "3/4" }
]
}
else
@@ -53,44 +77,43 @@ class DoubleEliminationMatchGeneration
number_of_placers = @tournament.number_of_placers
bracket_size = weight.calculate_bracket_size
bracket_matches = define_bracket_matches(bracket_size)
# Generate round 1 matches
bracket_matches[:round_one_matchups].each_with_index do |matchup, index|
matches_this_round = bracket_matches[:round_one_matchups].size
bracket_position = matchup[2]
create_matchup_from_seed(
matchup[0],
matchup[1],
bracket_position,
index + 1,
1,
weight
)
seed_1 = matchup[:seeds][0]
seed_2 = matchup[:seeds][1]
bracket_position = matchup[:bracket_position]
round = 1
bracket_position_number = index + 1
create_matchup_from_seed(seed_1, seed_2, bracket_position, bracket_position_number, round, weight)
end
# Generate remaining championship rounds
bracket_matches[:championship_rounds].each do |matchup|
round = matchup[0]
matches_this_round = matchup[1]
bracket_position = matchup[2]
bracket_matches[:championship_rounds].each do |round_info|
round = round_info[:round]
matches_this_round = round_info[:number_of_matches]
bracket_position = round_info[:bracket_position]
matches_this_round.times do |bracket_position_number|
create_matchup(nil, nil, bracket_position, bracket_position_number + 1, round, weight)
end
end
# Generate consolation matches
bracket_matches[:consolation_rounds].each do |matchup|
round = matchup[0]
matches_this_round = matchup[1]
bracket_position = matchup[2]
bracket_matches[:consolation_rounds].each do |round_info|
round = round_info[:round]
matches_this_round = round_info[:number_of_matches]
bracket_position = round_info[:bracket_position]
matches_this_round.times do |bracket_position_number|
create_matchup(nil, nil, bracket_position, bracket_position_number + 1, round, weight)
end
if weight.wrestlers.size >= 5
create_matchup(nil, nil, "5/6", 1, round, weight) if @tournament.number_of_placers >= 6 && matches_this_round == 1
end
if weight.wrestlers.size >= 7
create_matchup(nil, nil, "7/8", 1, round, weight) if @tournament.number_of_placers >= 8 && matches_this_round == 1
end

View File

@@ -8,7 +8,7 @@
<li>Tournament Types
<ul>
<li>Pool to bracket (adhears to 5 match per day rule)</li>
<li>Regular Double Elimination 16 man and 8 man. Options for placing 1st-6th or 1st-8th.</li>
<li>Regular Double Elimination 32 man, 16 man, and 8 man. Options for placing 1st-6th or 1st-8th.</li>
<li>Modified 16 Man Double Elimination 1-6. Options for placing 1st-6th or 1st-8th. Adhears to 5 match per day rule.</li>
</ul>
</li>
@@ -62,7 +62,7 @@
</ul>
<br>
<h3>Regular Double Elimination Information</h3>
<p>Right now, double elimination brackets only support 8 and 16 man brackets (4-16 wrestlers). Cross bracketing will happen every other round. 16 man in quarter finals, 8 man in semi finals.</p>
<p>Right now, double elimination brackets only support 8, 16, and 32 man brackets (4-32 wrestlers). Cross bracketing will happen every other round. 16 man in quarter finals, 8 man in semi finals.</p>
<p>Regular Double Elimination 1-6 places 1st through 6th. Regular Double Elimination 1-8 places 1st through 8th.</p>
<h4>Regular Double Elimination scoring</h4>
<ul>

View File

@@ -87,17 +87,19 @@
# Regular Double Elimination 1-6
tournament = Tournament.create(id: 203, name: 'Regular Double Elimination 1-6', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Regular Double Elimination 1-6', user_id: 1, date: Date.today, is_public: true)
create_schools(tournament, 16)
create_schools(tournament, 32)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each_with_index do |weight, index|
if index == 0
number_of_wrestlers = 4
number_of_wrestlers = 4
elsif index == 1
number_of_wrestlers = 8
number_of_wrestlers = 8
elsif index == 2
number_of_wrestlers = 32
else
number_of_wrestlers = 16
number_of_wrestlers = 16
end
create_wrestlers_for_weight(weight, tournament, number_of_wrestlers, wrestler_name_number)
@@ -106,7 +108,7 @@
# Regular Double Elimination 1-8
tournament = Tournament.create(id: 204, name: 'Regular Double Elimination 1-8', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Regular Double Elimination 1-8', user_id: 1, date: Date.today, is_public: true)
create_schools(tournament, 16)
create_schools(tournament, 32)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
@@ -115,6 +117,8 @@
number_of_wrestlers = 4
elsif index == 1
number_of_wrestlers = 8
elsif index == 2
number_of_wrestlers = 32
else
number_of_wrestlers = 16
end

View File

@@ -0,0 +1,225 @@
require 'test_helper'
class DoubleEliminationThirtyTwoManEightPlacesMatchGeneration < ActionDispatch::IntegrationTest
def setup
create_double_elim_tournament_single_weight(30, "Regular Double Elimination 1-8")
end
test "Match generation works" do
assert @tournament.matches.count == 62
assert @tournament.matches.select{|m| m.bracket_position == "Bracket" and m.round == 1}.count == 16
assert @tournament.matches.select{|m| m.bracket_position == "Bracket" and m.round == 2}.count == 8
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2}.count == 8
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3}.count == 8
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 4}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 5}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "1/2"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "3/4"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "5/6"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "7/8"}.count == 1
assert @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Semis"}.count == 2
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter"}.count == 2
assert @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.count == 2
end
test "Seeded wrestlers have correct first line" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 2}.first
match3 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 3}.first
match4 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 4}.first
match5 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 5}.first
match6 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 6}.first
match7 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 7}.first
match8 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 8}.first
match9 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 9}.first
match10 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 10}.first
match11 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 11}.first
match12 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 12}.first
match13 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 13}.first
match14 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 14}.first
match15 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 15}.first
match16 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 16}.first
assert match1.wrestler1.bracket_line == 1
assert match1.loser2_name == "BYE"
assert match2.wrestler1.bracket_line == 16
assert match2.wrestler2.bracket_line == 17
assert match3.wrestler1.bracket_line == 9
assert match3.wrestler2.bracket_line == 24
assert match4.wrestler1.bracket_line == 8
assert match4.wrestler2.bracket_line == 25
assert match5.wrestler1.bracket_line == 5
assert match5.wrestler2.bracket_line == 28
assert match6.wrestler1.bracket_line == 12
assert match6.wrestler2.bracket_line == 21
assert match7.wrestler1.bracket_line == 13
assert match7.wrestler2.bracket_line == 20
assert match8.wrestler1.bracket_line == 4
assert match8.wrestler2.bracket_line == 29
assert match9.wrestler1.bracket_line == 3
assert match9.wrestler2.bracket_line == 30
assert match10.wrestler1.bracket_line == 14
assert match10.wrestler2.bracket_line == 19
assert match11.wrestler1.bracket_line == 11
assert match11.wrestler2.bracket_line == 22
assert match12.wrestler1.bracket_line == 6
assert match12.wrestler2.bracket_line == 27
assert match13.wrestler1.bracket_line == 7
assert match13.wrestler2.bracket_line == 26
assert match14.wrestler1.bracket_line == 10
assert match14.wrestler2.bracket_line == 23
assert match15.wrestler1.bracket_line == 15
assert match15.wrestler2.bracket_line == 18
assert match16.wrestler1.bracket_line == 2
assert match16.loser2_name == "BYE"
end
test "Byes are advanced correctly" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 8}.first
assert match1.wrestler1.name == "Test1"
assert match2.wrestler2.name == "Test2"
end
test "Loser names set up correctly" do
@tournament.matches.reload
match1 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 1}.first
match2 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 2}.first
match3 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 3}.first
match4 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 4}.first
match5 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 5}.first
match6 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 6}.first
match7 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 7}.first
match8 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 8}.first
match9 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 9}.first
match10 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 10}.first
match11 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 11}.first
match12 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 12}.first
match13 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 13}.first
match14 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 14}.first
match15 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 15}.first
match16 = @tournament.matches.select{|match| match.round == 1 and match.bracket_position_number == 16}.first
# Conso round 2
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 1}.first.loser1_name == "BYE"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{match2.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 2}.first.loser1_name == "Loser of #{match3.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 2}.first.loser2_name == "Loser of #{match4.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 3}.first.loser1_name == "Loser of #{match5.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 3}.first.loser2_name == "Loser of #{match6.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 4}.first.loser1_name == "Loser of #{match7.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 4}.first.loser2_name == "Loser of #{match8.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 5}.first.loser1_name == "Loser of #{match9.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 5}.first.loser2_name == "Loser of #{match10.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 6}.first.loser1_name == "Loser of #{match11.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 6}.first.loser2_name == "Loser of #{match12.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 7}.first.loser1_name == "Loser of #{match13.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 7}.first.loser2_name == "Loser of #{match14.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 8}.first.loser1_name == "Loser of #{match15.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 2 && m.bracket_position_number == 8}.first.loser2_name == "BYE"
# Conso round 3
round2_match1 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 1}.first
round2_match2 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 2}.first
round2_match3 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 3}.first
round2_match4 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 4}.first
round2_match5 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 5}.first
round2_match6 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 6}.first
round2_match7 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 7}.first
round2_match8 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Bracket" and match.bracket_position_number == 8}.first
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 1}.first.loser1_name == "Loser of #{round2_match8.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 2}.first.loser1_name == "Loser of #{round2_match7.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 3}.first.loser1_name == "Loser of #{round2_match6.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 4}.first.loser1_name == "Loser of #{round2_match5.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 5}.first.loser1_name == "Loser of #{round2_match4.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 6}.first.loser1_name == "Loser of #{round2_match3.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 7}.first.loser1_name == "Loser of #{round2_match2.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "Conso" and m.round == 3 && m.bracket_position_number == 8}.first.loser1_name == "Loser of #{round2_match1.bout_number}"
# Conso Quarter round 5
quarter1 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 1}.first
quarter2 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 2}.first
quarter3 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 3}.first
quarter4 = @tournament.matches.select{|match| match.bracket_position == "Quarter" and match.bracket_position_number == 4}.first
consoround2match1 = @tournament.matches.select{|match| match.bracket_position == "Conso" and match.round == 5 && match.bracket_position_number == 1}.first
consoround2match2 = @tournament.matches.select{|match| match.bracket_position == "Conso" and match.round == 5 && match.bracket_position_number == 2}.first
consoround2match3 = @tournament.matches.select{|match| match.bracket_position == "Conso" and match.round == 5 && match.bracket_position_number == 3}.first
consoround2match4 = @tournament.matches.select{|match| match.bracket_position == "Conso" and match.round == 5 && match.bracket_position_number == 4}.first
assert consoround2match1.loser1_name == "Loser of #{quarter1.bout_number}"
assert consoround2match2.loser1_name == "Loser of #{quarter2.bout_number}"
assert consoround2match3.loser1_name == "Loser of #{quarter3.bout_number}"
assert consoround2match4.loser1_name == "Loser of #{quarter4.bout_number}"
# Conso Semis round 7
semis1 = @tournament.matches.select{|match| match.bracket_position == "Semis" and match.bracket_position_number == 1}.first
semis2 = @tournament.matches.select{|match| match.bracket_position == "Semis" and match.bracket_position_number == 2}.first
consosemis1 = @tournament.matches.select{|match| match.bracket_position == "Conso Semis" and match.bracket_position_number == 1}.first
consosemis2 = @tournament.matches.select{|match| match.bracket_position == "Conso Semis" and match.bracket_position_number == 2}.first
assert consosemis1.loser1_name == "Loser of #{semis2.bout_number}"
assert consosemis2.loser1_name == "Loser of #{semis1.bout_number}"
# 5/6
assert @tournament.matches.select{|m| m.bracket_position == "5/6" && m.bracket_position_number == 1}.first.loser1_name == "Loser of #{consosemis1.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "5/6" && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{consosemis2.bout_number}"
# 7/8
consoquarters1 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.bracket_position_number == 1}.first
consoquarters2 = @tournament.matches.select{|match| match.bracket_position == "Conso Quarter" and match.bracket_position_number == 2}.first
assert @tournament.matches.select{|m| m.bracket_position == "7/8" && m.bracket_position_number == 1}.first.loser1_name == "Loser of #{consoquarters1.bout_number}"
assert @tournament.matches.select{|m| m.bracket_position == "7/8" && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{consoquarters2.bout_number}"
end
test "Placement points are given when moving through bracket" do
match = @tournament.matches.select{|m| m.bracket_position == "Semis"}.first
wrestler = get_wrestler_by_name("Test1")
match.w1 = wrestler.id
match.save
match2 = @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.first
wrestler2 = get_wrestler_by_name("Test2")
match2.w1 = wrestler2.id
match2.save
match3 = @tournament.matches.select{|m| m.bracket_position == "Conso Quarter"}.first
wrestler3 = get_wrestler_by_name("Test3")
match3.w1 = wrestler3.id
match3.save
assert wrestler.reload.placement_points == 3
assert wrestler2.reload.placement_points == 3
assert wrestler3.reload.placement_points == 1
end
test "Run through all matches works" do
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
match.reload
if match.finished != 1 and match.w1 and match.w2
match.winner_id = match.w1
match.win_type = "Decision"
match.score = "0-0"
match.finished = 1
match.save
end
end
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
end
end

View File

@@ -0,0 +1,201 @@
require 'test_helper'
class DoubleEliminationThirtyTwoManEightPlacesRunThrough < ActionDispatch::IntegrationTest
def setup
end
def winner_by_name(winner_name,match)
wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first
match.winner_id = wrestler.id
match.finished = 1
match.win_type = "Decision"
match.score = "1-0"
match.save
end
test "16 man double elimination place 1-8" do
create_double_elim_tournament_single_weight(30, "Regular Double Elimination 1-8")
matches = @tournament.matches.reload
round1 = matches.select{|m| m.round == 1}
winner_by_name("Test17", round1.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test9", round1.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test25", round1.select{|m| m.bracket_position_number == 4}.first)
winner_by_name("Test5", round1.select{|m| m.bracket_position_number == 5}.first)
winner_by_name("Test12", round1.select{|m| m.bracket_position_number == 6}.first)
winner_by_name("Test20", round1.select{|m| m.bracket_position_number == 7}.first)
winner_by_name("Test4", round1.select{|m| m.bracket_position_number == 8}.first)
winner_by_name("Test3", round1.select{|m| m.bracket_position_number == 9}.first)
winner_by_name("Test14", round1.select{|m| m.bracket_position_number == 10}.first)
winner_by_name("Test11", round1.select{|m| m.bracket_position_number == 11}.first)
winner_by_name("Test6", round1.select{|m| m.bracket_position_number == 12}.first)
winner_by_name("Test7", round1.select{|m| m.bracket_position_number == 13}.first)
winner_by_name("Test10", round1.select{|m| m.bracket_position_number == 14}.first)
winner_by_name("Test18", round1.select{|m| m.bracket_position_number == 15}.first)
round2_championship = matches.reload.select{|m| m.bracket_position == "Bracket" and m.round == 2}.sort_by{|m| m.bracket_position_number}
assert round2_championship.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test1"
assert round2_championship.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test17"
assert round2_championship.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test9"
assert round2_championship.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test25"
assert round2_championship.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test5"
assert round2_championship.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test12"
assert round2_championship.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test20"
assert round2_championship.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test4"
assert round2_championship.select{|m| m.bracket_position_number == 5}.first.reload.wrestler1.name == "Test3"
assert round2_championship.select{|m| m.bracket_position_number == 5}.first.reload.wrestler2.name == "Test14"
assert round2_championship.select{|m| m.bracket_position_number == 6}.first.reload.wrestler1.name == "Test11"
assert round2_championship.select{|m| m.bracket_position_number == 6}.first.reload.wrestler2.name == "Test6"
assert round2_championship.select{|m| m.bracket_position_number == 7}.first.reload.wrestler1.name == "Test7"
assert round2_championship.select{|m| m.bracket_position_number == 7}.first.reload.wrestler2.name == "Test10"
assert round2_championship.select{|m| m.bracket_position_number == 8}.first.reload.wrestler1.name == "Test18"
assert round2_championship.select{|m| m.bracket_position_number == 8}.first.reload.wrestler2.name == "Test2"
winner_by_name("Test1", round2_championship.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test25", round2_championship.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test5", round2_championship.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test4", round2_championship.select{|m| m.bracket_position_number == 4}.first)
winner_by_name("Test3", round2_championship.select{|m| m.bracket_position_number == 5}.first)
winner_by_name("Test11", round2_championship.select{|m| m.bracket_position_number == 6}.first)
winner_by_name("Test10", round2_championship.select{|m| m.bracket_position_number == 7}.first)
winner_by_name("Test2", round2_championship.select{|m| m.bracket_position_number == 8}.first)
round2_conso = matches.reload.select{|m| m.bracket_position == "Conso" and m.round == 2}.sort_by{|m| m.bracket_position_number}
assert round2_conso.select{|m| m.bracket_position_number == 1}.first.reload.loser1_name == "BYE"
assert round2_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test16"
assert round2_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test24"
assert round2_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test8"
assert round2_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test28"
assert round2_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test21"
assert round2_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test13"
assert round2_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test29"
assert round2_conso.select{|m| m.bracket_position_number == 5}.first.reload.wrestler1.name == "Test30"
assert round2_conso.select{|m| m.bracket_position_number == 5}.first.reload.wrestler2.name == "Test19"
assert round2_conso.select{|m| m.bracket_position_number == 6}.first.reload.wrestler1.name == "Test22"
assert round2_conso.select{|m| m.bracket_position_number == 6}.first.reload.wrestler2.name == "Test27"
assert round2_conso.select{|m| m.bracket_position_number == 7}.first.reload.wrestler1.name == "Test26"
assert round2_conso.select{|m| m.bracket_position_number == 7}.first.reload.wrestler2.name == "Test23"
assert round2_conso.select{|m| m.bracket_position_number == 8}.first.reload.wrestler1.name == "Test15"
assert round2_conso.select{|m| m.bracket_position_number == 8}.first.reload.loser2_name == "BYE"
winner_by_name("Test8", round2_conso.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test21", round2_conso.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test29", round2_conso.select{|m| m.bracket_position_number == 4}.first)
winner_by_name("Test19", round2_conso.select{|m| m.bracket_position_number == 5}.first)
winner_by_name("Test22", round2_conso.select{|m| m.bracket_position_number == 6}.first)
winner_by_name("Test23", round2_conso.select{|m| m.bracket_position_number == 7}.first)
round3_conso = matches.reload.select{|m| m.bracket_position == "Conso" and m.round == 3}.sort_by{|m| m.bracket_position_number}
assert round3_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test18"
assert round3_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test16"
assert round3_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test7"
assert round3_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test8"
assert round3_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test6"
assert round3_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test21"
assert round3_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test14"
assert round3_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test29"
assert round3_conso.select{|m| m.bracket_position_number == 5}.first.reload.wrestler1.name == "Test20"
assert round3_conso.select{|m| m.bracket_position_number == 5}.first.reload.wrestler2.name == "Test19"
assert round3_conso.select{|m| m.bracket_position_number == 6}.first.reload.wrestler1.name == "Test12"
assert round3_conso.select{|m| m.bracket_position_number == 6}.first.reload.wrestler2.name == "Test22"
assert round3_conso.select{|m| m.bracket_position_number == 7}.first.reload.wrestler1.name == "Test9"
assert round3_conso.select{|m| m.bracket_position_number == 7}.first.reload.wrestler2.name == "Test23"
assert round3_conso.select{|m| m.bracket_position_number == 8}.first.reload.wrestler1.name == "Test17"
assert round3_conso.select{|m| m.bracket_position_number == 8}.first.reload.wrestler2.name == "Test15"
winner_by_name("Test16", round3_conso.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test8", round3_conso.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test6", round3_conso.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test29", round3_conso.select{|m| m.bracket_position_number == 4}.first)
winner_by_name("Test20", round3_conso.select{|m| m.bracket_position_number == 5}.first)
winner_by_name("Test12", round3_conso.select{|m| m.bracket_position_number == 6}.first)
winner_by_name("Test23", round3_conso.select{|m| m.bracket_position_number == 7}.first)
winner_by_name("Test17", round3_conso.select{|m| m.bracket_position_number == 8}.first)
round4_conso = matches.reload.select{|m| m.bracket_position == "Conso" and m.round == 4}.sort_by{|m| m.bracket_position_number}
assert round4_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test16"
assert round4_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test8"
assert round4_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test6"
assert round4_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test29"
assert round4_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test20"
assert round4_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test12"
assert round4_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test23"
assert round4_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test17"
winner_by_name("Test8", round4_conso.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test6", round4_conso.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test20", round4_conso.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test17", round4_conso.select{|m| m.bracket_position_number == 4}.first)
quarters = matches.reload.select{|m| m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}
assert quarters.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test1"
assert quarters.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test25"
assert quarters.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test5"
assert quarters.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test4"
assert quarters.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test3"
assert quarters.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test11"
assert quarters.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test10"
assert quarters.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test2"
winner_by_name("Test1", quarters.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test5", quarters.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test11", quarters.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test2", quarters.select{|m| m.bracket_position_number == 4}.first)
round5_conso = matches.reload.select{|m| m.bracket_position == "Conso" and m.round == 5}.sort_by{|m| m.bracket_position_number}
assert round5_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test25"
assert round5_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test8"
assert round5_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test4"
assert round5_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test6"
assert round5_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test3"
assert round5_conso.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test20"
assert round5_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test10"
assert round5_conso.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test17"
winner_by_name("Test8", round5_conso.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test6", round5_conso.select{|m| m.bracket_position_number == 2}.first)
winner_by_name("Test3", round5_conso.select{|m| m.bracket_position_number == 3}.first)
winner_by_name("Test10", round5_conso.select{|m| m.bracket_position_number == 4}.first)
quarters_conso = matches.reload.select{|m| m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}
assert quarters_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test8"
assert quarters_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test6"
assert quarters_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test3"
assert quarters_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test10"
winner_by_name("Test8", quarters_conso.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test3", quarters_conso.select{|m| m.bracket_position_number == 2}.first)
semis = matches.reload.select{|m| m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}
assert semis.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test1"
assert semis.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test5"
assert semis.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test11"
assert semis.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test2"
winner_by_name("Test5", semis.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test2", semis.select{|m| m.bracket_position_number == 2}.first)
semis_conso = matches.reload.select{|m| m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}
assert semis_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test11"
assert semis_conso.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test8"
assert semis_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test1"
assert semis_conso.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test3"
winner_by_name("Test11", semis_conso.select{|m| m.bracket_position_number == 1}.first)
winner_by_name("Test3", semis_conso.select{|m| m.bracket_position_number == 2}.first)
first_finals = matches.select{|m| m.bracket_position == "1/2"}.first
third_finals = matches.select{|m| m.bracket_position == "3/4"}.first
fifth_finals = matches.select{|m| m.bracket_position == "5/6"}.first
seventh_finals = matches.select{|m| m.bracket_position == "7/8"}.first
assert first_finals.reload.wrestler1.name == "Test5"
assert first_finals.reload.wrestler2.name == "Test2"
assert third_finals.reload.wrestler1.name == "Test11"
assert third_finals.reload.wrestler2.name == "Test3"
assert fifth_finals.reload.wrestler1.name == "Test8"
assert fifth_finals.reload.wrestler2.name == "Test1"
assert seventh_finals.reload.wrestler1.name == "Test6"
assert seventh_finals.reload.wrestler2.name == "Test10"
# DEBUG
# matches.sort_by{|m| m.bout_number}.each do |match|
# match.reload
# puts "Round #{match.round} #{match.w1_bracket_name} vs #{match.w2_bracket_name}"
# end
end
end

View File

@@ -69,8 +69,8 @@ class TournamentTest < ActiveSupport::TestCase
assert @tournament.match_generation_error != nil
end
test "Tournament Double Elimination 1-8 match generation errors with more than 16 wrestlers" do
number_of_wrestlers=17
test "Tournament Double Elimination 1-8 match generation errors with more than 32 wrestlers" do
number_of_wrestlers=33
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end