mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-19 14:00:27 +00:00
Added tests for 8 man double elimination brackets.
This commit is contained in:
@@ -0,0 +1,101 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class DoubleEliminationEightManMatchGeneration < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
create_double_elim_tournament_single_weight_1_6(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Match generation works" do
|
||||||
|
assert @tournament.matches.count == 13
|
||||||
|
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 == "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
|
||||||
|
|
||||||
|
assert match1.wrestler1.bracket_line == 1
|
||||||
|
assert match1.loser2_name == "BYE"
|
||||||
|
|
||||||
|
assert match2.wrestler1.bracket_line == 4
|
||||||
|
assert match2.wrestler2.bracket_line == 5
|
||||||
|
|
||||||
|
assert match3.wrestler1.bracket_line == 3
|
||||||
|
assert match3.wrestler2.bracket_line == 6
|
||||||
|
|
||||||
|
assert match4.wrestler1.bracket_line == 2
|
||||||
|
assert match4.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 == "Semis" and match.bracket_position_number == 1}.first
|
||||||
|
match2 = @tournament.matches.select{|match| match.round == 2 and match.bracket_position == "Semis" and match.bracket_position_number == 2}.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
|
||||||
|
|
||||||
|
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter" && m.bracket_position_number == 1}.first.loser1_name == "BYE"
|
||||||
|
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter" && m.bracket_position_number == 1}.first.loser2_name == "Loser of #{match3.bout_number}"
|
||||||
|
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter" && m.bracket_position_number == 2}.first.loser1_name == "Loser of #{match2.bout_number}"
|
||||||
|
assert @tournament.matches.select{|m| m.bracket_position == "Conso Quarter" && m.bracket_position_number == 2}.first.loser2_name == "BYE"
|
||||||
|
|
||||||
|
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 #{semis1.bout_number}"
|
||||||
|
assert consosemis2.loser1_name == "Loser of #{semis2.bout_number}"
|
||||||
|
|
||||||
|
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}"
|
||||||
|
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 = wrestler.id
|
||||||
|
match2.save
|
||||||
|
|
||||||
|
assert wrestler.reload.placement_points == 3
|
||||||
|
assert wrestler2.reload.placement_points == 3
|
||||||
|
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
|
||||||
67
test/integration/double_elimination_run_through_test.rb
Normal file
67
test/integration/double_elimination_run_through_test.rb
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class DoubleEliminationRunThrough < 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 = "0-0"
|
||||||
|
match.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test "8 man double elimination" do
|
||||||
|
create_double_elim_tournament_single_weight_1_6(6)
|
||||||
|
matches = @tournament.matches.reload
|
||||||
|
|
||||||
|
round1 = matches.select{|m| m.round == 1}
|
||||||
|
winner_by_name("Test4", round1.select{|m| m.bracket_position_number == 2}.first)
|
||||||
|
winner_by_name("Test3", round1.select{|m| m.bracket_position_number == 3}.first)
|
||||||
|
|
||||||
|
semis = matches.select{|m| m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}
|
||||||
|
assert semis.first.reload.wrestler1.name == "Test1"
|
||||||
|
assert semis.first.reload.wrestler2.name == "Test4"
|
||||||
|
assert semis.second.reload.wrestler1.name == "Test3"
|
||||||
|
assert semis.second.reload.wrestler2.name == "Test2"
|
||||||
|
winner_by_name("Test4",semis.first)
|
||||||
|
winner_by_name("Test2",semis.second)
|
||||||
|
|
||||||
|
conso_quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}
|
||||||
|
assert conso_quarter.first.reload.loser1_name == "BYE"
|
||||||
|
assert conso_quarter.first.reload.wrestler2.name == "Test6"
|
||||||
|
assert conso_quarter.second.reload.wrestler1.name == "Test5"
|
||||||
|
assert conso_quarter.second.reload.loser2_name == "BYE"
|
||||||
|
|
||||||
|
conso_semis = matches.select{|m| m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}
|
||||||
|
assert conso_semis.first.reload.wrestler1.name == "Test1"
|
||||||
|
assert conso_semis.first.reload.wrestler2.name == "Test6"
|
||||||
|
assert conso_semis.second.reload.wrestler1.name == "Test3"
|
||||||
|
assert conso_semis.second.reload.wrestler2.name == "Test5"
|
||||||
|
winner_by_name("Test1",conso_semis.first)
|
||||||
|
winner_by_name("Test5",conso_semis.second)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
assert first_finals.reload.wrestler1.name == "Test4"
|
||||||
|
assert first_finals.reload.wrestler2.name == "Test2"
|
||||||
|
|
||||||
|
assert third_finals.reload.wrestler1.name == "Test1"
|
||||||
|
assert third_finals.reload.wrestler2.name == "Test5"
|
||||||
|
|
||||||
|
assert fifth_finals.reload.wrestler1.name == "Test6"
|
||||||
|
assert fifth_finals.reload.wrestler2.name == "Test3"
|
||||||
|
|
||||||
|
# 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
|
||||||
@@ -35,6 +35,41 @@ class ActiveSupport::TestCase
|
|||||||
return @tournament
|
return @tournament
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_double_elim_tournament_single_weight_1_6(number_of_wrestlers)
|
||||||
|
@tournament = Tournament.new
|
||||||
|
@tournament.name = "Test Tournament"
|
||||||
|
@tournament.address = "some place"
|
||||||
|
@tournament.director = "some guy"
|
||||||
|
@tournament.director_email= "test@test.com"
|
||||||
|
@tournament.tournament_type = "Double Elimination 1-6"
|
||||||
|
@tournament.date = "2015-12-30"
|
||||||
|
@tournament.save
|
||||||
|
@school = School.new
|
||||||
|
@school.name = "Test"
|
||||||
|
@school.tournament_id = @tournament.id
|
||||||
|
@school.save
|
||||||
|
@weight = Weight.new
|
||||||
|
@weight.max = 106
|
||||||
|
@weight.tournament_id = @tournament.id
|
||||||
|
@weight.save
|
||||||
|
create_wrestlers_for_weight_for_double_elim(@weight, @school, number_of_wrestlers, 1)
|
||||||
|
GenerateTournamentMatches.new(@tournament).generate
|
||||||
|
return @tournament
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_wrestlers_for_weight_for_double_elim(weight, school, number_of_wrestlers, naming_start_number)
|
||||||
|
naming_number = naming_start_number
|
||||||
|
for number in (1..number_of_wrestlers) do
|
||||||
|
wrestler = Wrestler.new
|
||||||
|
wrestler.name = "Test#{naming_number}"
|
||||||
|
wrestler.school_id = school.id
|
||||||
|
wrestler.weight_id = weight.id
|
||||||
|
wrestler.original_seed = naming_number
|
||||||
|
wrestler.save
|
||||||
|
naming_number = naming_number + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_pool_tournament
|
def create_pool_tournament
|
||||||
@tournament = Tournament.new
|
@tournament = Tournament.new
|
||||||
@tournament.name = "Test Tournament"
|
@tournament.name = "Test Tournament"
|
||||||
|
|||||||
Reference in New Issue
Block a user