diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 2b3d3da..77d8e7b 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -8,10 +8,9 @@ class StaticPagesController < ApplicationController @tournament = Tournament.find(params[:tournament]) end if @tournament - if @tournament.matches.empty? + @matches = @tournament.matches + if @matches.empty? redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}" - else - @matches = @tournament.upcomingMatches end end end @@ -30,12 +29,12 @@ class StaticPagesController < ApplicationController if params[:tournament] @tournament = Tournament.find(params[:tournament]) end - if @tournament - @matches = Match.where(tournament_id: @tournament.id) - end + if @tournament + @matches = @tournament.matches + end @matches = @matches.where(finished: 1) - end + def brackets if params[:weight] @weight = Weight.find(params[:weight]) @@ -50,7 +49,7 @@ class StaticPagesController < ApplicationController end end end - + def all_brackets if params[:tournament] @tournament = Tournament.find(params[:tournament]) @@ -85,7 +84,7 @@ class StaticPagesController < ApplicationController @tournament = Tournament.find(params[:tournament]) end end - + def generate_matches if !user_signed_in? redirect_to root_path diff --git a/app/models/boutgen.rb b/app/models/boutgen.rb deleted file mode 100644 index 12a0176..0000000 --- a/app/models/boutgen.rb +++ /dev/null @@ -1,27 +0,0 @@ -class Boutgen - def matchesByRound(round, matches) - @matches = matches.select {|m| m.round == round} - return @matches - end - - def giveBout(matches) - @matches = matches.sort_by{|x|[x.weight_max]} - @matches.each_with_index do |m, i| - @bout = m.round * 1000 + i - m.bout_number = @bout - end - return @matches - end - - def assignBouts(matches,weights) - @round = 1 - until matchesByRound(@round, matches).blank? do - @matches = matchesByRound(@round, matches) - giveBout(@matches) - @round += 1 - end - return matches - end - - -end \ No newline at end of file diff --git a/app/models/generates_loser_names.rb b/app/models/generates_loser_names.rb new file mode 100644 index 0000000..7ac2d30 --- /dev/null +++ b/app/models/generates_loser_names.rb @@ -0,0 +1,57 @@ +module GeneratesLoserNames + def assignLoserNames + matches_by_weight = nil + weights.each do |w| + matches_by_weight = matches.where(weight_id: w.id) + if w.pool_bracket_type == "twoPoolsToSemi" + twoPoolsToSemiLoser(matches_by_weight) + elsif w.pool_bracket_type == "fourPoolsToQuarter" + fourPoolsToQuarterLoser(matches_by_weight) + elsif w.pool_bracket_type == "fourPoolsToSemi" + fourPoolsToSemiLoser(matches_by_weight) + end + end + return matches_by_weight + end + + def twoPoolsToSemiLoser(matches_by_weight) + match1 = matches_by_weight.select{|m| m.loser1_name == "Winner Pool 1"}.first + match2 = matches_by_weight.select{|m| m.loser1_name == "Winner Pool 2"}.first + matchChange = matches_by_weight.select{|m| m.bracket_position == "3/4"}.first + matchChange.loser1_name = "Loser of #{match1.bout_number}" + matchChange.loser2_name = "Loser of #{match2.bout_number}" + end + + def fourPoolsToQuarterLoser(matches_by_weight) + quarters = matches_by_weight.select{|m| m.bracket_position == "Quarter"} + consoSemis = matches_by_weight.select{|m| m.bracket_position == "Conso Semis"} + semis = matches_by_weight.select{|m| m.bracket_position == "Semis"} + thirdFourth = matches_by_weight.select{|m| m.bracket_position == "3/4"}.first + seventhEighth = matches_by_weight.select{|m| m.bracket_position == "7/8"}.first + consoSemis.each do |m| + if m.bracket_position_number == 1 + m.loser1_name = "Loser of #{quarters.select{|m| m.bracket_position_number == 1}.first.bout_number}" + m.loser2_name = "Loser of #{quarters.select{|m| m.bracket_position_number == 2}.first.bout_number}" + elsif m.bracket_position_number == 2 + m.loser1_name = "Loser of #{quarters.select{|m| m.bracket_position_number == 3}.first.bout_number}" + m.loser2_name = "Loser of #{quarters.select{|m| m.bracket_position_number == 4}.first.bout_number}" + end + end + thirdFourth.loser1_name = "Loser of #{semis.select{|m| m.bracket_position_number == 1}.first.bout_number}" + thirdFourth.loser2_name = "Loser of #{semis.select{|m| m.bracket_position_number == 2}.first.bout_number}" + consoSemis = matches_by_weight.select{|m| m.bracket_position == "Conso Semis"} + seventhEighth.loser1_name = "Loser of #{consoSemis.select{|m| m.bracket_position_number == 1}.first.bout_number}" + seventhEighth.loser2_name = "Loser of #{consoSemis.select{|m| m.bracket_position_number == 2}.first.bout_number}" + end + + def fourPoolsToSemiLoser(matches_by_weight) + semis = matches_by_weight.select{|m| m.bracket_position == "Semis"} + thirdFourth = matches_by_weight.select{|m| m.bracket_position == "3/4"}.first + consoSemis = matches_by_weight.select{|m| m.bracket_position == "Conso Semis"} + seventhEighth = matches_by_weight.select{|m| m.bracket_position == "7/8"}.first + thirdFourth.loser1_name = "Loser of #{semis.select{|m| m.bracket_position_number == 1}.first.bout_number}" + thirdFourth.loser2_name = "Loser of #{semis.select{|m| m.bracket_position_number == 2}.first.bout_number}" + seventhEighth.loser1_name = "Loser of #{consoSemis.select{|m| m.bracket_position_number == 1}.first.bout_number}" + seventhEighth.loser2_name = "Loser of #{consoSemis.select{|m| m.bracket_position_number == 2}.first.bout_number}" + end +end diff --git a/app/models/generates_tournament_matches.rb b/app/models/generates_tournament_matches.rb new file mode 100644 index 0000000..752292b --- /dev/null +++ b/app/models/generates_tournament_matches.rb @@ -0,0 +1,28 @@ +module GeneratesTournamentMatches + + def generateMatchups + poolToBracket() if tournament_type == "Pool to bracket" + matches + end + + def poolToBracket + destroyAllMatches + buildTournamentWeights + generateMatches + end + + def buildTournamentWeights + weights.order(:max).each do |weight| + Pool.new(weight).generatePools() + last_match = matches.where(weight: weight).order(round: :desc).limit(1).first + highest_round = last_match.round + Poolbracket.new(weight, highest_round).generateBracketMatches() + end + end + + def generateMatches + assignBouts + assignLoserNames + end + +end diff --git a/app/models/losernamegen.rb b/app/models/losernamegen.rb deleted file mode 100644 index fae2f90..0000000 --- a/app/models/losernamegen.rb +++ /dev/null @@ -1,56 +0,0 @@ -class Losernamegen - def assignLoserNames(matches,weights) - weights.each do |w| - @matches = matches.select{|m| m.weight_id == w.id} - if w.pool_bracket_type == "twoPoolsToSemi" - twoPoolsToSemiLoser(@matches) - elsif w.pool_bracket_type == "fourPoolsToQuarter" - fourPoolsToQuarterLoser(@matches) - elsif w.pool_bracket_type == "fourPoolsToSemi" - fourPoolsToSemiLoser(@matches) - end - end - return matches - end - - def twoPoolsToSemiLoser(matches) - @match1 = matches.select{|m| m.loser1_name == "Winner Pool 1"}.first - @match2 = matches.select{|m| m.loser1_name == "Winner Pool 2"}.first - @matchChange = matches.select{|m| m.bracket_position == "3/4"}.first - @matchChange.loser1_name = "Loser of #{@match1.bout_number}" - @matchChange.loser2_name = "Loser of #{@match2.bout_number}" - end - - def fourPoolsToQuarterLoser(matches) - @quarters = matches.select{|m| m.bracket_position == "Quarter"} - @consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"} - @semis = matches.select{|m| m.bracket_position == "Semis"} - @thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first - @seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first - @consoSemis.each do |match| - if match.bracket_position_number == 1 - match.loser1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 1}.first.bout_number}" - match.loser2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 2}.first.bout_number}" - elsif match.bracket_position_number == 2 - match.loser1_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 3}.first.bout_number}" - match.loser2_name = "Loser of #{@quarters.select{|m| m.bracket_position_number == 4}.first.bout_number}" - end - end - @thirdFourth.loser1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.bout_number}" - @thirdFourth.loser2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.bout_number}" - @consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"} - @seventhEighth.loser1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.bout_number}" - @seventhEighth.loser2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.bout_number}" - end - - def fourPoolsToSemiLoser(matches) - @semis = matches.select{|m| m.bracket_position == "Semis"} - @thirdFourth = matches.select{|m| m.bracket_position == "3/4"}.first - @consoSemis = matches.select{|m| m.bracket_position == "Conso Semis"} - @seventhEighth = matches.select{|m| m.bracket_position == "7/8"}.first - @thirdFourth.loser1_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 1}.first.bout_number}" - @thirdFourth.loser2_name = "Loser of #{@semis.select{|m| m.bracket_position_number == 2}.first.bout_number}" - @seventhEighth.loser1_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 1}.first.bout_number}" - @seventhEighth.loser2_name = "Loser of #{@consoSemis.select{|m| m.bracket_position_number == 2}.first.bout_number}" - end -end \ No newline at end of file diff --git a/app/models/match.rb b/app/models/match.rb index 7bad4a1..b5a95da 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,5 +1,8 @@ class Match < ActiveRecord::Base belongs_to :tournament + belongs_to :weight + + WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"] diff --git a/app/models/pool.rb b/app/models/pool.rb index cb823c8..36c26d5 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -1,6 +1,7 @@ class Pool def initialize(weight) @weight = weight + @tournament = @weight.tournament @pool = 1 end @@ -23,7 +24,7 @@ class Pool bouts = b.map bouts.each do |bout| if bout[0] != nil and bout[1] != nil - match = Match.new( + match = @tournament.matches.create( w1: bout[0].id, w2: bout[1].id, weight_id: @weight.id, diff --git a/app/models/poolbracket.rb b/app/models/poolbracket.rb index 561b793..cdfc969 100644 --- a/app/models/poolbracket.rb +++ b/app/models/poolbracket.rb @@ -1,80 +1,80 @@ class Poolbracket - def generateBracketMatches(matches,weight,highest_round) - if weight.pool_bracket_type == "twoPoolsToSemi" - matches = twoPoolsToSemi(matches,weight,highest_round) - elsif weight.pool_bracket_type == "twoPoolsToFinal" - matches = twoPoolsToFinal(matches,weight,highest_round) - elsif weight.pool_bracket_type == "fourPoolsToQuarter" - matches = fourPoolsToQuarter(matches,weight,highest_round) - elsif weight.pool_bracket_type == "fourPoolsToSemi" - matches = fourPoolsToSemi(matches,weight,highest_round) - end - return matches - end - - def twoPoolsToSemi(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Runner Up Pool 2","Semis",1) - matches = createMatchup(matches,weight,@round,"Winner Pool 2","Runner Up Pool 1","Semis",2) - @round = @round + 1 - @matches = matches.select{|m| m.weight_id == weight.id} - matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"","","3/4",1) - return matches - end - - def twoPoolsToFinal(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Winner Pool 2","1/2",1) - matches = createMatchup(matches,weight,@round,"Runner Up Pool 1","Runner Up Pool 2","3/4",1) - return matches - end - - def fourPoolsToQuarter(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Runner Up Pool 2","Quarter",1) - matches = createMatchup(matches,weight,@round,"Winner Pool 4","Runner Up Pool 3","Quarter",2) - matches = createMatchup(matches,weight,@round,"Winner Pool 2","Runner Up Pool 1","Quarter",3) - matches = createMatchup(matches,weight,@round,"Winner Pool 3","Runner Up Pool 4","Quarter",4) - @round = @round + 1 - matches = createMatchup(matches,weight,@round,"","","Semis",1) - matches = createMatchup(matches,weight,@round,"","","Semis",2) - matches = createMatchup(matches,weight,@round,"","","Conso Semis",1) - matches = createMatchup(matches,weight,@round,"","","Conso Semis",2) - @round = @round + 1 - matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"","","3/4",1) - matches = createMatchup(matches,weight,@round,"","","5/6",1) - matches = createMatchup(matches,weight,@round,"","","7/8",1) - return matches - end - - def fourPoolsToSemi(matches,weight,round) - @round = round + 1 - matches = createMatchup(matches,weight,@round,"Winner Pool 1","Winner Pool 4","Semis",1) - matches = createMatchup(matches,weight,@round,"Winner Pool 2","Winner Pool 3","Semis",2) - matches = createMatchup(matches,weight,@round,"Runner Up Pool 1","Runner Up Pool 4","Conso Semis",1) - matches = createMatchup(matches,weight,@round,"Runner Up Pool 2","Runner Up Pool 3","Conso Semis",2) - @round = @round + 1 - matches = createMatchup(matches,weight,@round,"","","1/2",1) - matches = createMatchup(matches,weight,@round,"","","3/4",1) - matches = createMatchup(matches,weight,@round,"","","5/6",1) - matches = createMatchup(matches,weight,@round,"","","7/8",1) - return matches - end - - def createMatchup(matches,weight,round,w1_name,w2_name,bracket_position,bracket_position_number) - @match = Match.new - @match.loser1_name = w1_name - @match.loser2_name = w2_name - @match.weight_id = weight.id - @match.round = round - @match.bracket_position = bracket_position - @match.bracket_position_number = bracket_position_number - matches << @match - return matches - end - + def initialize(weight, highest_round) + @weight = weight + @tournament = @weight.tournament + @pool_bracket_type = @weight.pool_bracket_type + @round = highest_round + 1 + end -end \ No newline at end of file + def next_round + @round += 1 + end + + def generateBracketMatches() + if @pool_bracket_type == "twoPoolsToSemi" + return twoPoolsToSemi() + elsif @pool_bracket_type == "twoPoolsToFinal" + return twoPoolsToFinal() + elsif @pool_bracket_type == "fourPoolsToQuarter" + return fourPoolsToQuarter() + elsif @pool_bracket_type == "fourPoolsToSemi" + return fourPoolsToSemi() + end + return [] + end + + def twoPoolsToSemi() + createMatchup("Winner Pool 1", "Runner Up Pool 2", "Semis", 1) + createMatchup("Winner Pool 2", "Runner Up Pool 1", "Semis", 2) + next_round + createMatchup("","","1/2",1) + createMatchup("","","3/4",1) + end + + def twoPoolsToFinal() + createMatchup("Winner Pool 1", "Winner Pool 2", "1/2", 1) + createMatchup("Runner Up Pool 1", "Runner Up Pool 2", "3/4", 1) + end + + def fourPoolsToQuarter() + createMatchup("Winner Pool 1", "Runner Up Pool 2", "Quarter", 1) + createMatchup("Winner Pool 4", "Runner Up Pool 3", "Quarter", 2) + createMatchup("Winner Pool 2", "Runner Up Pool 1", "Quarter", 3) + createMatchup("Winner Pool 3", "Runner Up Pool 4", "Quarter", 4) + next_round + createMatchup("", "", "Semis", 1) + createMatchup("", "", "Semis", 2) + createMatchup("", "", "Conso Semis", 1) + createMatchup("", "", "Conso Semis", 2) + next_round + createMatchup("", "", "1/2", 1) + createMatchup("", "", "3/4", 1) + createMatchup("", "", "5/6", 1) + createMatchup("", "", "7/8", 1) + end + + def fourPoolsToSemi() + createMatchup("Winner Pool 1", "Winner Pool 4", "Semis", 1) + createMatchup("Winner Pool 2", "Winner Pool 3", "Semis", 2) + createMatchup("Runner Up Pool 1", "Runner Up Pool 4", "Conso Semis", 1) + createMatchup("Runner Up Pool 2", "Runner Up Pool 3", "Conso Semis", 2) + next_round + createMatchup("", "", "1/2", 1) + createMatchup("", "", "3/4", 1) + createMatchup("", "", "5/6", 1) + createMatchup("", "", "7/8", 1) + end + + def createMatchup(w1_name, w2_name, bracket_position, bracket_position_number) + @tournament.matches.create( + loser1_name: w1_name, + loser2_name: w2_name, + weight_id: @weight.id, + round: @round, + bracket_position: bracket_position, + bracket_position_number: bracket_position_number + ) + end + +end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index dd8c8b9..a103274 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,45 +1,44 @@ class Tournament < ActiveRecord::Base + + include GeneratesLoserNames + include GeneratesTournamentMatches + has_many :schools, dependent: :destroy has_many :weights, dependent: :destroy has_many :mats, dependent: :destroy has_many :wrestlers, through: :weights - + has_many :matches, dependent: :destroy def tournament_types ["Pool to bracket"] end - def matches - @matches = Match.where(tournament_id: self.id) - end - - def createCustomWeights(value) - self.weights.destroy_all + def createCustomWeights(value) + weights.destroy_all if value == 'hs' - @weights = [106,113,120,132,138,145,152,160,170,182,195,220,285] - end - @weights.each do |w| - newWeight = Weight.new - newWeight.max = w - newWeight.tournament_id = self.id - newWeight.save - end - end - - def upcomingMatches - if matches.nil? - return nil + Weight::HS_WEIGHT_CLASSES.each do |w| + weights.create(max: w) + end else - matches + raise "Unspecified behavior" end end - def generateMatchups - @matches = Tournamentmatchgen.new(self).genMatches() - end - def destroyAllMatches matches.destroy_all end + def matchesByRound(round) + matches.joins(:weight).where(round: round).order("weights.max") + end + + def assignBouts + bout_counts = Hash.new(0) + matches.each do |m| + m.bout_number = m.round * 1000 + bout_counts[m.round] + bout_counts[m.round] += 1 + m.save! + end + end + end diff --git a/app/models/tournamentmatchgen.rb b/app/models/tournamentmatchgen.rb deleted file mode 100644 index 5285559..0000000 --- a/app/models/tournamentmatchgen.rb +++ /dev/null @@ -1,51 +0,0 @@ -class Tournamentmatchgen - - def initialize(tournament) - @tournament = tournament - @matches = @tournament.matches - end - - def genMatches - if @tournament.tournament_type == "Pool to bracket" - @matches = poolToBracket() - end - @matches - end - - def poolToBracket - destroyMatches - buildTournamentWeights - generateMatches - saveMatches - @matches - end - - def destroyMatches - @tournament.destroyAllMatches - @matches = [] - end - - def buildTournamentWeights - @tournament.weights.sort_by{|x|[x.max]}.each do |weight| - matches = Pool.new(weight).generatePools() - last_match = matches.sort_by{|m| m.round}.last - highest_round = last_match.round - @matches += Poolbracket.new.generateBracketMatches(matches, weight, highest_round) - end - end - - def generateMatches - @matches = - Losernamegen.new.assignLoserNames( - Boutgen.new.assignBouts(@matches, @tournament.weights), - @tournament.weights) - end - - def saveMatches - @matches.each do |m| - m.tournament_id = @tournament.id - m.save - end - end - -end diff --git a/app/models/weight.rb b/app/models/weight.rb index 3ae2cf8..42b3a97 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -1,9 +1,12 @@ class Weight < ActiveRecord::Base belongs_to :tournament has_many :wrestlers, dependent: :destroy + has_many :matches, dependent: :destroy attr_accessor :pools + HS_WEIGHT_CLASSES = [106,113,120,132,138,145,152,160,170,182,195,220,285] + before_save do self.tournament.destroyAllMatches end @@ -43,7 +46,7 @@ class Weight < ActiveRecord::Base end - def twoPoolNumbers(wrestlers) + def twoPoolNumbers(wrestlers) pool = 1 wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w| if w.original_seed == 1 @@ -65,8 +68,8 @@ class Weight < ActiveRecord::Base end return wrestlers end - - def fourPoolNumbers(wrestlers) + + def fourPoolNumbers(wrestlers) pool = 1 wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w| if w.original_seed == 1 @@ -98,20 +101,20 @@ class Weight < ActiveRecord::Base if self.wrestlers.size > 6 && self.wrestlers.size <= 8 return "twoPoolsToSemi" elsif self.wrestlers.size > 8 && self.wrestlers.size <= 10 - return "twoPoolsToFinal" + return "twoPoolsToFinal" elsif self.wrestlers.size == 11 || self.wrestlers.size == 12 return "fourPoolsToQuarter" elsif self.wrestlers.size > 12 && self.wrestlers.size <= 16 return "fourPoolsToSemi" end end - + def poolRounds(matches) @matchups = matches.select{|m| m.weight_id == self.id} @poolMatches = @matchups.select{|m| m.bracket_position == nil} return @poolMatches.sort_by{|m| m.round}.last.round end - + def totalRounds(matches) @matchups = matches.select{|m| m.weight_id == self.id} @lastRound = matches.sort_by{|m| m.round}.last.round @@ -125,5 +128,5 @@ class Weight < ActiveRecord::Base end return @count end - + end diff --git a/app/views/static_pages/all_brackets.html.erb b/app/views/static_pages/all_brackets.html.erb index 8e712e6..57c013e 100644 --- a/app/views/static_pages/all_brackets.html.erb +++ b/app/views/static_pages/all_brackets.html.erb @@ -1,5 +1,5 @@ @@ -26,11 +26,11 @@ <% @tournament.weights.sort_by{|w| w.max}.each do |w| %>
<% @weight = w %> - <% @matches = @tournament.upcomingMatches.select{|m| m.weight_id == @weight.id} %> + <% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %> <% @wrestlers = Wrestler.where(weight_id: @weight.id) %> <% @pools = w.poolRounds(@matches) %>
<%= @weight.max %> lbs Bracket
- + <%= render 'pool' %>
@@ -48,4 +48,4 @@ <% end %>
<% end %> - \ No newline at end of file + diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb index 86c3b4d..37db1c7 100644 --- a/test/integration/poolbracket_matchups_test.rb +++ b/test/integration/poolbracket_matchups_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest def setup @tournament = Tournament.find(1) - @genMatchups = @tournament.upcomingMatches + @genMatchups = @tournament.generateMatchups end def createTournament(numberOfWrestlers) @@ -39,7 +39,8 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest def create_weight Weight.new( id: @id, - tournament_id: @id + tournament_id: @id, + max: @id ).save! end @@ -58,7 +59,7 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest end def checkForByeInPool(tournament) - tournament.upcomingMatches + tournament.generateMatchups matchups = tournament.matches tournament.weights.each do |w| w.wrestlers.each do |wr| @@ -81,15 +82,21 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest refute_nil @tournament end - test "tests bout_number matches round" do - @matchup_to_test = @genMatchups.select{|m| m.bout_number == 4000}.first - assert_equal 4, @matchup_to_test.round + test "tournament can be set to high school weight classes" do + @tournament.weights.destroy_all + @tournament.createCustomWeights("hs") + assert_equal Weight::HS_WEIGHT_CLASSES.size, @tournament.weights.size + end + + test "tests bout numbers correspond to round" do + matchup_to_test = @genMatchups.select{|m| m.bout_number == 4000}.first + assert_equal 4, matchup_to_test.round end test "tests bout_numbers are generated with smallest weight first regardless of id" do - @weight = @tournament.weights.map.sort_by{|x|[x.max]}.first - @matchup = @genMatchups.select{|m| m.bout_number == 1000}.first - assert_equal @weight.max, @matchup.weight_max + weight = @tournament.weights.order(:max).limit(1).first + matchup = @tournament.matches.where(bout_number: 1000).limit(1).first + assert_equal weight.max, matchup.weight.max end test "tests number of matches in 5 man one pool" do @@ -117,13 +124,10 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest assert_equal 32, @twentysix_matches.length end - test "test if a wrestler can exceed five matches" do - @count = 5 - until @count > 16 do - @tournament2 = createTournament(@count) - checkForByeInPool(@tournament2) - @count = @count + 1 + (5...16).each do |count| + tourney = createTournament(count) + checkForByeInPool(tourney) end end