icu_tournament 0.8.9
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.
- data/.gitignore +4 -0
- data/LICENCE +22 -0
- data/README.rdoc +75 -0
- data/Rakefile +57 -0
- data/VERSION.yml +5 -0
- data/lib/icu_tournament.rb +8 -0
- data/lib/icu_tournament/federation.rb +303 -0
- data/lib/icu_tournament/name.rb +274 -0
- data/lib/icu_tournament/player.rb +204 -0
- data/lib/icu_tournament/result.rb +191 -0
- data/lib/icu_tournament/team.rb +90 -0
- data/lib/icu_tournament/tournament.rb +508 -0
- data/lib/icu_tournament/tournament_fcsv.rb +310 -0
- data/lib/icu_tournament/tournament_krause.rb +329 -0
- data/lib/icu_tournament/util.rb +156 -0
- data/spec/federation_spec.rb +176 -0
- data/spec/name_spec.rb +208 -0
- data/spec/player_spec.rb +313 -0
- data/spec/result_spec.rb +203 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/team_spec.rb +60 -0
- data/spec/tournament_fcsv_spec.rb +548 -0
- data/spec/tournament_krause_spec.rb +379 -0
- data/spec/tournament_spec.rb +733 -0
- data/spec/util_spec.rb +357 -0
- metadata +97 -0
data/spec/spec_helper.rb
ADDED
data/spec/team_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module ICU
|
4
|
+
describe Team do
|
5
|
+
context "a typical team" do
|
6
|
+
before(:each) do
|
7
|
+
@t = Team.new('Wandering Dragons')
|
8
|
+
@t.add_member(0)
|
9
|
+
@t.add_member('3')
|
10
|
+
@t.add_member(' -7 ')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a name" do
|
14
|
+
@t.name.should == 'Wandering Dragons'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have some members" do
|
18
|
+
@t.should have(3).members
|
19
|
+
@t.include?(0).should be_true
|
20
|
+
@t.include?(3).should be_true
|
21
|
+
@t.include?(-7).should be_true
|
22
|
+
@t.include?(7).should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should match names ignoring case and irrelevant whitespace" do
|
26
|
+
@t.matches('Wandering Dragons').should be_true
|
27
|
+
@t.matches(' wandering dragons ').should be_true
|
28
|
+
@t.matches(' wanderingdragons ').should be_false
|
29
|
+
@t.matches('Blundering Bishops').should be_false
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a changeable name with irrelevant whitespace being trimmed" do
|
33
|
+
@t.name = ' blue dragons '
|
34
|
+
@t.name.should == 'blue dragons'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should blowup if an attempt is made to blank the name" do
|
38
|
+
lambda { @t.name = ' ' }.should raise_error(/blank/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should blowup if an attempt is made to add a non-number" do
|
42
|
+
lambda { @t.add_member(' ') }.should raise_error(/number/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should blow up if an attempt is made to add a duplicate number" do
|
46
|
+
lambda { @t.add_member(3) }.should raise_error(/duplicate/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should renumber successfully if the map has the relevant player numbers" do
|
50
|
+
map = { 0 => 1, 3 => 2, -7 => 3 }
|
51
|
+
@t.renumber(map)
|
52
|
+
@t.members.sort.join('').should == '123'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should raise exception if a player is missing from the renumber map" do
|
56
|
+
lambda { @t.renumber({ 5 => 1, 3 => 2 }) }.should raise_error(/player.*not found/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,548 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module ICU
|
4
|
+
class Tournament
|
5
|
+
describe ForeignCSV do
|
6
|
+
def check_player(num, first, last, results, rateable, points, other={})
|
7
|
+
p = @t.player(num)
|
8
|
+
p.first_name.should == first
|
9
|
+
p.last_name.should == last
|
10
|
+
p.id.should == other[:id]
|
11
|
+
p.rating.should == other[:rating]
|
12
|
+
p.fed.should == other[:fed]
|
13
|
+
p.title.should == other[:title]
|
14
|
+
p.results.size.should == results
|
15
|
+
p.results.select{|r| r.rateable}.size.should == rateable
|
16
|
+
p.points.should == points
|
17
|
+
end
|
18
|
+
|
19
|
+
context "a typical tournament" do
|
20
|
+
before(:all) do
|
21
|
+
@csv = <<CSV
|
22
|
+
Event,"Bangor Open, 2003"
|
23
|
+
Start,1st July 2003
|
24
|
+
Rounds,4
|
25
|
+
Website,http://www.icu.ie/tournaments/display.php?id=371
|
26
|
+
|
27
|
+
Player,3364,Ui Laighleis,Gearoidin
|
28
|
+
1,0,B,Cronin,April,2005,,IRL
|
29
|
+
2,=,W,Connolly,Suzanne,1950,,IRL
|
30
|
+
3,=,-
|
31
|
+
4,1,B,Powell,Linda,1850,,WLS
|
32
|
+
Total,2
|
33
|
+
CSV
|
34
|
+
@f = ICU::Tournament::ForeignCSV.new
|
35
|
+
@t = @f.parse!(@csv)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have a name" do
|
39
|
+
@t.name.should == 'Bangor Open, 2003'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have a start date" do
|
43
|
+
@t.start.should == '2003-07-01'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have a number of rounds" do
|
47
|
+
@t.rounds.should == 4
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have a website" do
|
51
|
+
@t.site.should == 'http://www.icu.ie/tournaments/display.php?id=371'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have some players" do
|
55
|
+
@t.should have(4).players
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have correct player details" do
|
59
|
+
check_player(1, 'Gearoidin', 'Ui Laighleis', 4, 3, 2.0, :id => 3364)
|
60
|
+
check_player(2, 'April', 'Cronin', 1, 0, 1.0, :rating => 2005, :fed => 'IRL')
|
61
|
+
check_player(3, 'Suzanne', 'Connolly', 1, 0, 0.5, :rating => 1950, :fed => 'IRL')
|
62
|
+
check_player(4, 'Linda', 'Powell', 1, 0, 0.0, :rating => 1850, :fed => 'WLS')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "the rdoc example tournament" do
|
67
|
+
before(:all) do
|
68
|
+
@csv = <<CSV
|
69
|
+
Event,"Isle of Man Masters, 2007"
|
70
|
+
Start,2007-09-22
|
71
|
+
Rounds,9
|
72
|
+
Website,http://www.bcmchess.co.uk/monarch2007/
|
73
|
+
|
74
|
+
Player,456,Fox,Anthony
|
75
|
+
1,0,B,Taylor,Peter P.,2209,,ENG
|
76
|
+
2,=,W,Nadav,Egozi,2205,,ISR
|
77
|
+
3,=,B,Cafolla,Peter,2048,,IRL
|
78
|
+
4,1,W,Spanton,Tim R.,1982,,ENG
|
79
|
+
5,1,B,Grant,Alan,2223,,SCO
|
80
|
+
6,0,-
|
81
|
+
7,=,W,Walton,Alan J.,2223,,ENG
|
82
|
+
8,0,B,Bannink,Bernard,2271,FM,NED
|
83
|
+
9,=,W,Phillips,Roy,2271,,MAU
|
84
|
+
Total,4
|
85
|
+
CSV
|
86
|
+
@f = ICU::Tournament::ForeignCSV.new
|
87
|
+
@t = @f.parse!(@csv)
|
88
|
+
@p = @t.player(1)
|
89
|
+
@o = @t.players.reject { |o| o.num == 1 }
|
90
|
+
@r = @t.player(2)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have correct basic details" do
|
94
|
+
@t.name.should == 'Isle of Man Masters, 2007'
|
95
|
+
@t.start.should == '2007-09-22'
|
96
|
+
@t.rounds.should == 9
|
97
|
+
@t.site.should == 'http://www.bcmchess.co.uk/monarch2007/'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should have the right number of players in the right order" do
|
101
|
+
@t.players.size.should == 9
|
102
|
+
@t.players.inject(''){ |a,o| a << o.num.to_s }.should == '123456789'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should have the right details for the main player" do
|
106
|
+
@p.name.should == "Fox, Anthony"
|
107
|
+
@p.results.size == 9
|
108
|
+
@p.results.find_all{ |r| r.rateable }.size.should == 8
|
109
|
+
@p.points.should == 4.0
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have the right details for the opponents" do
|
113
|
+
@o.size.should == 8
|
114
|
+
@o.find_all{ |o| o.results.size == 1}.size.should == 8
|
115
|
+
@r.name.should == "Taylor, Peter P."
|
116
|
+
@r.results[0].rateable.should be_false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "a tournament with more than one player" do
|
121
|
+
before(:all) do
|
122
|
+
@csv = <<CSV
|
123
|
+
Event,"Edinburgh Masters, 2007"
|
124
|
+
Start,3rd January 2007
|
125
|
+
Rounds,2
|
126
|
+
Website,http://www.chesscenter.com/twic/twic.html
|
127
|
+
|
128
|
+
Player,3364,Ui Laighleis,Gearoidin
|
129
|
+
1,=,W,Kasparov,Gary,2800,GM,RUS
|
130
|
+
2,=,B,Cronin,April,2005,,IRL
|
131
|
+
Total,1.0
|
132
|
+
|
133
|
+
Player,1350,Orr,Mark
|
134
|
+
1,=,W,Cronin,April,2005,,IRL
|
135
|
+
2,1,B,Fischer,Bobby,2700,GM,USA
|
136
|
+
Total,1.5
|
137
|
+
CSV
|
138
|
+
@f = ICU::Tournament::ForeignCSV.new
|
139
|
+
@t = @f.parse!(@csv)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should have the usual basic details" do
|
143
|
+
@t.name.should == 'Edinburgh Masters, 2007'
|
144
|
+
@t.start.should == '2007-01-03'
|
145
|
+
@t.rounds.should == 2
|
146
|
+
@t.site.should == 'http://www.chesscenter.com/twic/twic.html'
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should have the correct number of players" do
|
150
|
+
@t.should have(5).players
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should have correct player details" do
|
154
|
+
check_player(1, 'Gearoidin', 'Ui Laighleis', 2, 2, 1.0, :id => 3364)
|
155
|
+
check_player(4, 'Mark', 'Orr', 2, 2, 1.5, :id => 1350)
|
156
|
+
check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :rating => 2800, :fed => 'RUS', :title => 'GM')
|
157
|
+
check_player(3, 'April', 'Cronin', 2, 0, 1.0, :rating => 2005, :fed => 'IRL')
|
158
|
+
check_player(5, 'Bobby', 'Fischer', 1, 0, 0.0, :rating => 2700, :fed => 'USA', :title => 'GM')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "a tournament where someone is both a player and an opponent" do
|
163
|
+
before(:all) do
|
164
|
+
@csv = <<CSV
|
165
|
+
Event,"Bratto Open, 2001"
|
166
|
+
Start,7th March 2001
|
167
|
+
Rounds,2
|
168
|
+
Website,http://www.federscacchi.it/
|
169
|
+
|
170
|
+
Player,3364,Ui Laighleis,Gearoidin
|
171
|
+
1,=,W,Kasparov,Gary,2800,,RUS
|
172
|
+
2,=,B,Orr,Mark,2100,IM,IRL
|
173
|
+
Total,1.0
|
174
|
+
|
175
|
+
Player,1350,Orr,Mark
|
176
|
+
1,=,W,Cronin,April,2005,,IRL
|
177
|
+
2,=,W,Ui Laighleis,Gearoidin,1800,,IRL
|
178
|
+
Total,1.0
|
179
|
+
CSV
|
180
|
+
@f = ICU::Tournament::ForeignCSV.new
|
181
|
+
@t = @f.parse!(@csv)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should have the usual basic details" do
|
185
|
+
@t.name.should == 'Bratto Open, 2001'
|
186
|
+
@t.start.should == '2001-03-07'
|
187
|
+
@t.rounds.should == 2
|
188
|
+
@t.site.should == 'http://www.federscacchi.it/'
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should have the correct number of players" do
|
192
|
+
@t.should have(4).players
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should have correct player details" do
|
196
|
+
check_player(1, 'Gearoidin', 'Ui Laighleis', 2, 2, 1.0, :rating => 1800, :fed => 'IRL', :id => 3364)
|
197
|
+
check_player(3, 'Mark', 'Orr', 2, 2, 1.0, :rating => 2100, :fed => 'IRL', :id => 1350, :title => 'IM')
|
198
|
+
check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :rating => 2800, :fed => 'RUS')
|
199
|
+
check_player(4, 'April', 'Cronin', 1, 0, 0.5, :rating => 2005, :fed => 'IRL')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "a file that contains spurious white space and other untidiness" do
|
204
|
+
before(:all) do
|
205
|
+
@csv = <<CSV
|
206
|
+
|
207
|
+
Event," Bratto Open, 2001 "
|
208
|
+
Start, 7th March 2001
|
209
|
+
Rounds, 2
|
210
|
+
Website, http://www.federscacchi.it/
|
211
|
+
Player ,3364 , ui Laighleis, gearoidin
|
212
|
+
|
213
|
+
1, = ,W, kasparov, gary, 2800 , g , Rus
|
214
|
+
|
215
|
+
2 ,=, b, Orr , Mark,2100, iM , irl
|
216
|
+
Total,1.0
|
217
|
+
|
218
|
+
CSV
|
219
|
+
@f = ICU::Tournament::ForeignCSV.new
|
220
|
+
@t = @f.parse!(@csv)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should have the correct basic details" do
|
224
|
+
@t.name.should == 'Bratto Open, 2001'
|
225
|
+
@t.start.should == '2001-03-07'
|
226
|
+
@t.rounds.should == 2
|
227
|
+
@t.site.should == 'http://www.federscacchi.it/'
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should have the correct number of players" do
|
231
|
+
@t.should have(3).players
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should have correct player details" do
|
235
|
+
check_player(1, 'Gearoidin', 'Ui Laighleis', 2, 2, 1.0, :id => 3364)
|
236
|
+
check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :rating => 2800, :fed => 'RUS', :title => 'GM')
|
237
|
+
check_player(3, 'Mark', 'Orr', 1, 0, 0.5, :rating => 2100, :fed => 'IRL', :title => 'IM')
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "#parse" do
|
242
|
+
before(:each) do
|
243
|
+
@f = ICU::Tournament::ForeignCSV.new
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should behave just like #parse! on success" do
|
247
|
+
csv = <<CSV
|
248
|
+
Event,"Bratto Open, 2001"
|
249
|
+
Start,7th March 2001
|
250
|
+
Rounds,2
|
251
|
+
Website,http://www.federscacchi.it/
|
252
|
+
|
253
|
+
Player,3364,Ui Laighleis,Gearoidin
|
254
|
+
1,=,W,Kasparov,Gary,2800,GM,RUS
|
255
|
+
2,=,B,Orr,Mark,2100,IM,IRL
|
256
|
+
Total,1.0
|
257
|
+
CSV
|
258
|
+
@f.parse(csv).should be_an_instance_of(ICU::Tournament)
|
259
|
+
@f.error.should be_nil
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should not throw an exception but return nil on error" do
|
263
|
+
@f.parse(' ').should be_nil
|
264
|
+
@f.error.should match(/event/)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "invalid files" do
|
269
|
+
before(:each) do
|
270
|
+
@f = ICU::Tournament::ForeignCSV.new
|
271
|
+
end
|
272
|
+
|
273
|
+
it "a blank file is invalid" do
|
274
|
+
lambda { @f.parse!(' ') }.should raise_error(/event/i)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "the event should come first" do
|
278
|
+
csv = <<CSV
|
279
|
+
Start,7th March 2001
|
280
|
+
Event,"Bratto Open, 2001"
|
281
|
+
Rounds,2
|
282
|
+
Website,http://www.federscacchi.it/
|
283
|
+
CSV
|
284
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 1.*event/i)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "the start should come second" do
|
288
|
+
csv = <<CSV
|
289
|
+
Event,"Bratto Open, 2001"
|
290
|
+
Rounds,2
|
291
|
+
Start,7th March 2001
|
292
|
+
Website,http://www.federscacchi.it/
|
293
|
+
CSV
|
294
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 2.*start/i)
|
295
|
+
end
|
296
|
+
|
297
|
+
it "the number of rounds should come third" do
|
298
|
+
csv = <<CSV
|
299
|
+
Event,"Bratto Open, 2001"
|
300
|
+
Start,7th March 2001
|
301
|
+
Website,http://www.federscacchi.it/
|
302
|
+
Rounds,2
|
303
|
+
CSV
|
304
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 3.*rounds/i)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "there should be a web site" do
|
308
|
+
csv = <<CSV
|
309
|
+
Event,"Bratto Open, 2001"
|
310
|
+
Start,7th March 2001
|
311
|
+
Rounds,2
|
312
|
+
|
313
|
+
CSV
|
314
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 4.*site/i)
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should have at least one player" do
|
318
|
+
csv = <<CSV
|
319
|
+
Event,"Bratto Open, 2001"
|
320
|
+
Start,7th March 2001
|
321
|
+
Rounds,2
|
322
|
+
Website,http://www.federscacchi.it/
|
323
|
+
CSV
|
324
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 4.*no players/i)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "the player needs to have a valid ID number" do
|
328
|
+
csv = <<CSV
|
329
|
+
Event,"Bratto Open, 2001"
|
330
|
+
Start,7th March 2001
|
331
|
+
Rounds,2
|
332
|
+
Website,http://www.federscacchi.it/
|
333
|
+
|
334
|
+
Player,0,Ui Laighleis,Gearoidin
|
335
|
+
CSV
|
336
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 6.*number/i)
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should have the right number of results for each player" do
|
340
|
+
csv = <<CSV
|
341
|
+
Event,"Bratto Open, 2001"
|
342
|
+
Start,7th March 2001
|
343
|
+
Rounds,2
|
344
|
+
Website,http://www.federscacchi.it/
|
345
|
+
|
346
|
+
Player,3364,Ui Laighleis,Gearoidin
|
347
|
+
1,=,W,Kasparov,Gary,2800,GM,RUS
|
348
|
+
Total,0.5
|
349
|
+
CSV
|
350
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 8.*round/i)
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should have correct totals" do
|
354
|
+
csv = <<CSV
|
355
|
+
Event,"Bratto Open, 2001"
|
356
|
+
Start,7th March 2001
|
357
|
+
Rounds,2
|
358
|
+
Website,http://www.federscacchi.it/
|
359
|
+
|
360
|
+
Player,3364,Ui Laighleis,Gearoidin
|
361
|
+
1,=,W,Kasparov,Gary,2800,GM,RUS
|
362
|
+
2,=,B,Orr,Mark,2100,IM,IRL
|
363
|
+
Total,1.5
|
364
|
+
CSV
|
365
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 9.*total/i)
|
366
|
+
end
|
367
|
+
|
368
|
+
|
369
|
+
it "players who match by name and federation should match in all other details" do
|
370
|
+
csv = <<CSV
|
371
|
+
Event,"Bratto Open, 2001"
|
372
|
+
Start,7th March 2001
|
373
|
+
Rounds,2
|
374
|
+
Website,http://www.federscacchi.it/
|
375
|
+
|
376
|
+
Player,3364,Ui Laighleis,Gearoidin
|
377
|
+
1,=,W,Kasparov,Gary,2800,GM,RUS
|
378
|
+
2,=,B,Orr,Mark,2100,IM,IRL
|
379
|
+
Total,1.0
|
380
|
+
|
381
|
+
Player,1350,Orr,Mark
|
382
|
+
1,=,W,Fischer,Bobby,2700,,USA
|
383
|
+
2,=,B,Kasparov,Gary,2850,GM,RUS
|
384
|
+
Total,1.0
|
385
|
+
CSV
|
386
|
+
lambda { @f.parse!(csv) }.should raise_error(/line 13.*same name.*conflicting/i)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
context "serialisation of simple tournament" do
|
391
|
+
before(:each) do
|
392
|
+
@csv = <<CSV
|
393
|
+
Event,"Edinburgh Masters, 2007"
|
394
|
+
Start,2007-08-09
|
395
|
+
Rounds,2
|
396
|
+
Website,http://www.chesscenter.com/twic/twic.html
|
397
|
+
|
398
|
+
Player,3364,Ui Laighleis,Gearoidin
|
399
|
+
1,0,W,Kasparov,Gary,2800,GM,RUS
|
400
|
+
2,1,B,Cronin,April,2005,,IRL
|
401
|
+
Total,1.0
|
402
|
+
|
403
|
+
Player,1350,Orr,Mark
|
404
|
+
1,=,W,Cronin,April,2005,,IRL
|
405
|
+
2,=,-
|
406
|
+
Total,1.0
|
407
|
+
CSV
|
408
|
+
@f = ICU::Tournament::ForeignCSV.new
|
409
|
+
@t = @f.parse!(@csv)
|
410
|
+
end
|
411
|
+
|
412
|
+
it "should serialize back to the original" do
|
413
|
+
@f.serialize(@t).should == @csv
|
414
|
+
end
|
415
|
+
|
416
|
+
it "should return nil on invalid input" do
|
417
|
+
@f.serialize('Rubbish').should be_nil
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
context "serialisation of ForeignCSV documentation example" do
|
422
|
+
before(:each) do
|
423
|
+
@csv = <<CSV
|
424
|
+
Event,"Isle of Man Masters, 2007"
|
425
|
+
Start,2007-09-22
|
426
|
+
Rounds,9
|
427
|
+
Website,http://www.bcmchess.co.uk/monarch2007/
|
428
|
+
|
429
|
+
Player,456,Fox,Anthony
|
430
|
+
1,0,B,Taylor,Peter P.,2209,,ENG
|
431
|
+
2,=,W,Nadav,Egozi,2205,,ISR
|
432
|
+
3,=,B,Cafolla,Peter,2048,,IRL
|
433
|
+
4,1,W,Spanton,Tim R.,1982,,ENG
|
434
|
+
5,1,B,Grant,Alan,2223,,SCO
|
435
|
+
6,0,-
|
436
|
+
7,=,W,Walton,Alan J.,2223,,ENG
|
437
|
+
8,0,B,Bannink,Bernard,2271,FM,NED
|
438
|
+
9,=,W,Phillips,Roy,2271,,MAU
|
439
|
+
Total,4.0
|
440
|
+
|
441
|
+
Player,159,Cafolla,Peter
|
442
|
+
1,0,W,Jackson,Oliver A.,2198,,ENG
|
443
|
+
2,0,B,Jeroen,Van Den Berssalaar,,,NED
|
444
|
+
3,=,W,Fox,Anthony,2100,,IRL
|
445
|
+
4,=,B,Collins,Sam E.,2394,IM,IRL
|
446
|
+
5,1,W,Troyke,Doreen,2151,WFM,GER
|
447
|
+
6,=,B,Nelson,Jonathan P.,2282,,ENG
|
448
|
+
7,0,W,Egozi,Nadav,2205,,ISR
|
449
|
+
8,=,B,Weeks,Manuel,2200,FM,AUS
|
450
|
+
9,0,W,Grant,Alan,2223,,SCO
|
451
|
+
Total,3.0
|
452
|
+
CSV
|
453
|
+
@t = ICU::Tournament.new("Isle of Man Masters, 2007", '2007-09-22')
|
454
|
+
@t.site = 'http://www.bcmchess.co.uk/monarch2007/'
|
455
|
+
@t.rounds = 9
|
456
|
+
@t.add_player(ICU::Player.new('Anthony', 'Fox', 1, :id => 456, :rating => 2100, :fed => 'IRL'))
|
457
|
+
@t.add_player(ICU::Player.new('Peter', 'Cafolla', 2, :id => 159, :rating => 2048, :fed => 'IRL'))
|
458
|
+
@t.add_player(ICU::Player.new('Peter P.', 'Taylor', 3, :rating => 2209, :fed => 'ENG'))
|
459
|
+
@t.add_player(ICU::Player.new('Egozi', 'Nadav', 4, :rating => 2205, :fed => 'ISR'))
|
460
|
+
@t.add_player(ICU::Player.new('Tim R.', 'Spanton', 5, :rating => 1982, :fed => 'ENG'))
|
461
|
+
@t.add_player(ICU::Player.new('Alan', 'Grant', 6, :rating => 2223, :fed => 'SCO'))
|
462
|
+
@t.add_player(ICU::Player.new('Alan J.', 'Walton', 7, :rating => 2223, :fed => 'ENG'))
|
463
|
+
@t.add_player(ICU::Player.new('Bernard', 'Bannink', 8, :rating => 2271, :fed => 'NED', :title => 'FM'))
|
464
|
+
@t.add_player(ICU::Player.new('Roy', 'Phillips', 9, :rating => 2271, :fed => 'MAU'))
|
465
|
+
@t.add_player(ICU::Player.new('Oliver A.', 'Jackson', 10, :rating => 2198, :fed => 'ENG'))
|
466
|
+
@t.add_player(ICU::Player.new('Van Den Berssalaar', 'Jeroen', 11, :fed => 'NED'))
|
467
|
+
@t.add_player(ICU::Player.new('Sam E.', 'Collins', 12, :rating => 2394, :fed => 'IRL', :title => 'IM'))
|
468
|
+
@t.add_player(ICU::Player.new('Doreen', 'Troyke', 13, :rating => 2151, :fed => 'GER', :title => 'WFM'))
|
469
|
+
@t.add_player(ICU::Player.new('Jonathan P.', 'Nelson', 14, :rating => 2282, :fed => 'ENG'))
|
470
|
+
@t.add_player(ICU::Player.new('Nadav', 'Egozi', 15, :rating => 2205, :fed => 'ISR'))
|
471
|
+
@t.add_player(ICU::Player.new('Manuel', 'Weeks', 16, :rating => 2200, :fed => 'AUS', :title => 'FM'))
|
472
|
+
@t.add_player(ICU::Player.new('Alan', 'Grant', 17, :rating => 2223, :fed => 'SCO'))
|
473
|
+
@t.add_result(ICU::Result.new(1, 1, 'L', :opponent => 3, :colour => 'B'))
|
474
|
+
@t.add_result(ICU::Result.new(2, 1, 'D', :opponent => 4, :colour => 'W'))
|
475
|
+
@t.add_result(ICU::Result.new(3, 1, 'D', :opponent => 2, :colour => 'B'))
|
476
|
+
@t.add_result(ICU::Result.new(4, 1, 'W', :opponent => 5, :colour => 'W'))
|
477
|
+
@t.add_result(ICU::Result.new(5, 1, 'W', :opponent => 6, :colour => 'B'))
|
478
|
+
@t.add_result(ICU::Result.new(6, 1, 'L'))
|
479
|
+
@t.add_result(ICU::Result.new(7, 1, 'D', :opponent => 7, :colour => 'W'))
|
480
|
+
@t.add_result(ICU::Result.new(8, 1, 'L', :opponent => 8, :colour => 'B'))
|
481
|
+
@t.add_result(ICU::Result.new(9, 1, 'D', :opponent => 9, :colour => 'W'))
|
482
|
+
@t.add_result(ICU::Result.new(1, 2, 'L', :opponent => 10, :colour => 'W'))
|
483
|
+
@t.add_result(ICU::Result.new(2, 2, 'L', :opponent => 11, :colour => 'B'))
|
484
|
+
@t.add_result(ICU::Result.new(3, 2, 'D', :opponent => 1, :colour => 'W'))
|
485
|
+
@t.add_result(ICU::Result.new(4, 2, 'D', :opponent => 12, :colour => 'B'))
|
486
|
+
@t.add_result(ICU::Result.new(5, 2, 'W', :opponent => 13, :colour => 'W'))
|
487
|
+
@t.add_result(ICU::Result.new(6, 2, 'D', :opponent => 14, :colour => 'B'))
|
488
|
+
@t.add_result(ICU::Result.new(7, 2, 'L', :opponent => 15, :colour => 'W'))
|
489
|
+
@t.add_result(ICU::Result.new(8, 2, 'D', :opponent => 16, :colour => 'B'))
|
490
|
+
@t.add_result(ICU::Result.new(9, 2, 'L', :opponent => 17, :colour => 'W'))
|
491
|
+
end
|
492
|
+
|
493
|
+
it "should serialize to the expected string" do
|
494
|
+
@t.serialize('ForeignCSV').should == @csv
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
context "serialisation of shortened ForeignCSV documentation example" do
|
499
|
+
before(:each) do
|
500
|
+
@csv = <<CSV
|
501
|
+
Event,"Isle of Man Masters, 2007"
|
502
|
+
Start,2007-09-22
|
503
|
+
Rounds,9
|
504
|
+
Website,http://www.bcmchess.co.uk/monarch2007/
|
505
|
+
|
506
|
+
Player,456,Fox,Anthony
|
507
|
+
1,0,B,Taylor,Peter P.,2209,,ENG
|
508
|
+
2,=,W,Nadav,Egozi,2205,,ISR
|
509
|
+
3,=,B,Cafolla,Peter,2048,,IRL
|
510
|
+
4,1,W,Spanton,Tim R.,1982,,ENG
|
511
|
+
5,1,B,Grant,Alan,2223,,SCO
|
512
|
+
6,0,-
|
513
|
+
7,=,W,Walton,Alan J.,2223,,ENG
|
514
|
+
8,0,B,Bannink,Bernard,2271,FM,NED
|
515
|
+
9,=,W,Phillips,Roy,2271,,MAU
|
516
|
+
Total,4.0
|
517
|
+
CSV
|
518
|
+
@t = ICU::Tournament.new("Isle of Man Masters, 2007", '2007-09-22', :round => 9)
|
519
|
+
@t.site = 'http://www.bcmchess.co.uk/monarch2007/'
|
520
|
+
@t.rounds = 9
|
521
|
+
@t.add_player(ICU::Player.new('Anthony', 'Fox', 1, :id => 456, :rating => 2100, :fed => 'IRL'))
|
522
|
+
@t.add_player(ICU::Player.new('Peter P.', 'Taylor', 2, :rating => 2209, :fed => 'ENG'))
|
523
|
+
@t.add_player(ICU::Player.new('Egozi', 'Nadav', 3, :rating => 2205, :fed => 'ISR'))
|
524
|
+
@t.add_player(ICU::Player.new('Peter', 'Cafolla', 4, :rating => 2048, :fed => 'IRL'))
|
525
|
+
@t.add_player(ICU::Player.new('Tim R.', 'Spanton', 5, :rating => 1982, :fed => 'ENG'))
|
526
|
+
@t.add_player(ICU::Player.new('Alan', 'Grant', 6, :rating => 2223, :fed => 'SCO'))
|
527
|
+
@t.add_player(ICU::Player.new('Alan J.', 'Walton', 7, :rating => 2223, :fed => 'ENG'))
|
528
|
+
@t.add_player(ICU::Player.new('Bernard', 'Bannink', 8, :rating => 2271, :fed => 'NED', :title => 'FM'))
|
529
|
+
@t.add_player(ICU::Player.new('Roy', 'Phillips', 9, :rating => 2271, :fed => 'MAU'))
|
530
|
+
@t.add_result(ICU::Result.new(1, 1, 'L', :opponent => 2, :colour => 'B'))
|
531
|
+
@t.add_result(ICU::Result.new(2, 1, 'D', :opponent => 3, :colour => 'W'))
|
532
|
+
@t.add_result(ICU::Result.new(3, 1, 'D', :opponent => 4, :colour => 'B'))
|
533
|
+
@t.add_result(ICU::Result.new(4, 1, 'W', :opponent => 5, :colour => 'W'))
|
534
|
+
@t.add_result(ICU::Result.new(5, 1, 'W', :opponent => 6, :colour => 'B'))
|
535
|
+
@t.add_result(ICU::Result.new(6, 1, 'L'))
|
536
|
+
@t.add_result(ICU::Result.new(7, 1, 'D', :opponent => 7, :colour => 'W'))
|
537
|
+
@t.add_result(ICU::Result.new(8, 1, 'L', :opponent => 8, :colour => 'B'))
|
538
|
+
@t.add_result(ICU::Result.new(9, 1, 'D', :opponent => 9, :colour => 'W'))
|
539
|
+
@t.validate!
|
540
|
+
end
|
541
|
+
|
542
|
+
it "should serialize to the expected string" do
|
543
|
+
@t.serialize('ForeignCSV').should == @csv
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|