From 7146c401cf309d7df39268cceddbb09233116443 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Fri, 27 Mar 2015 19:07:49 +0000 Subject: [PATCH] Test 5 match rule for bracket size 5-16 --- app/controllers/static_pages_controller.rb | 4 -- app/models/weight.rb | 9 ++- test/fixtures/schools.yml | 2 + test/fixtures/tournaments.yml | 2 + test/fixtures/weights.yml | 1 - test/integration/poolbracket_matchups_test.rb | 64 +++++++++++++++++++ 6 files changed, 75 insertions(+), 7 deletions(-) diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index f46dc1e..0a89ead 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -40,10 +40,6 @@ class StaticPagesController < ApplicationController @tournament = Tournament.find(@weight.tournament_id) @matches = @tournament.upcomingMatches.select{|m| m.weight_id == @weight.id} @wrestlers = Wrestler.where(weight_id: @weight.id) - #@poolOneWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 1} - #@poolTwoWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 2} - #@poolThreeWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 3} - #@poolFourWrestlers = @wrestlers.select{|w| w.generatePoolNumber == 4} end diff --git a/app/models/weight.rb b/app/models/weight.rb index 7920927..c3da269 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -2,7 +2,7 @@ class Weight < ActiveRecord::Base belongs_to :tournament has_many :wrestlers, dependent: :destroy - attr_accessor :pools, :bracket_size, :bracket_type, :poolRounds + attr_accessor :pools, :bracket_size, :bracket_type, :poolRounds, :totalRounds def pools @wrestlers = self.wrestlers @@ -95,7 +95,7 @@ class Weight < ActiveRecord::Base elsif self.wrestlers.size == 11 || self.wrestlers.size == 12 return "fourPoolsToQuarter" elsif self.wrestlers.size > 12 && self.wrestlers.size <= 16 - return "fourPoolsToSemi" + return "fourPoolsToSemi" end end @@ -117,4 +117,9 @@ class Weight < ActiveRecord::Base return @poolMatches.sort_by{|m| m.round}.last.round end + def totalRounds(matches) + @matchups = matches.select{|m| m.weight_id == self.id} + return @matchups.sort_by{|m| m.round}.last.round + end + end diff --git a/test/fixtures/schools.yml b/test/fixtures/schools.yml index f73adfb..e9359b1 100644 --- a/test/fixtures/schools.yml +++ b/test/fixtures/schools.yml @@ -9,3 +9,5 @@ two: id: 2 name: Grove City tournament_id: 1 + + diff --git a/test/fixtures/tournaments.yml b/test/fixtures/tournaments.yml index 250d475..040d3e4 100644 --- a/test/fixtures/tournaments.yml +++ b/test/fixtures/tournaments.yml @@ -9,3 +9,5 @@ one: matchups_array: + + diff --git a/test/fixtures/weights.yml b/test/fixtures/weights.yml index 42a2c0e..51d0555 100644 --- a/test/fixtures/weights.yml +++ b/test/fixtures/weights.yml @@ -27,4 +27,3 @@ five: - diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb index 0fd33e4..6c7d4e4 100644 --- a/test/integration/poolbracket_matchups_test.rb +++ b/test/integration/poolbracket_matchups_test.rb @@ -7,6 +7,61 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest @genMatchups = @tournament.generateMatchups end + def createTournament(numberOfWrestlers) + @count = 1 + @id = 6000 + numberOfWrestlers + @tournament3 = Tournament.new + @tournament3.id = @id + @tournament3.name = "Something" + @tournament3.address = "Some Place" + @tournament3.director = "Some Guy" + @tournament3.director_email = "test@test.com" + @tournament3.save + @school3 = School.new + @school3.id = @id + @school3.name = "Shit Show" + @school3.tournament_id = @id + @school3.save + @weight3 = Weight.new + @weight3.id = @id + @weight3.max = 350 + @weight3.tournament_id = @id + @weight3.save + until @count > numberOfWrestlers do + @wrestler2 = Wrestler.new + @wrestler2.name = "Guy #{@count}" + @wrestler2.school_id = @id + @wrestler2.weight_id = @id + @wrestler2.original_seed = @count + @wrestler2.season_loss = 0 + @wrestler2.season_win = 0 + @wrestler2.criteria = nil + @wrestler2.save + @count = @count + 1 + end + return @tournament3 + end + + def checkForByeInPool(tournament) + @matchups = tournament.generateMatchups + tournament.weights.each do |w| + w.wrestlers.each do |wr| + @round = 1 + if w.totalRounds(@matchups) > 5 + until @round > w.poolRounds(@matchups) do + if wr.boutByRound(@round,@matchups) == "BYE" + @message = "BYE" + end + @round = @round + 1 + end + assert_equal "BYE", @message + @message = nil + end + end + end + end + + test "the truth" do assert true end @@ -58,5 +113,14 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest assert_equal @genMatchup.w1_name, @matchup.w1_name 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 + end + end + #todo test crazy movements through each bracket? end