olympic 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ module OlympicSpec
2
+ class Match < ActiveRecord::Base
3
+ include Olympic::Match
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ module OlympicSpec
2
+ module Schema
3
+ def self.load
4
+ ActiveRecord::Schema.define do
5
+ self.verbose = false
6
+ create_table :teams do |t|
7
+ t.string :name
8
+ t.float :rating, null: false, default: 1500
9
+ t.float :derivation, null: false, default: 350
10
+ end
11
+
12
+ create_table :tournaments do |t|
13
+ t.string :type
14
+ t.integer :root_id
15
+ end
16
+
17
+ create_table :teams_tournaments, id: false do |t|
18
+ t.integer :team_id
19
+ t.integer :tournament_id
20
+ end
21
+
22
+ create_table :matches_teams, id: false do |t|
23
+ t.integer :match_id
24
+ t.integer :team_id
25
+ end
26
+
27
+ create_table :sources do |t|
28
+ t.integer :match_id
29
+ t.integer :source_id
30
+ t.string :source_type
31
+ end
32
+
33
+ create_table :matches do |t|
34
+ t.integer :tournament_id
35
+ t.integer :winner_id
36
+ t.integer :depth
37
+ t.integer :offset
38
+ t.integer :value
39
+ t.text :data
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.unload
45
+ ActiveRecord::Schema.define do
46
+ self.verbose = false
47
+ drop_table :teams
48
+ drop_table :tournaments
49
+ drop_table :teams_tournaments
50
+ drop_table :matches_teams
51
+ drop_table :sources
52
+ drop_table :matches
53
+ end
54
+ end
55
+
56
+ def self.connect
57
+ ActiveRecord::Base.
58
+ establish_connection(adapter: "sqlite3", database: ":memory:")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ Olympic::Settings.configure do |config|
2
+ config.match_class = "OlympicSpec::Match"
3
+ config.team_class = "OlympicSpec::Team"
4
+ config.tournament_class = "OlympicSpec::Tournament"
5
+ config.source_class = "OlympicSpec::Source"
6
+ end
@@ -0,0 +1,5 @@
1
+ module OlympicSpec
2
+ class Source < ActiveRecord::Base
3
+ include Olympic::Source
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module OlympicSpec
2
+ class Team < ActiveRecord::Base
3
+ include Olympic::Team
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module OlympicSpec
2
+ class Tournament < ActiveRecord::Base
3
+ include Olympic::Tournament
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ RSpec.describe Olympic::Rating::Glicko do
2
+ OS = OlympicSpec
3
+
4
+ def source_for(team)
5
+ OS::Source.create(source: team)
6
+ end
7
+
8
+ subject { described_class.new(unit) }
9
+ let(:unit) { OS::Team.
10
+ create(name: "Alpha", rating: 1500, derivation: 200) }
11
+ let(:beta) { OS::Team.
12
+ create(name: "Beta", rating: 1400, derivation: 30) }
13
+ let(:charlie) { OS::Team.
14
+ create(name: "Charlie", rating: 1550, derivation: 100) }
15
+ let(:delta) { OS::Team.
16
+ create(name: "Delta", rating: 1700, derivation: 300) }
17
+ let(:matches) { [
18
+ OS::Match.create(incoming: [source_for(unit), source_for(beta)], winner: unit),
19
+ OS::Match.create(incoming: [source_for(unit), source_for(charlie)], winner: unit),
20
+ OS::Match.create(incoming: [source_for(unit), source_for(delta)], winner: unit)] }
21
+
22
+ context "#update" do
23
+ it "updates the unit" do
24
+ expect { subject.update(matches) }.to_not raise_error
25
+ expect(unit.rating).to be_within(2).of 1464
26
+ expect(unit.derivation).to be_within(1).of 151.4
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,85 @@
1
+ describe Olympic::Settings do
2
+
3
+ subject { described_class.new(team_class: "Hello", foo: "bar") }
4
+
5
+ describe "#build" do
6
+
7
+ it "yields itself" do
8
+ expect { |b| subject.build(&b) }.to yield_with_args(subject)
9
+ end
10
+
11
+ it "returns itself" do
12
+ expect(subject.build {}).to be subject
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "accesses using symbols" do
18
+ expect(subject["foo"]).to eq "bar"
19
+ expect(subject[:foo]).to be subject["foo"]
20
+ end
21
+
22
+ it "raises on a missing key" do
23
+ expect { subject[:not_here] }.to raise_error KeyError
24
+ end
25
+ end
26
+
27
+ describe "#[]=" do
28
+ it "sets with a symbol key" do
29
+ subject["may"] = "not"
30
+ expect(subject[:may]).to eq "not"
31
+ end
32
+ end
33
+
34
+ describe "#method_missing" do
35
+ it "accesses the settings" do
36
+ expect(subject.foo).to eq "bar"
37
+ end
38
+
39
+ it "sets with a symbol key" do
40
+ subject.baz = "foo"
41
+ expect(subject.baz).to eq "foo"
42
+ end
43
+
44
+ it "raises otherwise" do
45
+ expect { subject.foo {} }.to raise_error
46
+ expect { subject.foo(1) }.to raise_error
47
+ expect { subject.foo(1, 2) }.to raise_error
48
+ expect { subject.foo! }.to raise_error
49
+ expect { subject.foo? }.to raise_error
50
+ expect { subject.send(:foo=, 1, 2) }.to raise_error
51
+ end
52
+ end
53
+
54
+ describe ".settings" do
55
+ specify { expect(described_class.settings).
56
+ to be_a described_class }
57
+
58
+ it "persists" do
59
+ expect(Olympic::Settings.settings).
60
+ to be Olympic::Settings.settings
61
+ end
62
+ end
63
+
64
+ describe ".configure" do
65
+
66
+ it "yields a Settings instance" do
67
+ expect { |b| described_class.configure(&b) }.
68
+ to yield_with_args(Olympic::Settings)
69
+ end
70
+
71
+ it "returns a settings instance" do
72
+ expect(described_class.configure {}).to be_a Olympic::Settings
73
+ expect(described_class.configure {}).
74
+ to be described_class.settings
75
+ end
76
+ end
77
+
78
+ describe ".[]" do
79
+ it "accesses the settings instance" do
80
+ expect(described_class[:team_class]).
81
+ to be described_class.settings[:team_class]
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,43 @@
1
+ RSpec.describe Olympic::Tournament do
2
+ let(:klass) { OlympicSpec::Tournament }
3
+
4
+ describe ".create_tournament" do
5
+ let(:teams) { 16.times.
6
+ map { |i| OlympicSpec::Team.create(name: "Team #{i}") } }
7
+
8
+ it "creates a single elimination tournament" do
9
+ tournament = nil
10
+ expect {
11
+ tournament = klass.
12
+ create_tournament(teams: teams, type: :single)
13
+ }.to_not raise_error
14
+
15
+ expect(tournament.type).to eq "single"
16
+ expect(tournament.teams.size).to eq teams
17
+ expect(tournament.matches.size).to be 15
18
+ expect(tournament.root.incoming.size).to be 2
19
+ expect(tournament.root.outgoing.size).to be 0
20
+
21
+ sources = [].concat(tournament.root.incoming)
22
+ found = []
23
+
24
+ Timeout.timeout(5) do
25
+ until sources.empty?
26
+ source = sources.shift
27
+
28
+ case source.source_type
29
+ when "OlympicSpec::Match"
30
+ sources.concat(source.source.incoming)
31
+ when "OlympicSpec::Team"
32
+ found << source.source
33
+ else
34
+ raise ArgumentError, "Invalid source type"
35
+ end
36
+ end
37
+ end
38
+
39
+ expect(found.size).to be 16
40
+ expect(found).to eq teams
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "simplecov"
4
+ require "coveralls"
5
+ require "pry"
6
+
7
+ require "active_support"
8
+ require "active_record"
9
+ require "olympic"
10
+
11
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
12
+ SimpleCov.start do
13
+ add_filter "spec"
14
+ end
15
+
16
+ Dir[File.dirname(__FILE__) + "/{support,helpers}/**/*.rb"].
17
+ each { |f| require f }
18
+ OlympicSpec::Schema.connect
19
+
20
+ RSpec.configure do |config|
21
+
22
+ config.run_all_when_everything_filtered = true
23
+ config.order = "random"
24
+
25
+ config.expect_with :rspec do |c|
26
+ c.syntax = :expect
27
+ end
28
+
29
+ config.before(:each) do
30
+ OlympicSpec::Schema.load
31
+ end
32
+
33
+ config.after(:each) do
34
+ OlympicSpec::Schema.unload
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,15 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: olympic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - medcat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2016-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: memoist
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.12'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.12'
13
47
  - !ruby/object:Gem::Dependency
14
48
  name: bundler
15
49
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +72,20 @@ dependencies:
38
72
  - - ">="
39
73
  - !ruby/object:Gem::Version
40
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.1'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.1'
41
89
  description: Tournament system for Rails.
42
90
  email:
43
91
  - redjazz96@gmail.com
@@ -45,14 +93,45 @@ executables: []
45
93
  extensions: []
46
94
  extra_rdoc_files: []
47
95
  files:
96
+ - ".gitattributes"
48
97
  - ".gitignore"
98
+ - ".rspec"
49
99
  - Gemfile
50
100
  - LICENSE.txt
51
101
  - README.md
52
102
  - Rakefile
103
+ - lib/generators/olympic/install/install_generator.rb
104
+ - lib/generators/olympic/install/templates/create_olympic_tables.rb
53
105
  - lib/olympic.rb
106
+ - lib/olympic/bracket.rb
107
+ - lib/olympic/bracket/base.rb
108
+ - lib/olympic/bracket/single_elimination.rb
109
+ - lib/olympic/bracket/single_elimination/information.rb
110
+ - lib/olympic/coordinate.rb
111
+ - lib/olympic/coordinate/standard.rb
112
+ - lib/olympic/error.rb
113
+ - lib/olympic/match.rb
114
+ - lib/olympic/rating.rb
115
+ - lib/olympic/rating/base.rb
116
+ - lib/olympic/rating/glicko.rb
117
+ - lib/olympic/rating/glicko/formula.rb
118
+ - lib/olympic/settings.rb
119
+ - lib/olympic/settings/class_methods.rb
120
+ - lib/olympic/source.rb
121
+ - lib/olympic/team.rb
122
+ - lib/olympic/tournament.rb
54
123
  - lib/olympic/version.rb
55
124
  - olympic.gemspec
125
+ - spec/helpers/match.rb
126
+ - spec/helpers/schema.rb
127
+ - spec/helpers/settings.rb
128
+ - spec/helpers/source.rb
129
+ - spec/helpers/team.rb
130
+ - spec/helpers/tournament.rb
131
+ - spec/olympic/rating/glicko_spec.rb
132
+ - spec/olympic/settings_spec.rb
133
+ - spec/olympic/tournament_spec.rb
134
+ - spec/spec_helper.rb
56
135
  homepage: ''
57
136
  licenses:
58
137
  - MIT
@@ -73,9 +152,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
152
  version: '0'
74
153
  requirements: []
75
154
  rubyforge_project:
76
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.5.1
77
156
  signing_key:
78
157
  specification_version: 4
79
158
  summary: Tournament system for Rails.
80
- test_files: []
159
+ test_files:
160
+ - spec/helpers/match.rb
161
+ - spec/helpers/schema.rb
162
+ - spec/helpers/settings.rb
163
+ - spec/helpers/source.rb
164
+ - spec/helpers/team.rb
165
+ - spec/helpers/tournament.rb
166
+ - spec/olympic/rating/glicko_spec.rb
167
+ - spec/olympic/settings_spec.rb
168
+ - spec/olympic/tournament_spec.rb
169
+ - spec/spec_helper.rb
81
170
  has_rdoc: