1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

Added safeguards for generating pool matches along with tests, updated two errors on about page, and added time saver to create middle school weights

This commit is contained in:
2023-01-24 22:56:22 +00:00
parent 1d0cff0e6f
commit c133a8b051
6 changed files with 131 additions and 23 deletions

View File

@@ -128,17 +128,19 @@ end
end
end
def pool_to_bracket_weights_with_too_many_wrestlers
if self.tournament_type == "Pool to bracket"
weightsWithTooManyWrestlers = weights.select{|w| w.wrestlers.size > 24}
if weightsWithTooManyWrestlers.size < 1
return nil
else
return weightsWithTooManyWrestlers
end
else
nil
end
def pool_to_bracket_number_of_wrestlers
error_string = ""
if self.tournament_type.include? "Pool to bracket"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 24}
weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 2}
weights_with_too_many_wrestlers.each do |weight|
error_string = error_string + " The weight class #{weight.max} has more than 24 wrestlers."
end
weight_with_too_few_wrestlers.each do |weight|
error_string = error_string + " The weight class #{weight.max} has less than 2 wrestlers."
end
end
return error_string
end
def modified_sixteen_man_number_of_wrestlers
@@ -158,7 +160,7 @@ end
def double_elim_number_of_wrestlers
error_string = ""
if self.tournament_type == "Double Elimination 1-6"
if self.tournament_type == "Double Elimination 1-6" or self.tournament_type == "Double Elimination 1-8"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 16}
weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 4}
weights_with_too_many_wrestlers.each do |weight|
@@ -174,14 +176,11 @@ end
def match_generation_error
error_string = "There is a tournament error."
modified_sixteen_man_error = modified_sixteen_man_number_of_wrestlers
double_elim_error = double_elim_number_of_wrestlers
if pool_to_bracket_weights_with_too_many_wrestlers != nil
error_string = error_string + " The following weights have too many wrestlers "
pool_to_bracket_weights_with_too_many_wrestlers.each do |w|
error_string = error_string + "#{w.max} "
end
return error_string
elsif modified_sixteen_man_error.length > 0
double_elim_error = double_elim_number_of_wrestlers
pool_to_bracket_error = pool_to_bracket_number_of_wrestlers
if pool_to_bracket_error.length > 0
return error_string + pool_to_bracket_error
elsif modified_sixteen_man_error.length > 0
return error_string + modified_sixteen_man_error
elsif double_elim_error.length > 0
return error_string + double_elim_error

View File

@@ -12,6 +12,7 @@ class Weight < ActiveRecord::Base
# tournament model runs the code via method create_pre_defined_weights
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,144,150,157,165,175,190,215,285"
HS_GIRLS_WEIGHT_CLASSES = "100,105,110,115,120,125,130,135,140,145,155,170,190,235"
MS_WEIGHT_CLASSES = "80,86,92,98,104,110,116,122,128,134,142,150,160,172,205,245"
before_destroy do
self.tournament.destroy_all_matches

View File

@@ -45,6 +45,7 @@
<li><strong>Time Savers</strong></li>
<li><%= link_to "Create Boys High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
<li><%= link_to "Create Girls High School Weights (101-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_GIRLS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
<li><%= link_to "Create Boys Middle School Weights (80-245)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::MS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
<li><strong>Tournament Actions</strong></li>
<li><%= link_to "Calculate Team Scores" , "/tournaments/#{@tournament.id}/calculate_team_scores", :method => :put %></li>
<li><%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' } %></li>

View File

@@ -36,7 +36,7 @@
<li>Most wins by tech fall</li>
<li>Most wins by major</li>
<li>Most points scored in decisions</li>
<li>Quickest pin</li>
<li>Total pin time accumulation</li>
<li>Coin flip</li>
</ul>
<p>If three wrestlers are tied, they will be put through this sequence until two wrestlers are left. Once two wrestlers are left, the pool runner up will be decided by head to head.</p>
@@ -53,8 +53,8 @@
<p>See placement points below (based on the largest bracket of the tournament)</p>
<h4>Pool Types</h4>
<ul>
<li>Single pool round robin - 2-5 wrestlers, place 1-4.</li>
<li>Two Pools of 4 (3 matches each) to a semi final bracket - 6-8 wrestlers, place 1-4.</li>
<li>Single pool round robin - 2-6 wrestlers, place 1-4.</li>
<li>Two Pools of 4 (3 matches each) to a semi final bracket - 7-8 wrestlers, place 1-4.</li>
<li>Two Pools of 5 (4 matches each) to a championship and 3rd/4th match - 8-10 wrestlers, place 1-4.</li>
<li>Four pools of 3 (2 matches each) to a quarter final bracket - 9-12 wrestlers, place 1-8.</li>
<li>Four pools of 4 (3 matches each) to a semi final bracket - 13-16 wrestlers, place 1-8.</li>

View File

@@ -12,6 +12,83 @@ class TournamentTest < ActiveSupport::TestCase
assert_equal [:date, :name, :tournament_type, :address, :director, :director_email], tourney.errors.attribute_names
end
# Pool to bracket match_generation_error
test "Tournament pool to bracket match generation errors with less than two wrestlers" do
number_of_wrestlers=1
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end
test "Tournament pool to bracket match generation errors with more than 24 wrestlers" do
number_of_wrestlers=25
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end
test "Tournament pool to bracket no match generation errors with 24 wrestlers" do
number_of_wrestlers=24
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers)
assert @tournament.match_generation_error == nil
end
test "Tournament pool to bracket no match generation errors with 2 wrestlers" do
number_of_wrestlers=2
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers)
assert @tournament.match_generation_error == nil
end
# Modified 16 Man Double Elimination match_generation_error
test "TournamentModified 16 Man Double Elimination match generation errors with less than 12 wrestlers" do
number_of_wrestlers=11
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end
test "Tournament Modified 16 Man Double Elimination match generation errors with more than 16 wrestlers" do
number_of_wrestlers=17
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end
test "Tournament Modified 16 Man Double Elimination no match generation errors with 16 wrestlers" do
number_of_wrestlers=16
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers)
assert @tournament.match_generation_error == nil
end
test "Tournament Modified 16 Man Double Elimination no match generation errors with 12 wrestlers" do
number_of_wrestlers=12
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers)
assert @tournament.match_generation_error == nil
end
# Double Elimination match_generation_error
test "Tournament Double Elimination 1-8 match generation errors with less than 4 wrestlers" do
number_of_wrestlers=3
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end
test "Tournament Double Elimination 1-8 match generation errors with more than 16 wrestlers" do
number_of_wrestlers=17
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers)
assert @tournament.match_generation_error != nil
end
test "Tournament Double Elimination 1-8 no match generation errors with 16 wrestlers" do
number_of_wrestlers=16
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers)
assert @tournament.match_generation_error == nil
end
test "Tournament Double Elimination 1-8 no match generation errors with 4 wrestlers" do
number_of_wrestlers=4
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers)
assert @tournament.match_generation_error == nil
end
## End match_generation_error tests
test "Tournament create_pre_defined_weights High School Boys Weights" do
tournament = Tournament.find(1)
tournament.create_pre_defined_weights(Weight::HS_WEIGHT_CLASSES.split(","))
@@ -28,6 +105,14 @@ class TournamentTest < ActiveSupport::TestCase
end
end
test "Tournament create_pre_defined_weights Middle School Boys Weights" do
tournament = Tournament.find(1)
tournament.create_pre_defined_weights(Weight::MS_WEIGHT_CLASSES.split(","))
Weight::MS_WEIGHT_CLASSES.split(",").each do |weight|
assert tournament.weights.select{|w| w.max == weight.to_i}.count == 1
end
end
test "Tournament search_date_name returns results for all terms separately and non case sensitive" do
tournament = Tournament.new
tournament.name = "League Test Tournament D1"

View File

@@ -12,6 +12,28 @@ class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
def create_a_tournament_with_single_weight(tournament_type, number_of_wrestlers)
@tournament = Tournament.new
@tournament.name = "Test Tournament"
@tournament.address = "some place"
@tournament.director = "some guy"
@tournament.director_email= "test@test.com"
@tournament.tournament_type = tournament_type
@tournament.date = "2015-12-30"
@tournament.is_public = true
@tournament.save
@school = School.new
@school.name = "Test"
@school.tournament_id = @tournament.id
@school.save
@weight = Weight.new
@weight.max = 106
@weight.tournament_id = @tournament.id
@weight.save
create_wrestlers_for_weight(@weight, @school, number_of_wrestlers, 1)
return @tournament
end
def create_pool_tournament_single_weight(number_of_wrestlers)
@tournament = Tournament.new