1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04: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

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