sanichi-chess_icu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/CHANGELOG +2 -0
- data/LICENCE +22 -0
- data/README.rdoc +11 -0
- data/Rakefile +41 -0
- data/VERSION.yml +4 -0
- data/lib/chess_icu.rb +3 -0
- data/lib/name.rb +217 -0
- data/lib/player.rb +143 -0
- data/lib/result.rb +103 -0
- data/lib/tournament.rb +81 -0
- data/lib/tournament_fcsv.rb +155 -0
- data/lib/util.rb +15 -0
- data/spec/name_spec.rb +172 -0
- data/spec/player_spec.rb +276 -0
- data/spec/result_spec.rb +165 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/tournament_fcsv_spec.rb +306 -0
- data/spec/tournament_spec.rb +166 -0
- data/spec/util_spec.rb +33 -0
- metadata +78 -0
@@ -0,0 +1,166 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module ICU
|
4
|
+
describe Tournament do
|
5
|
+
context "a typical tournament" do
|
6
|
+
it "has a name, start date, some players and some results" do
|
7
|
+
lambda do
|
8
|
+
t = Tournament.new('Bangor Bash', '2009-11-09')
|
9
|
+
t.add_player(Player.new('Bobby', 'Fischer', 1))
|
10
|
+
t.add_player(Player.new('Garry', 'Gary Kasparov', 2))
|
11
|
+
t.add_player(Player.new('Mark', 'Orr', 3))
|
12
|
+
t.add_result(Result.new(1, 1, '=', :opponent => 2, :colour => 'W'))
|
13
|
+
t.add_result(Result.new(2, 2, 'L', :opponent => 3, :colour => 'W'))
|
14
|
+
t.add_result(Result.new(3, 3, 'W', :opponent => 1, :colour => 'W'))
|
15
|
+
end.should_not raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Tournament name.
|
20
|
+
context "name" do
|
21
|
+
before(:each) do
|
22
|
+
@t = Tournament.new('Edinburgh Masters', '2009-11-09')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "must be specified in constructor" do
|
26
|
+
@t.name.should == 'Edinburgh Masters'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can be replaced by accessor" do
|
30
|
+
@t.name = 'Bangor Bashers'
|
31
|
+
@t.name.should == 'Bangor Bashers'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not be blank or without letters" do
|
35
|
+
lambda { Tournament.new(' ', '2009-11-09') }.should raise_error(/invalid.*name/)
|
36
|
+
lambda { @t.name = '333' }.should raise_error(/invalid.*name/)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Tournament start date.
|
41
|
+
context "start date" do
|
42
|
+
before(:each) do
|
43
|
+
@t = Tournament.new('Edinburgh Masters', '2009-11-09')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "must be specified in constructor" do
|
47
|
+
@t.start.should == '2009-11-09'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can be replaced by accessor" do
|
51
|
+
@t.start = '16th June 2010'
|
52
|
+
@t.start.should == '2010-06-16'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be a valid date" do
|
56
|
+
lambda { Tournament.new('Edinburgh Masters', ' ') }.should raise_error(/invalid.*date/)
|
57
|
+
lambda { @t.start = 'X' }.should raise_error(/invalid.*date/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Number of rounds.
|
62
|
+
context "rounds" do
|
63
|
+
it "defaults to nil" do
|
64
|
+
Tournament.new('Edinburgh Masters', '2009-11-09').rounds.should be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be a positive integer" do
|
68
|
+
Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => 3).rounds.should == 3
|
69
|
+
Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => ' 10 ').rounds.should == 10
|
70
|
+
lambda { Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => ' 0 ') }.should raise_error(/invalid.*rounds/)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Web site.
|
75
|
+
context "site" do
|
76
|
+
it "defaults to nil" do
|
77
|
+
Tournament.new('Edinburgh Masters', '2009-11-09').site.should be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should be a reasonably valid looking URL" do
|
81
|
+
Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'https://www.bbc.co.uk').site.should == 'https://www.bbc.co.uk'
|
82
|
+
Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'www.icu.ie/event.php?id=1').site.should == 'http://www.icu.ie/event.php?id=1'
|
83
|
+
lambda { Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'X') }.should raise_error(/invalid.*site/)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Tournament players.
|
88
|
+
context "players" do
|
89
|
+
before(:each) do
|
90
|
+
@t = Tournament.new('Edinburgh Masters', '2009-11-09')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have unique numbers" do
|
94
|
+
@t.add_player(Player.new('Mark', 'Orr', 1))
|
95
|
+
lambda { @t.add_player(Player.new('Bobby', 'Fischer', 1)) }.should raise_error(/player.*unique/)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "can be added one at a time" do
|
99
|
+
@t.add_player(Player.new('Mark', 'Orr', -1))
|
100
|
+
@t.add_player(Player.new('Gary', 'Kasparov', -2))
|
101
|
+
@t.add_player(Player.new('Bobby', 'Fischer', -3))
|
102
|
+
@t.players.size.should == 3
|
103
|
+
@t.player(-1).first_name.should == 'Mark'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Tournament results.
|
108
|
+
context "results" do
|
109
|
+
before(:each) do
|
110
|
+
@t = Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => 3)
|
111
|
+
@t.add_player(@mark = Player.new('Mark', 'Orr', 1))
|
112
|
+
@t.add_player(@gary = Player.new('Gary', 'Kasparov', 2))
|
113
|
+
@t.add_player(@boby = Player.new('Bobby', 'Fischer', 3))
|
114
|
+
end
|
115
|
+
|
116
|
+
it "can be added one at a time" do
|
117
|
+
@t.add_result(Result.new(1, 1, 'W', :opponent => 2))
|
118
|
+
@t.add_result(Result.new(2, 2, 'D', :opponent => 3))
|
119
|
+
@t.add_result(Result.new(3, 3, 'L', :opponent => 1))
|
120
|
+
@mark.results.size.should == 2
|
121
|
+
@mark.points.should == 2.0
|
122
|
+
@gary.results.size.should == 2
|
123
|
+
@gary.points.should == 0.5
|
124
|
+
@boby.results.size.should == 2
|
125
|
+
@boby.points.should == 0.5
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can be added symmetrically or asymmetrically with respect to rateability" do
|
129
|
+
@t.add_result(Result.new(1, 1, 'W', :opponent => 2))
|
130
|
+
@mark.results[0].rateable.should be_true
|
131
|
+
@gary.results[0].rateable.should be_true
|
132
|
+
@t.add_result(Result.new(2, 1, 'W', :opponent => 3), false)
|
133
|
+
@mark.results[1].rateable.should be_true
|
134
|
+
@boby.results[0].rateable.should be_false
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should have a defined player" do
|
138
|
+
lambda { @t.add_result(Result.new(1, 4, 'L', :opponent => 1)) }.should raise_error(/player.*exist/)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should have a defined opponent" do
|
142
|
+
lambda { @t.add_result(Result.new(1, 1, 'W', :opponent => 4)) }.should raise_error(/opponent.*exist/)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should be consistent with the tournament's number of rounds" do
|
146
|
+
lambda { @t.add_result(Result.new(4, 1, 'W', :opponent => 2)) }.should raise_error(/round/)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "finding players" do
|
151
|
+
before(:all) do
|
152
|
+
@t = Tournament.new('Bangor Bash', '2009-11-09')
|
153
|
+
@t.add_player(Player.new('Bobby', 'Fischer', 1, :fed => 'USA'))
|
154
|
+
@t.add_player(Player.new('Garry', 'Gary Kasparov', 2, :fed => 'RUS'))
|
155
|
+
@t.add_player(Player.new('Mark', 'Orr', 3, :fed => 'IRL'))
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should find players based on loose equality" do
|
159
|
+
@t.find_player(Player.new('Mark', 'Orr', 4, :fed => 'IRL')).num.should == 3
|
160
|
+
@t.find_player(Player.new('Mark', 'Orr', 4, :fed => 'USA')).should be_nil
|
161
|
+
@t.find_player(Player.new('Mark', 'Sax', 4, :fed => 'IRL')).should be_nil
|
162
|
+
@t.find_player(Player.new('John', 'Orr', 4, :fed => 'IRL')).should be_nil
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module ICU
|
4
|
+
describe Util do
|
5
|
+
context "#parsedate" do
|
6
|
+
it "should parse standard dates" do
|
7
|
+
Util.parsedate('2001-01-01').should == '2001-01-01'
|
8
|
+
Util.parsedate('1955-11-09').should == '1955-11-09'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should handle US format" do
|
12
|
+
Util.parsedate('03/30/2009').should == '2009-03-30'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle European format" do
|
16
|
+
Util.parsedate('30/03/2009').should == '2009-03-30'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should prefer European format" do
|
20
|
+
Util.parsedate('02/03/2009').should == '2009-03-02'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should handle single digits" do
|
24
|
+
Util.parsedate('9/8/2006').should == '2006-08-09'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle names of months" do
|
28
|
+
Util.parsedate('9th Nov 1955').should == '1955-11-09'
|
29
|
+
Util.parsedate('16th June 1986').should == '1986-06-16'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sanichi-chess_icu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Orr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-11 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: mark.j.l.orr@googlemail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- CHANGELOG
|
27
|
+
- LICENCE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION.yml
|
31
|
+
- lib/chess_icu.rb
|
32
|
+
- lib/name.rb
|
33
|
+
- lib/player.rb
|
34
|
+
- lib/result.rb
|
35
|
+
- lib/tournament.rb
|
36
|
+
- lib/tournament_fcsv.rb
|
37
|
+
- lib/util.rb
|
38
|
+
- spec/name_spec.rb
|
39
|
+
- spec/player_spec.rb
|
40
|
+
- spec/result_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- spec/tournament_fcsv_spec.rb
|
43
|
+
- spec/tournament_spec.rb
|
44
|
+
- spec/util_spec.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/sanichi/chess_icu
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.2.0
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: For parsing files of chess tournament data into ruby classes.
|
71
|
+
test_files:
|
72
|
+
- spec/name_spec.rb
|
73
|
+
- spec/player_spec.rb
|
74
|
+
- spec/result_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/tournament_fcsv_spec.rb
|
77
|
+
- spec/tournament_spec.rb
|
78
|
+
- spec/util_spec.rb
|