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

Fixed double elim match generation errors and added tests

This commit is contained in:
2026-01-23 17:35:16 -05:00
parent c8764c149b
commit 86f9c03991
2 changed files with 74 additions and 59 deletions

View File

@@ -156,14 +156,14 @@ class Tournament < ApplicationRecord
def double_elim_number_of_wrestlers_error def double_elim_number_of_wrestlers_error
error_string = "" error_string = ""
if self.tournament_type == "Double Elimination 1-6" or self.tournament_type == "Double Elimination 1-8" if self.tournament_type == "Regular Double Elimination 1-6" or self.tournament_type == "Regular Double Elimination 1-8"
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 64} weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 64}
weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 4} weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 2}
weights_with_too_many_wrestlers.each do |weight| weights_with_too_many_wrestlers.each do |weight|
error_string = error_string + " The weight class #{weight.max} has more than 64 wrestlers." error_string = error_string + " The weight class #{weight.max} has more than 64 wrestlers."
end end
weight_with_too_few_wrestlers.each do |weight| weight_with_too_few_wrestlers.each do |weight|
error_string = error_string + " The weight class #{weight.max} has less than 4 wrestlers." error_string = error_string + " The weight class #{weight.max} has less than 2 wrestlers."
end end
end end
return error_string return error_string

View File

@@ -14,77 +14,92 @@ class TournamentTest < ActiveSupport::TestCase
# Pool to bracket match_generation_error # Pool to bracket match_generation_error
test "Tournament pool to bracket match generation errors with less than two wrestlers" do 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", 1)
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers) assert_match("There is a tournament error.", @tournament.match_generation_error)
assert @tournament.match_generation_error != nil
end end
test "Tournament pool to bracket match generation errors with more than 24 wrestlers" do 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", 25)
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers) assert_match("There is a tournament error.", @tournament.match_generation_error)
assert @tournament.match_generation_error != nil
end end
test "Tournament pool to bracket no match generation errors with 24 wrestlers" do 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", 24)
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers) assert_nil @tournament.match_generation_error
assert @tournament.match_generation_error == nil
end end
test "Tournament pool to bracket no match generation errors with 2 wrestlers" do 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", 2)
create_a_tournament_with_single_weight("Pool to bracket", number_of_wrestlers) assert_nil @tournament.match_generation_error
assert @tournament.match_generation_error == nil
end end
# Modified 16 Man Double Elimination match_generation_error # Modified 16 Man Double Elimination match_generation_error
test "TournamentModified 16 Man Double Elimination match generation errors with less than 12 wrestlers" do test "Tournament modified 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", 11)
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers) assert_match("There is a tournament error.", @tournament.match_generation_error)
assert @tournament.match_generation_error != nil
end end
test "Tournament Modified 16 Man Double Elimination match generation errors with more than 16 wrestlers" do 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", 17)
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers) assert_match("There is a tournament error.", @tournament.match_generation_error)
assert @tournament.match_generation_error != nil
end end
test "Tournament Modified 16 Man Double Elimination no match generation errors with 16 wrestlers" do 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", 16)
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers) assert_nil @tournament.match_generation_error
assert @tournament.match_generation_error == nil
end end
test "Tournament Modified 16 Man Double Elimination no match generation errors with 12 wrestlers" do 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", 12)
create_a_tournament_with_single_weight("Modified 16 Man Double Elimination", number_of_wrestlers) assert_nil @tournament.match_generation_error
assert @tournament.match_generation_error == nil
end end
# Double Elimination match_generation_error # Double Elimination match_generation_error
test "Tournament Double Elimination 1-8 match generation errors with less than 4 wrestlers" do test "Tournament regular double elimination 1-8 match generation errors with less than 2 wrestlers" do
number_of_wrestlers=3 create_a_tournament_with_single_weight("Regular Double Elimination 1-8", 1)
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers) assert_match("There is a tournament error.", @tournament.match_generation_error)
assert @tournament.match_generation_error != nil
end end
test "Tournament Double Elimination 1-8 match generation errors with more than 64 wrestlers" do test "Tournament regular double elimination 1-8 match generation errors with more than 64 wrestlers" do
number_of_wrestlers=65 create_a_tournament_with_single_weight("Regular Double Elimination 1-8", 65)
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers) assert_match("There is a tournament error.", @tournament.match_generation_error)
assert @tournament.match_generation_error != nil
end end
test "Tournament Double Elimination 1-8 no match generation errors with 16 wrestlers" do test "Tournament regular double elimination 1-8 no match generation errors with 64 wrestlers" do
number_of_wrestlers=16 create_a_tournament_with_single_weight("Regular Double Elimination 1-8", 64)
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers) assert_nil @tournament.match_generation_error
assert @tournament.match_generation_error == nil
end end
test "Tournament Double Elimination 1-8 no match generation errors with 4 wrestlers" do test "Tournament regular double elimination 1-8 no match generation errors with 2 wrestlers" do
number_of_wrestlers=4 create_a_tournament_with_single_weight("Regular Double Elimination 1-8", 2)
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers) assert_nil @tournament.match_generation_error
assert @tournament.match_generation_error == nil end
test "Tournament match generation errors when a wrestler seed exceeds bracket size" do
create_a_tournament_with_single_weight("Pool to bracket", 4)
@tournament.weights.first.wrestlers.first.update!(original_seed: 8)
assert_match("There is a tournament error.", @tournament.match_generation_error)
assert_match("greater than the amount of wrestlers", @tournament.match_generation_error)
end
test "Tournament match generation errors when duplicate original seeds are present" do
create_a_tournament_with_single_weight("Pool to bracket", 4)
wrestlers = @tournament.weights.first.wrestlers.order(:id)
wrestlers.first.update!(original_seed: 2)
wrestlers.second.update!(original_seed: 2)
assert_match("There is a tournament error.", @tournament.match_generation_error)
assert_match("seeded 2", @tournament.match_generation_error)
end
test "Tournament match generation errors when original seeds are out of order" do
create_a_tournament_with_single_weight("Pool to bracket", 4)
wrestlers = @tournament.weights.first.wrestlers.order(:id)
wrestlers.first.update!(original_seed: 1)
wrestlers.second.update!(original_seed: 3)
wrestlers.third.update!(original_seed: nil)
wrestlers.fourth.update!(original_seed: nil)
assert_match("There is a tournament error.", @tournament.match_generation_error)
assert_match("out-of-order seeds", @tournament.match_generation_error)
end end
## End match_generation_error tests ## End match_generation_error tests