1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-05 06:07:20 +00:00

Moved a number of tests away from fixtures

This commit is contained in:
2019-04-19 11:53:59 -04:00
parent 1dfceda422
commit ff749df11d
6 changed files with 30 additions and 92 deletions

View File

@@ -2,7 +2,9 @@ require 'test_helper'
class BaumspageImporterTest < ActionDispatch::IntegrationTest class BaumspageImporterTest < ActionDispatch::IntegrationTest
def setup def setup
@school = School.find(1) create_pool_tournament
#Needs 106-126 or test will fail
@school = @tournament.schools.sample
@baums_text = "***** 2019-01-09 13:36:50 ***** @baums_text = "***** 2019-01-09 13:36:50 *****
Some School Some School
Some Guy Some Guy

View File

@@ -2,11 +2,10 @@ require 'test_helper'
class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest
def setup def setup
@tournament = Tournament.find(4) create_pool_tournament_single_weight(24)
end end
test "Match generation works" do test "Match generation works" do
GenerateTournamentMatches.new(@tournament).generate
assert @tournament.matches.count == 36 assert @tournament.matches.count == 36
assert @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count == 4 assert @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count == 4
assert @tournament.matches.select{|m| m.bracket_position == "Semis"}.count == 2 assert @tournament.matches.select{|m| m.bracket_position == "Semis"}.count == 2
@@ -20,16 +19,15 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest
end end
test "Seeded wrestlers go to correct pool" do test "Seeded wrestlers go to correct pool" do
GenerateTournamentMatches.new(@tournament).generate guy1 = get_wrestler_by_name("Test1")
guy10 = @tournament.wrestlers.select{|w| w.name == "Guy10"}.first guy2 = get_wrestler_by_name("Test2")
guy2 = @tournament.wrestlers.select{|w| w.name == "Guy2"}.first guy3 = get_wrestler_by_name("Test3")
guy3 = @tournament.wrestlers.select{|w| w.name == "Guy3"}.first guy4 = get_wrestler_by_name("Test4")
guy4 = @tournament.wrestlers.select{|w| w.name == "Guy4"}.first guy5 = get_wrestler_by_name("Test5")
guy5 = @tournament.wrestlers.select{|w| w.name == "Guy5"}.first guy6 = get_wrestler_by_name("Test6")
guy6 = @tournament.wrestlers.select{|w| w.name == "Guy6"}.first guy7 = get_wrestler_by_name("Test7")
guy7 = @tournament.wrestlers.select{|w| w.name == "Guy7"}.first guy8 = get_wrestler_by_name("Test8")
guy8 = @tournament.wrestlers.select{|w| w.name == "Guy8"}.first assert guy1.pool == 1
assert guy10.pool == 1
assert guy2.pool == 2 assert guy2.pool == 2
assert guy3.pool == 3 assert guy3.pool == 3
assert guy4.pool == 4 assert guy4.pool == 4
@@ -40,7 +38,6 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest
end end
test "Loser names set up correctly" do test "Loser names set up correctly" do
GenerateTournamentMatches.new(@tournament).generate
assert @tournament.matches.select{|m| m.bracket_position == "Quarter" && m.bracket_position_number == 1}.first.loser1_name == "Winner Pool 1" assert @tournament.matches.select{|m| m.bracket_position == "Quarter" && m.bracket_position_number == 1}.first.loser1_name == "Winner Pool 1"
assert @tournament.matches.select{|m| m.bracket_position == "Quarter" && m.bracket_position_number == 1}.first.loser2_name == "Winner Pool 8" assert @tournament.matches.select{|m| m.bracket_position == "Quarter" && m.bracket_position_number == 1}.first.loser2_name == "Winner Pool 8"
assert @tournament.matches.select{|m| m.bracket_position == "Quarter" && m.bracket_position_number == 2}.first.loser1_name == "Winner Pool 4" assert @tournament.matches.select{|m| m.bracket_position == "Quarter" && m.bracket_position_number == 2}.first.loser1_name == "Winner Pool 4"
@@ -62,16 +59,14 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest
end end
test "Each wrestler has two pool matches" do test "Each wrestler has two pool matches" do
GenerateTournamentMatches.new(@tournament).generate
@tournament.wrestlers.each do |wrestler| @tournament.wrestlers.each do |wrestler|
assert wrestler.pool_matches.size == 2 assert wrestler.pool_matches.size == 2
end end
end end
test "Placement points are given when moving through bracket" do test "Placement points are given when moving through bracket" do
GenerateTournamentMatches.new(@tournament).generate
match = @tournament.matches.select{|m| m.bracket_position == "Quarter"}.first match = @tournament.matches.select{|m| m.bracket_position == "Quarter"}.first
wrestler = @tournament.wrestlers.select{|w| w.name == "Guy10"}.first wrestler = get_wrestler_by_name("Test1")
match.w1 = wrestler.id match.w1 = wrestler.id
match.save match.save
assert wrestler.reload.placement_points == 3 assert wrestler.reload.placement_points == 3
@@ -83,7 +78,6 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest
end end
test "Run through all matches works" do test "Run through all matches works" do
GenerateTournamentMatches.new(@tournament).generate
@tournament.matches.sort{ |match| match.round }.each do |match| @tournament.matches.sort{ |match| match.round }.each do |match|
match.winner_id = match.w1 match.winner_id = match.w1
match.save match.save

View File

@@ -2,11 +2,10 @@ require 'test_helper'
class EightPoolToFourPoolChangesTest < ActionDispatch::IntegrationTest class EightPoolToFourPoolChangesTest < ActionDispatch::IntegrationTest
def setup def setup
@tournament = Tournament.find(4) create_pool_tournament_single_weight(24)
end end
test "All wrestlers get matches after a weight switches from 8 pool to 4 pool" do test "All wrestlers get matches after a weight switches from 8 pool to 4 pool" do
GenerateTournamentMatches.new(@tournament).generate
assert @tournament.matches.count == 36 assert @tournament.matches.count == 36
assert @tournament.weights.first.pools == 8 assert @tournament.weights.first.pools == 8
count = 1 count = 1

View File

@@ -1,60 +0,0 @@
require 'test_helper'
class SingleTestTest < ActionDispatch::IntegrationTest
def setup
@tournament = Tournament.find(1)
# GenerateTournamentMatches.new(@tournament).generate
end
#rake test test/integration/single_test_test.rb > matches.txt
def showMatches
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_wrestler_#{count}:"
# 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 " bracket_line: #{w.bracket_line}"
# puts " season_loss: #{w.season_loss}"
# puts " season_win: #{w.season_win}"
# puts " criteria: #{w.criteria}"
# puts " extra: #{w.extra}"
# puts " pool: #{w.pool}"
# puts ""
# count += 1
# end
end
test "the truth" do
showMatches
assert true
end
end

View File

@@ -2,27 +2,31 @@ require 'test_helper'
class SwapWrestlersTest < ActionDispatch::IntegrationTest class SwapWrestlersTest < ActionDispatch::IntegrationTest
def setup def setup
@tournament = tournaments(:swap_wrestlers_tournament) create_pool_tournament_single_weight(8)
GenerateTournamentMatches.new(@tournament).generate
end end
test "Wrestlers from different pools are swapped matches correctly" do test "Wrestlers from different pools are swapped matches correctly" do
wrestler1 = wrestlers(:swap_wrestlers_wrestler_1) wrestler1 = get_wrestler_by_name("Test1")
wrestler2 = wrestlers(:swap_wrestlers_wrestler_2) wrestler2 = get_wrestler_by_name("Test2")
wrestler3 = wrestlers(:swap_wrestlers_wrestler_3) wrestler3 = get_wrestler_by_name("Test3")
wrestler4 = wrestlers(:swap_wrestlers_wrestler_4) wrestler4 = get_wrestler_by_name("Test4")
#Set original bracket lines
test_line_wrestler1 = wrestler1.bracket_line
test_line_wrestler2 = wrestler2.bracket_line
SwapWrestlers.new.swap_wrestlers_bracket_lines(wrestler1.id,wrestler2.id) SwapWrestlers.new.swap_wrestlers_bracket_lines(wrestler1.id,wrestler2.id)
#Variable needs refreshed otherwise asserts fail #Variable needs refreshed otherwise asserts fail
wrestler1 = Wrestler.find(54) wrestler1 = get_wrestler_by_name("Test1")
wrestler2 = Wrestler.find(55) wrestler2 = get_wrestler_by_name("Test2")
assert_not_empty wrestler1.match_against(wrestler3) assert_not_empty wrestler1.match_against(wrestler3)
assert_equal 2, wrestler1.pool assert_equal 2, wrestler1.pool
assert_equal 2, wrestler1.bracket_line assert_equal test_line_wrestler2, wrestler1.bracket_line
assert_not_empty wrestler2.match_against(wrestler4) assert_not_empty wrestler2.match_against(wrestler4)
assert_equal 1, wrestler2.pool assert_equal 1, wrestler2.pool
assert_equal 1, wrestler2.bracket_line assert_equal test_line_wrestler1, wrestler2.bracket_line
end end
end end

View File

@@ -113,10 +113,9 @@ class ActiveSupport::TestCase
for number in (1..number_of_wrestlers) do for number in (1..number_of_wrestlers) do
wrestler = Wrestler.new wrestler = Wrestler.new
wrestler.name = "Test#{naming_number}" wrestler.name = "Test#{naming_number}"
school = @tournament.schools.sample
wrestler.school_id = school.id wrestler.school_id = school.id
wrestler.weight_id = weight.id wrestler.weight_id = weight.id
if seed <= 4 if (number_of_wrestlers <= 10 and seed <= 4) or (number_of_wrestlers > 10 and seed <= 8)
wrestler.original_seed = seed wrestler.original_seed = seed
end end
wrestler.save wrestler.save