From 67727c6391a9d162045147576a2741ac29eef990 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Tue, 17 Nov 2015 19:03:34 +0000 Subject: [PATCH] Testing team points for pool to bracket --- app/models/match.rb | 10 +- app/models/wrestler.rb | 4 + db/schema.rb | 4 +- test/integration/pool_advancement_test.rb | 111 +++++++++++++++++++++- 4 files changed, 121 insertions(+), 8 deletions(-) diff --git a/app/models/match.rb b/app/models/match.rb index 8ed960a..6e00039 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -7,13 +7,19 @@ class Match < ActiveRecord::Base after_save do if self.finished == 1 advance_wrestlers - self.wrestler1.school.calcScore - self.wrestler2.school.calcScore + calcSchoolPoints end end WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ"] + def calcSchoolPoints + if self.w1? && self.w2? + wrestler1.school.calcScore + wrestler2.school.calcScore + end + end + def advance_wrestlers if self.w1? && self.w2? @w1 = wrestler1 diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 408f267..8188f93 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -15,6 +15,10 @@ class Wrestler < ActiveRecord::Base end def totalTeamPoints + teamPointsEarned - totalDeductedPoints + end + + def teamPointsEarned points = 0.0 points = points + (poolWins.size * 1) + (pinWins.size * 2) + (techWins.size * 1.5) + (majorWins.size * 1) + placementPoints end diff --git a/db/schema.rb b/db/schema.rb index 02f837f..30e61b4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,7 +37,7 @@ ActiveRecord::Schema.define(version: 20151117152454) do add_index "matches", ["mat_id"], name: "index_matches_on_mat_id" add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id" - add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2", unique: true + add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2" create_table "mats", force: :cascade do |t| t.string "name" @@ -80,7 +80,6 @@ ActiveRecord::Schema.define(version: 20151117152454) do end add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id" - add_index "tournaments", ["weigh_in_ref"], name: "index_tournaments_on_weigh_in_ref" create_table "users", force: :cascade do |t| t.string "email", default: "", null: false @@ -124,7 +123,6 @@ ActiveRecord::Schema.define(version: 20151117152454) do t.decimal "offical_weight" end - add_index "wrestlers", ["offical_weight"], name: "index_wrestlers_on_offical_weight" add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id" end diff --git a/test/integration/pool_advancement_test.rb b/test/integration/pool_advancement_test.rb index b2ab134..90d9dee 100644 --- a/test/integration/pool_advancement_test.rb +++ b/test/integration/pool_advancement_test.rb @@ -14,7 +14,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest end end - def nineManBracketPoolOneOutrightWinner + def nineManBracketPoolOneOutrightWinnerGuyTwo matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"} endMatch(1002,"Guy8",matches) endMatch(1003,"Guy10",matches) @@ -150,13 +150,13 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest end test "nine man outright finals advance" do - nineManBracketPoolOneOutrightWinner + nineManBracketPoolOneOutrightWinnerGuyTwo wrestler = Wrestler.where("name = ?", "Guy2").first assert_equal 6000, wrestler.boutByRound(6) end test "nine man outright conso finals advance" do - nineManBracketPoolOneOutrightWinner + nineManBracketPoolOneOutrightWinnerGuyTwo wrestler = Wrestler.where("name = ?", "Guy8").first assert_equal 6001, wrestler.boutByRound(6) end @@ -233,4 +233,109 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest assert_equal 6001, wrestler.boutByRound(6) end + test "twoPoolsToFinal total points finals" do + nineManBracketPoolOneOutrightWinnerGuyTwo + nineManBracketPoolTwoGuyThreeHeadToHead + wrestler1 = Wrestler.where("name = ?", "Guy2").first + wrestler2 = Wrestler.where("name = ?", "Guy3").first + #Won four in pool + assert_equal 16, wrestler1.totalTeamPoints + #Won two in pool but was deducted a point + assert_equal 13, wrestler2.totalTeamPoints + end + + test "advancement points 1/2" do + nineManBracketPoolOneOutrightWinnerGuyTwo + wrestler1 = Wrestler.where("name = ?", "Guy2").first + assert_equal 12, wrestler1.placementPoints + end + + test "advancement points 3/4" do + nineManBracketPoolOneOutrightWinnerGuyTwo + wrestler1 = Wrestler.where("name = ?", "Guy8").first + assert_equal 9, wrestler1.placementPoints + end + + test "advancement points 5/6" do + + end + + test "advancement points 7/8" do + + end + + test "advancement points winner 1/2" do + nineManBracketPoolOneOutrightWinnerGuyTwo + nineManBracketPoolTwoGuyThreeHeadToHead + endMatch(6000,"Guy2",@tournament.matches) + wrestler1 = Wrestler.where("name = ?", "Guy2").first + assert_equal 16, wrestler1.placementPoints + end + + test "advancement points winner 3/4" do + nineManBracketPoolOneOutrightWinnerGuyTwo + nineManBracketPoolTwoGuyThreeHeadToHead + endMatch(6001,"Guy8",@tournament.matches) + wrestler1 = Wrestler.where("name = ?", "Guy8").first + assert_equal 10, wrestler1.placementPoints + end + + test "advancement points winner 5/6" do + + end + + test "advancement points winner 7/8" do + + end + + test "bonus points major" do + endMatchWithMajor(2002,"Guy2",@tournament.matches) + wrestler1 = Wrestler.where("name = ?", "Guy2").first + assert_equal 2, wrestler1.teamPointsEarned + end + + test "bonus points pin" do + endMatchWithPin(2002,"Guy2",@tournament.matches) + wrestler1 = Wrestler.where("name = ?", "Guy2").first + assert_equal 3, wrestler1.teamPointsEarned + end + + test "bonus points tech fall" do + endMatchWithTech(2002,"Guy2",@tournament.matches) + wrestler1 = Wrestler.where("name = ?", "Guy2").first + assert_equal 2.5, wrestler1.teamPointsEarned + end + + test "pool team points win" do + endMatch(2002,"Guy2",@tournament.matches) + wrestler1 = Wrestler.where("name = ?", "Guy2").first + assert_equal 1, wrestler1.teamPointsEarned + end + + test "advancement points fourPoolsToQuarter Quarter" do + + end + + test "advancement points fourPoolsToQuarter Semis" do + + end + + test "advancement points twoPoolsToSemi Semis" do + + end + + test "advancement points twoPoolsToSemi Conso Semis" do + + end + + test "advancement points fourPoolsToSemi Semis" do + + end + + test "advancement points fourPoolsToSemi Conso Semis" do + + end + + + end