diff --git a/test/integration/baumspage_importer_test.rb b/test/integration/baumspage_importer_test.rb index 071a1d8..83a70fb 100644 --- a/test/integration/baumspage_importer_test.rb +++ b/test/integration/baumspage_importer_test.rb @@ -2,7 +2,9 @@ require 'test_helper' class BaumspageImporterTest < ActionDispatch::IntegrationTest 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 ***** Some School Some Guy diff --git a/test/integration/eight_pool_match_generation_test.rb b/test/integration/eight_pool_match_generation_test.rb index 87850d9..cf81421 100644 --- a/test/integration/eight_pool_match_generation_test.rb +++ b/test/integration/eight_pool_match_generation_test.rb @@ -2,11 +2,10 @@ require 'test_helper' class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest def setup - @tournament = Tournament.find(4) + create_pool_tournament_single_weight(24) end test "Match generation works" do - GenerateTournamentMatches.new(@tournament).generate assert @tournament.matches.count == 36 assert @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count == 4 assert @tournament.matches.select{|m| m.bracket_position == "Semis"}.count == 2 @@ -20,16 +19,15 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest end test "Seeded wrestlers go to correct pool" do - GenerateTournamentMatches.new(@tournament).generate - guy10 = @tournament.wrestlers.select{|w| w.name == "Guy10"}.first - guy2 = @tournament.wrestlers.select{|w| w.name == "Guy2"}.first - guy3 = @tournament.wrestlers.select{|w| w.name == "Guy3"}.first - guy4 = @tournament.wrestlers.select{|w| w.name == "Guy4"}.first - guy5 = @tournament.wrestlers.select{|w| w.name == "Guy5"}.first - guy6 = @tournament.wrestlers.select{|w| w.name == "Guy6"}.first - guy7 = @tournament.wrestlers.select{|w| w.name == "Guy7"}.first - guy8 = @tournament.wrestlers.select{|w| w.name == "Guy8"}.first - assert guy10.pool == 1 + guy1 = get_wrestler_by_name("Test1") + guy2 = get_wrestler_by_name("Test2") + guy3 = get_wrestler_by_name("Test3") + guy4 = get_wrestler_by_name("Test4") + guy5 = get_wrestler_by_name("Test5") + guy6 = get_wrestler_by_name("Test6") + guy7 = get_wrestler_by_name("Test7") + guy8 = get_wrestler_by_name("Test8") + assert guy1.pool == 1 assert guy2.pool == 2 assert guy3.pool == 3 assert guy4.pool == 4 @@ -40,7 +38,6 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest end 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.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" @@ -62,16 +59,14 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest end test "Each wrestler has two pool matches" do - GenerateTournamentMatches.new(@tournament).generate @tournament.wrestlers.each do |wrestler| assert wrestler.pool_matches.size == 2 end end test "Placement points are given when moving through bracket" do - GenerateTournamentMatches.new(@tournament).generate 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.save assert wrestler.reload.placement_points == 3 @@ -83,7 +78,6 @@ class EightPoolMatchGenerationTest < ActionDispatch::IntegrationTest end test "Run through all matches works" do - GenerateTournamentMatches.new(@tournament).generate @tournament.matches.sort{ |match| match.round }.each do |match| match.winner_id = match.w1 match.save diff --git a/test/integration/eight_pool_to_four_pool_changes_test.rb b/test/integration/eight_pool_to_four_pool_changes_test.rb index 997b832..159e978 100644 --- a/test/integration/eight_pool_to_four_pool_changes_test.rb +++ b/test/integration/eight_pool_to_four_pool_changes_test.rb @@ -2,11 +2,10 @@ require 'test_helper' class EightPoolToFourPoolChangesTest < ActionDispatch::IntegrationTest def setup - @tournament = Tournament.find(4) + create_pool_tournament_single_weight(24) end 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.weights.first.pools == 8 count = 1 diff --git a/test/integration/single_test_test.rb b/test/integration/single_test_test.rb deleted file mode 100644 index e0a7f59..0000000 --- a/test/integration/single_test_test.rb +++ /dev/null @@ -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 diff --git a/test/integration/swap_wrestlers_test.rb b/test/integration/swap_wrestlers_test.rb index 1afcae1..020891f 100644 --- a/test/integration/swap_wrestlers_test.rb +++ b/test/integration/swap_wrestlers_test.rb @@ -2,27 +2,31 @@ require 'test_helper' class SwapWrestlersTest < ActionDispatch::IntegrationTest def setup - @tournament = tournaments(:swap_wrestlers_tournament) - GenerateTournamentMatches.new(@tournament).generate + create_pool_tournament_single_weight(8) end test "Wrestlers from different pools are swapped matches correctly" do - wrestler1 = wrestlers(:swap_wrestlers_wrestler_1) - wrestler2 = wrestlers(:swap_wrestlers_wrestler_2) - wrestler3 = wrestlers(:swap_wrestlers_wrestler_3) - wrestler4 = wrestlers(:swap_wrestlers_wrestler_4) + wrestler1 = get_wrestler_by_name("Test1") + wrestler2 = get_wrestler_by_name("Test2") + wrestler3 = get_wrestler_by_name("Test3") + 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) #Variable needs refreshed otherwise asserts fail - wrestler1 = Wrestler.find(54) - wrestler2 = Wrestler.find(55) + wrestler1 = get_wrestler_by_name("Test1") + wrestler2 = get_wrestler_by_name("Test2") assert_not_empty wrestler1.match_against(wrestler3) 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_equal 1, wrestler2.pool - assert_equal 1, wrestler2.bracket_line + assert_equal test_line_wrestler1, wrestler2.bracket_line end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 354534b..2b2d4d6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -113,10 +113,9 @@ class ActiveSupport::TestCase for number in (1..number_of_wrestlers) do wrestler = Wrestler.new wrestler.name = "Test#{naming_number}" - school = @tournament.schools.sample wrestler.school_id = school.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 end wrestler.save