test/test_rrschedule.rb in rrschedule-0.1.6 vs test/test_rrschedule.rb in rrschedule-0.1.7

- old
+ new

@@ -7,30 +7,25 @@ assert schedule.teams.size > 2 assert_equal 1, schedule.cycles assert schedule.game_times.respond_to?(:to_ary) assert schedule.playing_surfaces.respond_to?(:to_ary) - assert schedule.start_date.respond_to?(:to_date) + assert schedule.start_date.is_a?(Date) assert schedule.shuffle_initial_order + assert schedule.optimize assert schedule.wdays.select{|w| (0..6).member? w} == schedule.wdays assert schedule.exclude_dates.empty? end should "have a dummy team when number of teams is odd" do - schedule = RRSchedule::Schedule.new( - :teams => Array(1..9) - ) - + schedule = RRSchedule::Schedule.new(:teams => Array(1..9)) assert schedule.teams.size == 10 assert schedule.teams.member?(:dummy), "There should always be a :dummy team when the nbr of teams is odd" end should "not have a dummy team when number of teams is even" do - schedule = RRSchedule::Schedule.new( - :teams => Array(1..6) - ) - + schedule = RRSchedule::Schedule.new(:teams => Array(1..6)) assert schedule.teams.size == 6 assert !schedule.teams.member?(:dummy), "There should never be a :dummy team when the nbr of teams is even" end should "not have a team named :dummy in the initial array" do @@ -94,56 +89,75 @@ :teams => %w(a b c d e f g h i j l m), :playing_surfaces => %w(one two), :game_times => ["10:00 AM", "13:00 PM"] ) end - + should "have gamedays that respect the wdays attribute" do @s.wdays = [3,5] @s.generate - + @s.gamedays.each do |gd| assert [3,5].include?(gd.date.wday), "wday is #{gd.date.wday.to_s} but should be 3 or 5" end - end - end - - context "A generated schedule with an odd number of teams" do - setup do - @s = RRSchedule::Schedule.new( - :teams => %w(a b c d e f g h i j l), - :playing_surfaces => %w(one two), - :game_times => ["10:00 AM", "13:00 PM"] - ).generate - end + end - should "be a valid round-robin" do - assert @s.round_robin? + context "with the option optimize set to true" do + should "have at most (playing_surfaces*game_times) games per gameday" do + @s.generate + assert @s.gamedays.first.games.size == (@s.playing_surfaces.size * @s.game_times.size) + end end - should "not have any :dummy teams in the final schedule" do - assert @s.gamedays.collect{|gd| gd.games}.flatten.select{ - |g| [g.team_a,g.team_b].include?(:dummy) - }.size == 0 + context "with the option optimize set to false" do + setup do + @s.optimize = false + end + + should "never have more than (number of teams / 2) games per gameday" do + @s.teams = %w(only four teams here) + @s.generate + assert @s.gamedays.first.games.size == @s.teams.size / 2 + end end - end - - context "A generated schedule with an even number of teams" do - setup do - @s = RRSchedule::Schedule.new( - :teams => %w(a b c d e f g h i j l m), - :playing_surfaces => %w(one two), - :game_times => ["10:00 AM", "13:00 PM"] - ).generate - end - should "be a valid round-robin" do - assert @s.round_robin? + context "with an odd number of teams" do + setup do + @s = RRSchedule::Schedule.new( + :teams => %w(a b c d e f g h i j l), + :playing_surfaces => %w(one two), + :game_times => ["10:00 AM", "13:00 PM"] + ).generate + end + + should "be a valid round-robin" do + assert @s.round_robin? + end + + should "not have any :dummy teams in the final schedule" do + assert @s.gamedays.collect{|gd| gd.games}.flatten.select{ + |g| [g.team_a,g.team_b].include?(:dummy) + }.size == 0 + end end - should "not have any :dummy teams in the final schedule" do - assert @s.gamedays.collect{|gd| gd.games}.flatten.select{ - |g| [g.team_a,g.team_b].include?(:dummy) - }.size == 0 - end - end + context "with an even number of teams" do + setup do + @s = RRSchedule::Schedule.new( + :teams => %w(a b c d e f g h i j l m), + :playing_surfaces => %w(one two), + :game_times => ["10:00 AM", "13:00 PM"] + ).generate + end + + should "be a valid round-robin" do + assert @s.round_robin? + end + + should "not have any :dummy teams in the final schedule" do + assert @s.gamedays.collect{|gd| gd.games}.flatten.select{ + |g| [g.team_a,g.team_b].include?(:dummy) + }.size == 0 + end + end + end end