diff --git a/app/models/matchup.rb b/app/models/matchup.rb index b08ad5b..b884837 100644 --- a/app/models/matchup.rb +++ b/app/models/matchup.rb @@ -7,7 +7,7 @@ class Matchup hash end - def convert_to_obj(h) + def convert_to_obj(h) h.each do |k,v| self.class.send(:attr_accessor, k) instance_variable_set("@#{k}", v) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index fffacf2..a670fc0 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -31,10 +31,10 @@ class Tournament < ActiveRecord::Base def generateMatchups @matches = [] self.weights.map.sort_by{|x|[x.max]}.each do |weight| - @upcomingMatches = weight.generateMatchups(@matches) + @matches = weight.generateMatchups(@matches) end - @upcomingMatches = assignBouts(@upcomingMatches) - return @upcomingMatches + @matches = assignBouts(@matches) + return @matches end def assignBouts(matches) diff --git a/app/models/weight.rb b/app/models/weight.rb index 0ac596d..c8fbf90 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -92,9 +92,9 @@ class Weight < ActiveRecord::Base return "twoPoolsToSemi" elsif self.wrestlers.size > 8 && self.wrestlers.size <= 10 return "twoPoolsToFinal" - elsif self.wrestlers.size == 11 + elsif self.wrestlers.size == 11 || self.wrestlers.size == 12 return "fourPoolsToQuarter" - elsif self.wrestlers.size > 11 && self.wrestlers.size <= 16 + elsif self.wrestlers.size > 12 && self.wrestlers.size <= 16 return "fourPoolsToSemi" end end diff --git a/test/fixtures/wrestlers.yml b/test/fixtures/wrestlers.yml index 486fc4b..e8cff9d 100644 --- a/test/fixtures/wrestlers.yml +++ b/test/fixtures/wrestlers.yml @@ -394,4 +394,40 @@ fourtyfour: original_seed: 12 season_loss: 2 season_win: 50 + criteria: + +fourtyfive: + name: Guy34 + school_id: 1 + weight_id: 5 + original_seed: 13 + season_loss: 2 + season_win: 50 + criteria: + +fourtysix: + name: Guy35 + school_id: 1 + weight_id: 5 + original_seed: 14 + season_loss: 2 + season_win: 50 + criteria: + +fourtyseven: + name: Guy36 + school_id: 1 + weight_id: 5 + original_seed: 15 + season_loss: 2 + season_win: 50 + criteria: + +fourtyeight: + name: Guy37 + school_id: 1 + weight_id: 5 + original_seed: 16 + season_loss: 2 + season_win: 50 criteria: \ No newline at end of file diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb new file mode 100644 index 0000000..8b3ab79 --- /dev/null +++ b/test/integration/poolbracket_matchups_test.rb @@ -0,0 +1,52 @@ +require 'test_helper' + +class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest + def setup + @tournament = Tournament.find(1) + @genMatchups = @tournament.generateMatchups + end + + test "the truth" do + assert true + end + + test "found tournament" do + refute_nil @tournament + end + + test "tests boutNumber matches round" do + @matchup_to_test = @genMatchups.select{|m| m.boutNumber == 4000}.first + assert_equal 4, @matchup_to_test.round + end + + test "tests boutNumbers 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.boutNumber == 1000}.first + assert_equal @weight.max, @matchup.weight_max + end + + test "tests number of matches in 5 man one pool" do + @six_matches = @genMatchups.select{|m| m.weight_max == 106} + assert_equal 10, @six_matches.length + end + + test "tests number of matches in 11 man pool bracket" do + @twentysix_matches = @genMatchups.select{|m| m.weight_max == 126} + assert_equal 22, @twentysix_matches.length + end + + test "tests number of matches in 9 man pool bracket" do + @twentysix_matches = @genMatchups.select{|m| m.weight_max == 113} + assert_equal 18, @twentysix_matches.length + end + + test "tests number of matches in 7 man pool bracket" do + @twentysix_matches = @genMatchups.select{|m| m.weight_max == 120} + assert_equal 13, @twentysix_matches.length + end + + test "tests number of matches in 16 man pool bracket" do + @twentysix_matches = @genMatchups.select{|m| m.weight_max == 132} + assert_equal 32, @twentysix_matches.length + end +end