rrschedule 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -53
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rrschedule.rb +6 -2
- data/lib/rrschedule/version.rb +3 -0
- data/rrschedule.gemspec +31 -0
- metadata +47 -30
- data/VERSION +0 -1
- data/test/helper.rb +0 -10
- data/test/test_rrschedule.rb +0 -194
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 439b393f27ad028dfeb67335e73d5e67cf880059
|
4
|
+
data.tar.gz: 0459480cb024489b8e58a4b23bdd10477d6a3ba0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83ccd6ab973488999601024dcea8f152a280ace52edb1a0848dfc89bc7b6734a44f8914f1a6dfe0d346fd8266ac3ac587462c6910679057664238eb252f1f4ba
|
7
|
+
data.tar.gz: a26931770781aa184fae68ddaf487dd355b69b90bcca9644da9406910b1fd512def03491b09e75a404d19d428dfb5651869869b76893307a64a6f2238a8791de
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at flamontagne@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 François Lamontagne
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Rrschedule
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rrschedule`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rrschedule'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rrschedule
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rrschedule. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
CHANGED
@@ -1,53 +1,2 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "rrschedule"
|
8
|
-
gem.summary = %Q{Round-Robin schedule generator}
|
9
|
-
gem.description = %Q{This gem automate the process of creating a round-robin sport schedule.}
|
10
|
-
gem.email = "flamontagne@azanka.ca"
|
11
|
-
gem.homepage = "http://flamontagne.github.com/rrschedule"
|
12
|
-
gem.authors = ["flamontagne"]
|
13
|
-
#gem.add_dependency 'activesupport'
|
14
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'rake/testtask'
|
22
|
-
Rake::TestTask.new(:test) do |test|
|
23
|
-
test.libs << 'lib' << 'test'
|
24
|
-
test.pattern = 'test/**/test_*.rb'
|
25
|
-
test.verbose = true
|
26
|
-
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task :test => :check_dependencies
|
42
|
-
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "rrschedule #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :spec
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rrschedule"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rrschedule.rb
CHANGED
@@ -46,7 +46,7 @@ module RRSchedule
|
|
46
46
|
team_b = t.reverse!.shift
|
47
47
|
t.reverse!
|
48
48
|
|
49
|
-
x = [team_a,team_b]
|
49
|
+
x = (current_cycle % 2) == 0 ? [team_a,team_b] : [team_b,team_a]
|
50
50
|
|
51
51
|
matchup = {:team_a => x[0], :team_b => x[1]}
|
52
52
|
games << matchup
|
@@ -63,6 +63,8 @@ module RRSchedule
|
|
63
63
|
@rounds[flight_id] ||= []
|
64
64
|
@rounds[flight_id] << Round.new(
|
65
65
|
:round => current_round,
|
66
|
+
:cycle => current_cycle + 1,
|
67
|
+
:round_with_cycle => current_cycle * (teams.size-1) + current_round,
|
66
68
|
:flight => flight_id,
|
67
69
|
:games => games.collect { |g|
|
68
70
|
Game.new(
|
@@ -400,10 +402,12 @@ module RRSchedule
|
|
400
402
|
end
|
401
403
|
|
402
404
|
class Round
|
403
|
-
attr_accessor :round, :games
|
405
|
+
attr_accessor :round, :cycle, :round_with_cycle, :games, :flight
|
404
406
|
|
405
407
|
def initialize(params={})
|
406
408
|
self.round = params[:round]
|
409
|
+
self.cycle = params[:cycle]
|
410
|
+
self.round_with_cycle = params[:round_with_cycle]
|
407
411
|
self.flight = params[:flight]
|
408
412
|
self.games = params[:games] || []
|
409
413
|
end
|
data/rrschedule.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rrschedule/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rrschedule"
|
8
|
+
spec.version = RRSchedule::VERSION
|
9
|
+
spec.authors = ["François Lamontagne"]
|
10
|
+
spec.email = ["flamontagne@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "RRSchedule helps you create round-robin schedules"
|
13
|
+
spec.homepage = "https://github.com/flamontagne/rrschedule"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
end
|
metadata
CHANGED
@@ -1,72 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrschedule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- François Lamontagne
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '1.11'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
|
31
|
-
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- flamontagne@gmail.com
|
32
44
|
executables: []
|
33
45
|
extensions: []
|
34
|
-
extra_rdoc_files:
|
35
|
-
- LICENSE
|
36
|
-
- README.markdown
|
46
|
+
extra_rdoc_files: []
|
37
47
|
files:
|
38
|
-
- .document
|
48
|
+
- ".document"
|
49
|
+
- ".gitignore"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
39
52
|
- LICENSE
|
53
|
+
- LICENSE.txt
|
40
54
|
- README.markdown
|
55
|
+
- README.md
|
41
56
|
- Rakefile
|
42
|
-
-
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
43
59
|
- branches_info.markdown
|
44
60
|
- lib/rrschedule.rb
|
45
|
-
-
|
46
|
-
-
|
61
|
+
- lib/rrschedule/version.rb
|
62
|
+
- rrschedule.gemspec
|
47
63
|
- test_schedule.rb
|
48
|
-
homepage:
|
49
|
-
licenses:
|
64
|
+
homepage: https://github.com/flamontagne/rrschedule
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata:
|
68
|
+
allowed_push_host: https://rubygems.org
|
50
69
|
post_install_message:
|
51
70
|
rdoc_options: []
|
52
71
|
require_paths:
|
53
72
|
- lib
|
54
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
74
|
requirements:
|
57
|
-
- -
|
75
|
+
- - ">="
|
58
76
|
- !ruby/object:Gem::Version
|
59
77
|
version: '0'
|
60
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
79
|
requirements:
|
63
|
-
- -
|
80
|
+
- - ">="
|
64
81
|
- !ruby/object:Gem::Version
|
65
82
|
version: '0'
|
66
83
|
requirements: []
|
67
84
|
rubyforge_project:
|
68
|
-
rubygems_version:
|
85
|
+
rubygems_version: 2.5.1
|
69
86
|
signing_key:
|
70
|
-
specification_version:
|
71
|
-
summary:
|
87
|
+
specification_version: 4
|
88
|
+
summary: RRSchedule helps you create round-robin schedules
|
72
89
|
test_files: []
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.3
|
data/test/helper.rb
DELETED
data/test/test_rrschedule.rb
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'active_support/all'
|
3
|
-
class TestRrschedule < Test::Unit::TestCase
|
4
|
-
include RRSchedule
|
5
|
-
context "new instance without params" do
|
6
|
-
setup {@s= Schedule.new}
|
7
|
-
should "have default values for some options" do
|
8
|
-
assert_equal 1, @s.cycles
|
9
|
-
assert @s.shuffle
|
10
|
-
assert_equal Date.today, @s.start_date
|
11
|
-
assert_equal [], @s.exclude_dates
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "no teams" do
|
16
|
-
setup {@s = Schedule.new(:rules => [Rule.new(:wday => 1, :gt => ["7:00PM"], :ps => %w(one two))])}
|
17
|
-
should "raise an exception" do
|
18
|
-
exception = assert_raise(RuntimeError){@s.generate}
|
19
|
-
assert_equal "You need to specify at least 1 team", exception.message
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "no flight" do
|
24
|
-
setup{@s=Schedule.new(:teams => %w(1 2 3 4 5 6), :rules => some_rules)}
|
25
|
-
should "be wrapped into a single flight in the normalized array" do
|
26
|
-
@s.generate
|
27
|
-
assert_equal [%w(1 2 3 4 5 6)], @s.flights
|
28
|
-
end
|
29
|
-
|
30
|
-
should "not modify the original array" do
|
31
|
-
assert_equal %w(1 2 3 4 5 6), @s.teams
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "odd number of teams without flight" do
|
36
|
-
setup {@s=Schedule.new(:teams => %w(1 2 3 4 5),:rules => some_rules).generate}
|
37
|
-
should "add a dummy competitor in the created flight" do
|
38
|
-
assert_equal 1, @s.flights.size
|
39
|
-
assert_equal 6, @s.flights.first.size
|
40
|
-
assert @s.flights.first.include?(:dummy)
|
41
|
-
end
|
42
|
-
|
43
|
-
should "not modify the original array" do
|
44
|
-
assert_equal 5, @s.teams.size
|
45
|
-
assert !@s.teams.include?(:dummy)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
context "extra available resources" do
|
51
|
-
setup do
|
52
|
-
@s = Schedule.new(
|
53
|
-
:teams => %w(a1 a2 a3 a4 a5),
|
54
|
-
:rules => [
|
55
|
-
Rule.new(
|
56
|
-
:wday => 3,
|
57
|
-
:gt => ["7:00PM", "9:00PM"],
|
58
|
-
:ps => %w(one two three four)
|
59
|
-
)
|
60
|
-
]
|
61
|
-
).generate
|
62
|
-
end
|
63
|
-
|
64
|
-
should "have a maximum of (teams/2) games per day" do
|
65
|
-
@s.gamedays.each do |gd|
|
66
|
-
assert gd.games.size <= @s.teams.size/2
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
should "not have a team that play more than once on a single day" do
|
71
|
-
@s.gamedays.each do |gd|
|
72
|
-
day_teams = gd.games.collect{|g| [g.team_a,g.team_b]}.flatten
|
73
|
-
unique_day_teams = day_teams.uniq
|
74
|
-
assert_equal day_teams.size, unique_day_teams.size
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
context "multi flights" do
|
81
|
-
setup do
|
82
|
-
@s = Schedule.new(
|
83
|
-
:teams => [
|
84
|
-
%w(A1 A2 A3 A4 A5 A6 A7 A8),
|
85
|
-
%w(B1 B2 B3 B4 B5 B6 B7 B8),
|
86
|
-
%w(C1 C2 C3 C4 C5 C6 C7 C8),
|
87
|
-
%w(D1 D2 D3 D4 D5 D6 D7 D8)
|
88
|
-
],
|
89
|
-
|
90
|
-
:rules => [
|
91
|
-
Rule.new(
|
92
|
-
:wday => 3,
|
93
|
-
:gt => ["7:00PM", "9:00PM"],
|
94
|
-
:ps => ["one","two"]
|
95
|
-
)
|
96
|
-
],
|
97
|
-
|
98
|
-
:start_date => Date.parse("2011/01/26"),
|
99
|
-
:exclude_dates => [
|
100
|
-
Date.parse("2011/02/02")
|
101
|
-
]
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "generate separate round-robins" do
|
106
|
-
@s.generate
|
107
|
-
assert_equal 4, @s.flights.size
|
108
|
-
4.times { |i| assert @s.round_robin?(i)}
|
109
|
-
end
|
110
|
-
|
111
|
-
should "have a correct total number of games" do
|
112
|
-
@s.generate
|
113
|
-
assert_equal 112, @s.gamedays.collect{|gd| gd.games.size}.inject{|x,sum| x+sum}
|
114
|
-
end
|
115
|
-
|
116
|
-
should "not have games for a date that is excluded" do
|
117
|
-
@s.generate
|
118
|
-
assert !@s.gamedays.collect{|gd| gd.date}.include?(Date.parse("2011/02/02"))
|
119
|
-
assert @s.gamedays.collect{|gd| gd.date}.include?(Date.parse("2011/02/09"))
|
120
|
-
end
|
121
|
-
|
122
|
-
should "respect rules" do
|
123
|
-
@s.teams << %w(E1 E2 E3 E4 E5 E6 E7 E8)
|
124
|
-
@s.rules << Rule.new(:wday => 4, :gt => "7:00PM", :ps => %w(one two))
|
125
|
-
@s.generate
|
126
|
-
|
127
|
-
wday = 3
|
128
|
-
@s.gamedays.each do |gd|
|
129
|
-
assert_equal wday, gd.date.wday
|
130
|
-
wday = (wday==3) ? 4 : 3
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
##### RULES #######
|
136
|
-
should "auto create array for gt and ps" do
|
137
|
-
@s = Schedule.new(
|
138
|
-
:teams => %w(a1 a2 a4 a5),
|
139
|
-
:rules => [
|
140
|
-
Rule.new(:wday => 1, :gt => "7:00PM", :ps => "The Field")
|
141
|
-
]
|
142
|
-
).generate
|
143
|
-
|
144
|
-
assert_equal [DateTime.parse("7:00PM")], @s.rules.first.gt
|
145
|
-
assert_equal ["The Field"], @s.rules.first.ps
|
146
|
-
end
|
147
|
-
|
148
|
-
context "no rules specified" do
|
149
|
-
setup {@s = Schedule.new(:teams => %w(a1 a2 a4 a5))}
|
150
|
-
should "raise an exception" do
|
151
|
-
exception = assert_raise(RuntimeError){@s.generate}
|
152
|
-
assert_equal "You need to specify at least 1 rule", exception.message
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "multiple rules on the same weekday" do
|
157
|
-
setup do
|
158
|
-
@s = Schedule.new
|
159
|
-
@s.teams = [%w(a1 a2 a3 a4 a5 a6 a7 a8), %w(b1 b2 b3 b4 b5 b6 b7 b8)]
|
160
|
-
@s.rules = [
|
161
|
-
Rule.new(:wday => 4, :gt => ["7:00PM"], :ps => %w(field1 field2)),
|
162
|
-
Rule.new(:wday => 4, :gt => ["9:00PM"], :ps => %w(field1 field2 field3))
|
163
|
-
]
|
164
|
-
@s.start_date = Date.parse("2011/01/27")
|
165
|
-
@s.generate
|
166
|
-
end
|
167
|
-
|
168
|
-
should "keep games on the same day" do
|
169
|
-
cur_date = @s.start_date
|
170
|
-
@s.gamedays.each_with_index do |gd,i|
|
171
|
-
assert_equal cur_date, gd.date
|
172
|
-
|
173
|
-
#check all days to make sure that our rules are respected. We don't check
|
174
|
-
#the last one because it might not be full (round-robin over)
|
175
|
-
if i<@s.gamedays.size-1
|
176
|
-
assert_equal 5, gd.games.size
|
177
|
-
assert_equal 1, gd.games.select{|g| g.game_time == DateTime.parse("7:00PM") && g.playing_surface == "field1"}.size
|
178
|
-
assert_equal 1, gd.games.select{|g| g.game_time == DateTime.parse("7:00PM") && g.playing_surface == "field2"}.size
|
179
|
-
assert_equal 1, gd.games.select{|g| g.game_time == DateTime.parse("9:00PM") && g.playing_surface == "field1"}.size
|
180
|
-
assert_equal 1, gd.games.select{|g| g.game_time == DateTime.parse("9:00PM") && g.playing_surface == "field2"}.size
|
181
|
-
assert_equal 1, gd.games.select{|g| g.game_time == DateTime.parse("9:00PM") && g.playing_surface == "field3"}.size
|
182
|
-
cur_date += 7
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def some_rules
|
189
|
-
[
|
190
|
-
Rule.new(:wday => 1, :gt => "7:00PM", :ps => "one"),
|
191
|
-
Rule.new(:wday => 1, :gt => "8:00PM", :ps => %w(one two))
|
192
|
-
]
|
193
|
-
end
|
194
|
-
end
|