Skip to content

Commit

Permalink
extra resources
Browse files Browse the repository at this point in the history
  • Loading branch information
flamontagne committed Sep 25, 2011
1 parent af889b9 commit f86b140
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
14 changes: 14 additions & 0 deletions lib/rrschedule.rb
Expand Up @@ -242,6 +242,20 @@ def dispatch_game(game)

@cur_date ||= next_game_date(self.start_date,@cur_rule.wday)
@schedule ||= []

#if one of the team has already plays at this gamedate, we change rule
if @schedule.size>0
games_this_date = @schedule.select{|v| v[:gamedate] == @cur_date}
if games_this_date.select{|g| [game.team_a,game.team_b].include?(g[:team_a]) || [game.team_a,game.team_b].include?(g[:team_b])}.size >0
@cur_rule_index = (@cur_rule_index < @rules.size-1) ? @cur_rule_index+1 : 0
@cur_rule = @rules[@cur_rule_index]
@gt_stack = @cur_rule.gt.clone
@ps_stack = @cur_rule.ps.clone.shuffle
@cur_gt = @gt_stack.shift
@cur_ps = @ps_stack.shift
@cur_date = next_game_date(@cur_date+=1,@cur_rule.wday)
end
end

@schedule << {:team_a => game.team_a, :team_b => game.team_b, :gamedate => @cur_date, :ps => @cur_ps, :gt => @cur_gt}

Expand Down
56 changes: 28 additions & 28 deletions test/test_rrschedule.rb
Expand Up @@ -47,34 +47,34 @@ class TestRrschedule < Test::Unit::TestCase
end


# context "extra available resources" do
# setup do
# @s = Schedule.new(
# :teams => %w(a1 a2 a3 a4 a5),
# :rules => [
# Rule.new(
# :wday => 3,
# :gt => ["7:00PM", "9:00PM"],
# :ps => %w(one two three four)
# )
# ]
# ).generate
# end

# should "have a maximum of (teams/2) games per day" do
# @s.gamedays.each do |gd|
# assert gd.games.size <= @s.teams.size/2
# end
# end

# should "not have a team that play more than once on a single day" do
# @s.gamedays.each do |gd|
# day_teams = gd.games.collect{|g| [g.team_a,g.team_b]}.flatten
# unique_day_teams = day_teams.uniq
# assert_equal day_teams.size, unique_day_teams.size
# end
# end
# end
context "extra available resources" do
setup do
@s = Schedule.new(
:teams => %w(a1 a2 a3 a4 a5),
:rules => [
Rule.new(
:wday => 3,
:gt => ["7:00PM", "9:00PM"],
:ps => %w(one two three four)
)
]
).generate
end

should "have a maximum of (teams/2) games per day" do
@s.gamedays.each do |gd|
assert gd.games.size <= @s.teams.size/2
end
end

should "not have a team that play more than once on a single day" do
@s.gamedays.each do |gd|
day_teams = gd.games.collect{|g| [g.team_a,g.team_b]}.flatten
unique_day_teams = day_teams.uniq
assert_equal day_teams.size, unique_day_teams.size
end
end
end


context "multi flights" do
Expand Down

0 comments on commit f86b140

Please sign in to comment.