1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Speeding up tests and renaming generateMatchup methods

This commit is contained in:
2016-03-26 03:55:02 +00:00
17 changed files with 2814 additions and 729 deletions

View File

@@ -61,3 +61,4 @@ gem 'spring', :group => :development
#gem 'bullet' #gem 'bullet'
end end

View File

@@ -8,7 +8,6 @@ module GeneratesTournamentMatches
poolToBracket() if tournament_type == "Pool to bracket" poolToBracket() if tournament_type == "Pool to bracket"
self.curently_generating_matches = nil self.curently_generating_matches = nil
self.save self.save
matches
end end
if Rails.env.production? if Rails.env.production?
handle_asynchronously :generateMatchups handle_asynchronously :generateMatchups
@@ -16,13 +15,11 @@ module GeneratesTournamentMatches
def poolToBracket def poolToBracket
destroyAllMatches destroyAllMatches
buildTournamentWeights generatePoolToBracketMatches
generateMatches poolToBracketPostMatchCreation
# This is not working for pool order and I cannot get tests working
movePoolSeedsToFinalPoolRound
end end
def buildTournamentWeights def generatePoolToBracketMatches
weights.order(:max).each do |weight| weights.order(:max).each do |weight|
Pool.new(weight).generatePools() Pool.new(weight).generatePools()
last_match = matches.where(weight: weight).order(round: :desc).limit(1).first last_match = matches.where(weight: weight).order(round: :desc).limit(1).first
@@ -31,11 +28,12 @@ module GeneratesTournamentMatches
end end
end end
def generateMatches def poolToBracketPostMatchCreation
moveFinalsMatchesToLastRound moveFinalsMatchesToLastRound
assignBouts assignBouts
assignLoserNames assignLoserNames
assignFirstMatchesToMats assignFirstMatchesToMats
movePoolSeedsToFinalPoolRound
end end
def moveFinalsMatchesToLastRound def moveFinalsMatchesToLastRound

View File

@@ -7,6 +7,10 @@ class Match < ActiveRecord::Base
after_update do after_update do
after_update_actions
end
def after_update_actions
if self.finished == 1 && self.winner_id != nil if self.finished == 1 && self.winner_id != nil
if self.w1 && self.w2 if self.w1 && self.w2
wrestler1.touch wrestler1.touch

View File

@@ -6,17 +6,14 @@ class Pool
end end
def generatePools def generatePools
matches = []
pools = @weight.pools pools = @weight.pools
while @pool <= pools while @pool <= pools
matches += roundRobin() roundRobin
@pool += 1 @pool += 1
end end
return matches
end end
def roundRobin def roundRobin
matches = []
wrestlers = @weight.wrestlersForPool(@pool) wrestlers = @weight.wrestlersForPool(@pool)
poolMatches = RoundRobinTournament.schedule(wrestlers).reverse poolMatches = RoundRobinTournament.schedule(wrestlers).reverse
poolMatches.each_with_index do |b, index| poolMatches.each_with_index do |b, index|
@@ -24,16 +21,14 @@ class Pool
bouts = b.map bouts = b.map
bouts.each do |bout| bouts.each do |bout|
if bout[0] != nil and bout[1] != nil if bout[0] != nil and bout[1] != nil
match = @tournament.matches.create( @tournament.matches.create(
w1: bout[0].id, w1: bout[0].id,
w2: bout[1].id, w2: bout[1].id,
weight_id: @weight.id, weight_id: @weight.id,
bracket_position: "Pool", bracket_position: "Pool",
round: round) round: round)
matches << match
end end
end end
end end
matches
end end
end end

View File

@@ -14,7 +14,7 @@ class Weight < ActiveRecord::Base
end end
before_save do before_save do
self.tournament.destroyAllMatches # self.tournament.destroyAllMatches
end end
def wrestlersForPool(pool) def wrestlersForPool(pool)

View File

@@ -5,12 +5,12 @@ class MatchesControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@match = @tournament.matches.first @match = Match.where("tournament_id = ? and mat_id = ?",1,1).first
end end
def post_update def post_update
patch :update, id: @match.id, match: {w1: @match.w1, w2: @match.w2} patch :update, id: @match.id, match: {tournament_id: 1, mat_id: 1}
end end
def get_edit def get_edit

View File

@@ -5,7 +5,7 @@ class MatsControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@mat = mats(:one) @mat = mats(:one)
end end

View File

@@ -5,7 +5,7 @@ class SchoolsControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
end end

View File

@@ -5,7 +5,7 @@ class StaticPagesControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
end end

View File

@@ -5,7 +5,7 @@ include Devise::TestHelpers
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
@wrestlers = @tournament.weights.first.wrestlers @wrestlers = @tournament.weights.first.wrestlers
@adjust = Teampointadjust.find(1) @adjust = Teampointadjust.find(1)

View File

@@ -5,7 +5,7 @@ class WeightsControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@weight = @tournament.weights.first @weight = @tournament.weights.first
end end

View File

@@ -5,7 +5,7 @@ class WrestlersControllerTest < ActionController::TestCase
setup do setup do
@tournament = Tournament.find(1) @tournament = Tournament.find(1)
@tournament.generateMatchups # @tournament.generateMatchups
@school = @tournament.schools.first @school = @tournament.schools.first
@wrestler = @school.wrestlers.first @wrestler = @school.wrestlers.first
end end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -3,129 +3,127 @@ require 'test_helper'
class PoolAdvancementTest < ActionDispatch::IntegrationTest class PoolAdvancementTest < ActionDispatch::IntegrationTest
def setup def setup
@tournament = Tournament.find(1) tournament = Tournament.find(1)
@tournament.generateMatchups tournament.generateMatchups
@matches = @tournament.matches
end end
def showMatches # def showMatches
matches = Weight.where("id = ?", 4).first.matches # matches = Weight.where("id = ?", 4).first.matches
# matches = @matches.select{|m| m.weight_id == 4} # matches.each do |m|
matches.each do |m| # puts "Bout: #{m.bout_number} #{m.w1_name} vs #{m.w2_name} #{m.bracket_position} #{m.poolNumber}"
puts "Bout: #{m.bout_number} #{m.w1_name} vs #{m.w2_name} #{m.bracket_position} #{m.poolNumber}" # end
end # end
end
def singlePoolNotFinished def singlePoolNotFinished
matches = @matches
endMatch(1000,"Jackson Lakso",matches) endMatch(1000,"Jackson Lakso")
endMatch(1001,"Jaden Mattox",matches) endMatch(1001,"Jaden Mattox")
endMatch(2000,"James Wimer",matches) endMatch(2000,"James Wimer")
endMatch(2001,"Jaden Mattox",matches) endMatch(2001,"Jaden Mattox")
endMatch(3000,"Jaden Mattox",matches) endMatch(3000,"Jaden Mattox")
endMatch(3001,"James Wimer",matches) endMatch(3001,"James Wimer")
endMatch(4000,"JD Woods",matches) endMatch(4000,"JD Woods")
endMatch(4001,"James Wimer",matches) endMatch(4001,"James Wimer")
endMatch(5000,"James Wimer",matches) endMatch(5000,"James Wimer")
end end
def singlePoolFinished def singlePoolFinished
singlePoolNotFinished singlePoolNotFinished
matches = @matches
endMatch(5001,"Jackson Lakso",matches) endMatch(5001,"Jackson Lakso")
end end
def sixteenManToSemi def sixteenManToSemi
matches = @matches
endMatch(1013,"Guy22",matches) endMatch(1013,"Guy22")
endMatch(1014,"Guy29",matches) endMatch(1014,"Guy29")
endMatch(2012,"Guy29",matches) endMatch(2012,"Guy29")
endMatch(2013,"Guy22",matches) endMatch(2013,"Guy22")
endMatch(3012,"Guy37",matches) endMatch(3012,"Guy37")
endMatch(3013,"Guy22",matches) endMatch(3013,"Guy22")
endMatch(1015,"Guy36",matches) endMatch(1015,"Guy36")
endMatch(1016,"Guy32",matches) endMatch(1016,"Guy32")
endMatch(2014,"Guy36",matches) endMatch(2014,"Guy36")
endMatch(2015,"Guy32",matches) endMatch(2015,"Guy32")
endMatch(3014,"Guy36",matches) endMatch(3014,"Guy36")
endMatch(3015,"Guy23",matches) endMatch(3015,"Guy23")
endMatch(1017,"Guy31",matches) endMatch(1017,"Guy31")
endMatch(1018,"Guy35",matches) endMatch(1018,"Guy35")
endMatch(2016,"Guy35",matches) endMatch(2016,"Guy35")
endMatch(2017,"Guy31",matches) endMatch(2017,"Guy31")
endMatch(3016,"Guy27",matches) endMatch(3016,"Guy27")
endMatch(3017,"Guy31",matches) endMatch(3017,"Guy31")
endMatch(1019,"Guy34",matches) endMatch(1019,"Guy34")
endMatch(1020,"Guy26",matches) endMatch(1020,"Guy26")
endMatch(2018,"Guy30",matches) endMatch(2018,"Guy30")
endMatch(2019,"Guy34",matches) endMatch(2019,"Guy34")
endMatch(3018,"Guy26",matches) endMatch(3018,"Guy26")
endMatch(3019,"Guy34",matches) endMatch(3019,"Guy34")
end end
def sevenManTwoPoolToSemi def sevenManTwoPoolToSemi
matches = @matches
endMatch(1006,"Casey Davis",matches) endMatch(1006,"Casey Davis")
endMatch(1007,"Ethan Leapley",matches) endMatch(1007,"Ethan Leapley")
endMatch(2006,"Clayton Ray",matches) endMatch(2006,"Clayton Ray")
endMatch(2007,"Ethan Leapley",matches) endMatch(2007,"Ethan Leapley")
endMatch(3006,"Ethan Leapley",matches) endMatch(3006,"Ethan Leapley")
endMatch(3007,"Casey Davis",matches) endMatch(3007,"Casey Davis")
endMatch(1008,"Kameron Teacher",matches) endMatch(1008,"Kameron Teacher")
endMatch(2008,"Kameron Teacher",matches) endMatch(2008,"Kameron Teacher")
endMatch(3008,"Robbie Fusner",matches) endMatch(3008,"Robbie Fusner")
end end
def sevenManTwoPoolSemiToFinals def sevenManTwoPoolSemiToFinals
sevenManTwoPoolToSemi sevenManTwoPoolToSemi
matches = @matches
endMatch(4005,"Casey Davis",matches) endMatch(4005,"Casey Davis")
endMatch(4004,"Ethan Leapley",matches) endMatch(4004,"Ethan Leapley")
end end
def nineManBracketPoolOneOutrightWinnerGuyTwo def nineManBracketPoolOneOutrightWinnerGuyTwo
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1002,"Guy8",matches) endMatch(1002,"Guy8")
endMatch(1003,"Guy5",matches) endMatch(1003,"Guy5")
endMatch(2002,"Guy2",matches) endMatch(2002,"Guy2")
endMatch(2003,"Guy8",matches) endMatch(2003,"Guy8")
endMatch(3002,"Guy5",matches) endMatch(3002,"Guy5")
endMatch(3003,"Guy2",matches) endMatch(3003,"Guy2")
endMatch(4002,"Guy8",matches) endMatch(4002,"Guy8")
endMatch(4003,"Guy2",matches) endMatch(4003,"Guy2")
endMatch(5002,"Guy2",matches) endMatch(5002,"Guy2")
endMatch(5003,"Guy10",matches) endMatch(5003,"Guy10")
end end
def nineManBracketPoolTwoGuyNineHeadToHead def nineManBracketPoolTwoGuyNineHeadToHead
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy4",matches) endMatch(1004,"Guy4")
endMatch(1005,"Guy3",matches) endMatch(1005,"Guy3")
endMatch(2004,"Guy9",matches) endMatch(2004,"Guy9")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeHeadToHead def nineManBracketPoolTwoGuyThreeHeadToHead
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches) endMatch(1004,"Guy9")
endMatch(1005,"Guy3",matches) endMatch(1005,"Guy3")
endMatch(2004,"Guy3",matches) endMatch(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy4",matches) endMatch(3005,"Guy4")
end end
def nineManBracketPoolTwoGuyThreeDeductedPoints def nineManBracketPoolTwoGuyThreeDeductedPoints
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches) endMatch(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatch(2004,"Guy3",matches) endMatch(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
deduct = Teampointadjust.new deduct = Teampointadjust.new
deduct.wrestler_id = translateNameToId("Guy7") deduct.wrestler_id = translateNameToId("Guy7")
deduct.points = 1 deduct.points = 1
@@ -133,175 +131,162 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
end end
def nineManBracketPoolTwoGuyThreeMostDecisionPoints def nineManBracketPoolTwoGuyThreeMostDecisionPoints
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchExtraPoints(1004,"Guy9",matches) endMatchExtraPoints(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatchExtraPoints(2004,"Guy3",matches) endMatchExtraPoints(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatchExtraPoints(3005,"Guy3",matches) endMatchExtraPoints(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeQuickestPin def nineManBracketPoolTwoGuyThreeQuickestPin
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchWithQuickPin(1004,"Guy9",matches) endMatchWithQuickPin(1004,"Guy9")
endMatchWithPin(1005,"Guy7",matches) endMatchWithPin(1005,"Guy7")
endMatchWithQuickPin(2004,"Guy3",matches) endMatchWithQuickPin(2004,"Guy3")
endMatchWithPin(2005,"Guy7",matches) endMatchWithPin(2005,"Guy7")
endMatchWithPin(3004,"Guy9",matches) endMatchWithPin(3004,"Guy9")
endMatchWithQuickestPin(3005,"Guy3",matches) endMatchWithQuickestPin(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeTeamPoints def nineManBracketPoolTwoGuyThreeTeamPoints
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatch(1004,"Guy9",matches) endMatch(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatchWithMajor(2004,"Guy3",matches) endMatchWithMajor(2004,"Guy3")
endMatch(2005,"Guy7",matches) endMatch(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
end end
def nineManBracketPoolTwoGuyThreeMostPins def nineManBracketPoolTwoGuyThreeMostPins
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchWithMajor(1004,"Guy9",matches) endMatchWithMajor(1004,"Guy9")
endMatch(1005,"Guy7",matches) endMatch(1005,"Guy7")
endMatchWithPin(2004,"Guy3",matches) endMatchWithPin(2004,"Guy3")
endMatchWithMajor(2005,"Guy7",matches) endMatchWithMajor(2005,"Guy7")
endMatch(3004,"Guy9",matches) endMatch(3004,"Guy9")
endMatch(3005,"Guy3",matches) endMatch(3005,"Guy3")
end end
def nineManBracketPoolOneGuyEightMostTechs def nineManBracketPoolOneGuyEightMostTechs
matches = @matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
endMatchWithTech(1002,"Guy8",matches) endMatchWithTech(1002,"Guy8")
endMatch(1003,"Guy5",matches) endMatch(1003,"Guy5")
endMatchWithMajor(2002,"Guy2",matches) endMatchWithMajor(2002,"Guy2")
endMatchWithTech(2003,"Guy8",matches) endMatchWithTech(2003,"Guy8")
endMatchWithMajor(3002,"Guy10",matches) endMatchWithMajor(3002,"Guy10")
endMatchWithMajor(3003,"Guy2",matches) endMatchWithMajor(3003,"Guy2")
endMatch(4002,"Guy8",matches) endMatch(4002,"Guy8")
endMatchWithMajor(4003,"Guy10",matches) endMatchWithMajor(4003,"Guy10")
endMatchWithMajor(5002,"Guy2",matches) endMatchWithMajor(5002,"Guy2")
endMatchWithMajor(5003,"Guy10",matches) endMatchWithMajor(5003,"Guy10")
end end
def elevenManBracketToQuarter def elevenManBracketToQuarter
matches = @matches
endMatch(1009,"Guy11",matches) endMatch(1009,"Guy11")
endMatch(2009,"Guy11",matches) endMatch(2009,"Guy11")
endMatch(3009,"Guy18",matches) endMatch(3009,"Guy18")
endMatch(1010,"Guy12",matches) endMatch(1010,"Guy12")
endMatch(2010,"Guy12",matches) endMatch(2010,"Guy12")
endMatch(3010,"Guy17",matches) endMatch(3010,"Guy17")
endMatch(1011,"Guy13",matches) endMatch(1011,"Guy13")
endMatch(2011,"Guy13",matches) endMatch(2011,"Guy13")
endMatch(3011,"Guy19",matches) endMatch(3011,"Guy19")
endMatch(1012,"Guy14",matches) endMatch(1012,"Guy14")
end end
def elevenManBracketToSemis def elevenManBracketToSemis
elevenManBracketToQuarter elevenManBracketToQuarter
matches = @matches
endMatch(4006,"Guy11",matches) endMatch(4006,"Guy11")
endMatch(4007,"Guy14",matches) endMatch(4007,"Guy14")
endMatch(4008,"Guy12",matches) endMatch(4008,"Guy12")
endMatch(4009,"Guy13",matches) endMatch(4009,"Guy13")
end end
def elevenManBracketToFinals def elevenManBracketToFinals
elevenManBracketToSemis elevenManBracketToSemis
matches = @matches
endMatch(5004,"Guy11",matches) endMatch(5004,"Guy11")
endMatch(5005,"Guy12",matches) endMatch(5005,"Guy12")
endMatch(5006,"Guy17",matches) endMatch(5006,"Guy17")
endMatch(5007,"Guy18",matches) endMatch(5007,"Guy18")
end end
def elevenManBracketFinished def elevenManBracketFinished
elevenManBracketToFinals elevenManBracketToFinals
matches = @matches
endMatch(6004,"Guy11",matches) endMatch(6004,"Guy11")
endMatch(6005,"Guy14",matches) endMatch(6005,"Guy14")
endMatch(6006,"Guy17",matches) endMatch(6006,"Guy17")
endMatch(6007,"Guy19",matches) endMatch(6007,"Guy19")
end end
def extraDoesNotScoreTeamPoints def extraDoesNotScoreTeamPoints
matches = @matches
wrestlerName = "Guy22" wrestlerName = "Guy22"
wrestler = Wrestler.find(translateNameToId(wrestlerName)) wrestler = Wrestler.find(translateNameToId(wrestlerName))
wrestler.extra = true wrestler.extra = true
wrestler.save wrestler.save
endMatch(1013,"Guy22",matches) endMatch(1013,"Guy22")
end end
def endMatch(bout,winner,matches) def endMatch(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1 # match = @matches.select{|m| m.bout_number == bout}.first
match.winner_id = translateNameToId(winner)
match.win_type = "Decision" match.win_type = "Decision"
match.score = 1-0 match.score = 1-0
saveMatch(match,winner)
match.save
end end
def endMatchExtraPoints(bout,winner,matches) def endMatchExtraPoints(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Decision" match.win_type = "Decision"
match.score = 0-2 match.score = 0-2
saveMatch(match,winner)
match.save
end end
def endMatchWithMajor(bout,winner,matches) def endMatchWithMajor(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Major" match.win_type = "Major"
match.score = 8-0 match.score = 8-0
saveMatch(match,winner)
match.save
end end
def endMatchWithTech(bout,winner,matches) def endMatchWithTech(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Tech Fall" match.win_type = "Tech Fall"
match.score = 15-0
match.save saveMatch(match,winner)
end end
def endMatchWithPin(bout,winner,matches) def endMatchWithPin(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Pin" match.win_type = "Pin"
match.score = "5:00" match.score = "5:00"
saveMatch(match,winner)
match.save
end end
def endMatchWithQuickestPin(bout,winner,matches) def endMatchWithQuickestPin(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Pin" match.win_type = "Pin"
match.score = "0:20" match.score = "0:20"
saveMatch(match,winner)
match.save
end end
def endMatchWithQuickPin(bout,winner,matches) def endMatchWithQuickPin(bout,winner)
match = Match.where(bout_number: bout).first match = Match.where(bout_number: bout).first
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Pin" match.win_type = "Pin"
match.score = "1:20" match.score = "1:20"
saveMatch(match,winner)
match.save end
def saveMatch(match,winner)
match.finished = 1
match.winner_id = translateNameToId(winner)
match.save
end end
def translateNameToId(wrestler) def translateNameToId(wrestler)
@@ -458,7 +443,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "advancement points winner 1/2" do test "advancement points winner 1/2" do
nineManBracketPoolOneOutrightWinnerGuyTwo nineManBracketPoolOneOutrightWinnerGuyTwo
nineManBracketPoolTwoGuyThreeHeadToHead nineManBracketPoolTwoGuyThreeHeadToHead
endMatch(6000,"Guy2",@matches) endMatch(6000,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 16, wrestler1.placementPoints assert_equal 16, wrestler1.placementPoints
end end
@@ -466,7 +451,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "advancement points winner 3/4" do test "advancement points winner 3/4" do
nineManBracketPoolOneOutrightWinnerGuyTwo nineManBracketPoolOneOutrightWinnerGuyTwo
nineManBracketPoolTwoGuyThreeHeadToHead nineManBracketPoolTwoGuyThreeHeadToHead
endMatch(6001,"Guy8",@matches) endMatch(6001,"Guy8")
wrestler1 = Wrestler.where("name = ?", "Guy8").first wrestler1 = Wrestler.where("name = ?", "Guy8").first
assert_equal 10, wrestler1.placementPoints assert_equal 10, wrestler1.placementPoints
end end
@@ -486,25 +471,25 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
end end
test "bonus points major" do test "bonus points major" do
endMatchWithMajor(2002,"Guy2",@matches) endMatchWithMajor(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 3, wrestler1.teamPointsEarned assert_equal 3, wrestler1.teamPointsEarned
end end
test "bonus points pin" do test "bonus points pin" do
endMatchWithPin(2002,"Guy2",@matches) endMatchWithPin(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 4, wrestler1.teamPointsEarned assert_equal 4, wrestler1.teamPointsEarned
end end
test "bonus points tech fall" do test "bonus points tech fall" do
endMatchWithTech(2002,"Guy2",@matches) endMatchWithTech(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 3.5, wrestler1.teamPointsEarned assert_equal 3.5, wrestler1.teamPointsEarned
end end
test "pool team points win" do test "pool team points win" do
endMatch(2002,"Guy2",@matches) endMatch(2002,"Guy2")
wrestler1 = Wrestler.where("name = ?", "Guy2").first wrestler1 = Wrestler.where("name = ?", "Guy2").first
assert_equal 2, wrestler1.teamPointsEarned assert_equal 2, wrestler1.teamPointsEarned
end end
@@ -570,19 +555,19 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "Championship bracket wins are 2pts" do test "Championship bracket wins are 2pts" do
elevenManBracketToQuarter elevenManBracketToQuarter
assert_equal 7, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned assert_equal 7, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned
matches = @matches
endMatch(4006,"Guy11",matches) endMatch(4006,"Guy11")
assert_equal 15, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned assert_equal 15, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned
endMatch(4007,"Guy14",matches) endMatch(4007,"Guy14")
endMatch(5004,"Guy11",matches) endMatch(5004,"Guy11")
assert_equal 20, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned assert_equal 20, Wrestler.where("name = ?", "Guy11").first.teamPointsEarned
end end
test "Conso bracket wins are 1pt" do test "Conso bracket wins are 1pt" do
elevenManBracketToSemis elevenManBracketToSemis
assert_equal 5, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned assert_equal 5, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned
matches = @matches
endMatch(5006,"Guy17",matches) endMatch(5006,"Guy17")
assert_equal 9, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned assert_equal 9, Wrestler.where("name = ?", "Guy17").first.teamPointsEarned
end end

View File

@@ -1,8 +1,60 @@
require 'test_helper' require 'test_helper'
class SingleTestTest < ActionDispatch::IntegrationTest class SingleTestTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(1)
# @tournament.generateMatchups
# @matches = @tournament.matches
end
#rake test test/integration/single_test_test.rb > matches.txt
# Loser names need to be in quotes in yml file
def showMatches
# matches = Weight.where("id = ?", 4).first.matches
count = 1
# Yml for matches
# Match.where(tournament_id: 1).each do |m|
# puts "tournament_1_bout_#{m.bout_number}:"
# puts " tournament_id: #{m.tournament_id}"
# puts " weight_id: #{m.weight_id}"
# puts " bout_number: #{m.bout_number}"
# puts " w1: #{m.w1}"
# puts " w2: #{m.w2}"
# puts " bracket_position: #{m.bracket_position}"
# puts " bracket_position_number: #{m.bracket_position_number}"
# puts " loser1_name: #{m.loser1_name}"
# puts " loser2_name: #{m.loser2_name}"
# puts " round: #{m.round}"
# puts " mat_id: #{m.mat_id}"
# puts " finished: #{m.finished}"
# puts " w1_stat: "
# puts " w2_stat: "
# puts " score: "
# puts " winner_id: "
# puts " win_type: "
# puts ""
# count += 1
# end
# Yml for wrestlers
# @tournament.wrestlers.each do |w|
# puts "tournament_1_#{w.name}:"
# puts " id: #{count}"
# puts " name: #{w.name}"
# puts " school_id: #{w.school_id}"
# puts " weight_id: #{w.weight_id}"
# puts " original_seed: #{w.original_seed}"
# puts " season_loss: #{w.season_loss}"
# puts " season_win: #{w.season_win}"
# puts " criteria: #{w.criteria}"
# puts ""
# count += 1
# end
end
test "the truth" do test "the truth" do
showMatches
assert true assert true
end end
end end

View File

@@ -1,6 +1,7 @@
require 'test_helper' require 'test_helper'
class TournamentTest < ActiveSupport::TestCase class TournamentTest < ActiveSupport::TestCase
test "the truth" do test "the truth" do
assert true assert true
end end