icu_tournament 1.2.8 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/icu_tournament.rb +1 -1
- data/lib/icu_tournament/federation.rb +6 -0
- data/lib/icu_tournament/player.rb +7 -7
- data/lib/icu_tournament/tournament.rb +11 -10
- data/lib/icu_tournament/tournament_fcsv.rb +14 -12
- data/lib/icu_tournament/tournament_krause.rb +10 -7
- data/lib/icu_tournament/tournament_sp.rb +27 -63
- data/lib/icu_tournament/tournament_spx.rb +397 -0
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/player_spec.rb +50 -36
- data/spec/tournament_fcsv_spec.rb +50 -50
- data/spec/tournament_krause_spec.rb +26 -20
- data/spec/tournament_sp_spec.rb +46 -54
- data/spec/tournament_spx_spec.rb +379 -0
- metadata +7 -4
@@ -8,7 +8,7 @@ module ICU
|
|
8
8
|
p = @t.player(num)
|
9
9
|
p.first_name.should == first
|
10
10
|
p.last_name.should == last
|
11
|
-
[:gender, :title, :rating, :fed, :id, :fide, :dob, :rank].each do |key|
|
11
|
+
[:gender, :title, :rating, :fide_rating, :fed, :id, :fide, :dob, :rank].each do |key|
|
12
12
|
p.send(key).should == other[key] if other.has_key?(key)
|
13
13
|
end
|
14
14
|
end
|
@@ -43,7 +43,7 @@ module ICU
|
|
43
43
|
001 3 m g Bologan,Viktor 2663 MDA 13900048 1971.01.01 0.0 3 1 b 0 2 w 0
|
44
44
|
KRAUSE
|
45
45
|
@p = ICU::Tournament::Krause.new
|
46
|
-
@t = @p.parse!(krause)
|
46
|
+
@t = @p.parse!(krause, :fide => true)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should have a name, city and federation" do
|
@@ -71,9 +71,9 @@ KRAUSE
|
|
71
71
|
|
72
72
|
it "should have players and their details" do
|
73
73
|
@t.should have(3).players
|
74
|
-
check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :
|
75
|
-
check_player(2, 'Mark', 'Orr', :gender => 'M', :
|
76
|
-
check_player(3, 'Viktor', 'Bologan', :gender => 'M', :
|
74
|
+
check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :fide_rating => 1985, :fed => 'IRL', :fide => 2501171, :dob => '1964-06-10', :rank => 2)
|
75
|
+
check_player(2, 'Mark', 'Orr', :gender => 'M', :fide_rating => 2258, :fed => 'IRL', :fide => 2500035, :dob => '1955-11-09', :rank => 1, :title => 'IM')
|
76
|
+
check_player(3, 'Viktor', 'Bologan', :gender => 'M', :fide_rating => 2663, :fed => 'MDA', :fide => 13900048, :dob => '1971-01-01', :rank => 3, :title => 'GM')
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should have correct results for each player" do
|
@@ -202,6 +202,12 @@ KRAUSE
|
|
202
202
|
t.serialize('Krause').should == @krause
|
203
203
|
end
|
204
204
|
|
205
|
+
it "should serialize only if :fide option is used correctly" do
|
206
|
+
t = @p.parse!(@krause, :fide => true)
|
207
|
+
t.serialize('Krause', :fide => true).should == @krause
|
208
|
+
t.serialize('Krause').should_not == @krause
|
209
|
+
end
|
210
|
+
|
205
211
|
it "should not serialize coorectly if mixed ID types are used" do
|
206
212
|
t = @p.parse!(@krause, :fide => true)
|
207
213
|
t.serialize('Krause').should_not == @krause
|
@@ -233,7 +239,7 @@ KRAUSE
|
|
233
239
|
@t.player(3).rank.should == 3
|
234
240
|
end
|
235
241
|
end
|
236
|
-
|
242
|
+
|
237
243
|
context "local or FIDE IDs" do
|
238
244
|
before(:each) do
|
239
245
|
@krause = <<KRAUSE
|
@@ -266,7 +272,7 @@ KRAUSE
|
|
266
272
|
@krause = <<KRAUSE
|
267
273
|
012 Las Vegas National Open
|
268
274
|
042 2008-06-07
|
269
|
-
001 10 w Ui Laighleis,Gearoidin 1985 IRL 1.0 20 b 0 30 w 1
|
275
|
+
001 10 w Ui Laighleis,Gearoidin 1985 IRL 1.0 20 b 0 30 w 1
|
270
276
|
001 20 m m Orr,Mark 2258 IRL 2.0 10 w 1 30 b 1
|
271
277
|
001 30 m g Bologan,Viktor 2663 MDA 0.0 10 b 0 20 w 0
|
272
278
|
KRAUSE
|
@@ -307,7 +313,7 @@ KRAUSE
|
|
307
313
|
@output = @p.serialize(@t)
|
308
314
|
end
|
309
315
|
|
310
|
-
it "should serialise
|
316
|
+
it "should serialise" do
|
311
317
|
@output.should == @krause
|
312
318
|
end
|
313
319
|
end
|
@@ -346,27 +352,27 @@ KRAUSE
|
|
346
352
|
|
347
353
|
it "removing the line on which the tournament name is specified should cause an error" do
|
348
354
|
@k.sub!('012 Gonzaga Classic', '')
|
349
|
-
lambda {
|
355
|
+
lambda { @p.parse!(@k) }.should raise_error(/name missing/)
|
350
356
|
end
|
351
357
|
|
352
358
|
it "blanking the tournament name should cause an error" do
|
353
359
|
@k.sub!('Gonzaga Classic', '')
|
354
|
-
lambda {
|
360
|
+
lambda { @p.parse!(@k) }.should raise_error(/name missing/)
|
355
361
|
end
|
356
362
|
|
357
363
|
it "blanking the start date should cause an error" do
|
358
364
|
@k.sub!('2008-02-01', '2008-02-04')
|
359
|
-
lambda {
|
365
|
+
lambda { @p.parse!(@k) }.should raise_error(/start.*after.*end/)
|
360
366
|
end
|
361
367
|
|
362
368
|
it "the start cannot be later than the end date" do
|
363
369
|
@k.sub!('2008-02-01', '')
|
364
|
-
lambda {
|
370
|
+
lambda { @p.parse!(@k) }.should raise_error(/start date missing/)
|
365
371
|
end
|
366
372
|
|
367
373
|
it "creating a duplicate player number should cause an error" do
|
368
374
|
@k.sub!(' 2 ', ' 1 ')
|
369
|
-
lambda {
|
375
|
+
lambda { @p.parse!(@k) }.should raise_error(/player number/)
|
370
376
|
end
|
371
377
|
|
372
378
|
it "creating a duplicate rank number should not cause an error becuse the tournament will be reranked" do
|
@@ -377,35 +383,35 @@ KRAUSE
|
|
377
383
|
|
378
384
|
it "referring to a non-existant player number should cause an error" do
|
379
385
|
@k.sub!(' 3 b 1', '33 b 1')
|
380
|
-
lambda {
|
386
|
+
lambda { @p.parse!(@k) }.should raise_error(/opponent number/)
|
381
387
|
end
|
382
388
|
|
383
389
|
it "inconsistent colours should cause an error" do
|
384
390
|
@k.sub!('3 b 1', '3 w 1')
|
385
|
-
lambda {
|
391
|
+
lambda { @p.parse!(@k) }.should raise_error(/result/)
|
386
392
|
end
|
387
393
|
|
388
394
|
it "inconsistent scores should cause an error" do
|
389
395
|
@k.sub!('3 b 1', '3 b =')
|
390
|
-
lambda {
|
396
|
+
lambda { @p.parse!(@k) }.should raise_error(/result/)
|
391
397
|
end
|
392
398
|
|
393
399
|
it "inconsistent totals should cause an error" do
|
394
400
|
@k.sub!('4.0', '4.5')
|
395
|
-
lambda {
|
401
|
+
lambda { @p.parse!(@k) }.should raise_error(/total/)
|
396
402
|
end
|
397
403
|
|
398
404
|
it "invalid federations should cause an error" do
|
399
405
|
@k.sub!('SCO', 'XYZ')
|
400
|
-
lambda {
|
406
|
+
lambda { @p.parse!(@k) }.should raise_error(/federation/)
|
401
407
|
end
|
402
408
|
|
403
409
|
it "removing any player that somebody else has played should cause an error" do
|
404
410
|
@k.sub!(/^001 12.*$/, '')
|
405
|
-
lambda {
|
411
|
+
lambda { @p.parse!(@k) }.should raise_error(/opponent/)
|
406
412
|
end
|
407
413
|
end
|
408
|
-
|
414
|
+
|
409
415
|
context "encoding" do
|
410
416
|
before(:all) do
|
411
417
|
@utf8 = <<KRAUSE
|
data/spec/tournament_sp_spec.rb
CHANGED
@@ -4,14 +4,14 @@ SAMPLES = File.dirname(__FILE__) + '/samples/sp/'
|
|
4
4
|
|
5
5
|
module ICU
|
6
6
|
class Tournament
|
7
|
-
def
|
7
|
+
def sp_signature
|
8
8
|
[name, arbiter, rounds, start, players.size].join("|")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
class Player
|
12
|
-
def
|
12
|
+
def sp_signature
|
13
13
|
[
|
14
|
-
name, id, fide, rating, points, rank,
|
14
|
+
name, id, fide, rating, fide_rating, points, rank,
|
15
15
|
results.map{ |r| r.round }.join(''),
|
16
16
|
results.map{ |r| r.score }.join(''),
|
17
17
|
results.map{ |r| r.colour || "-" }.join(''),
|
@@ -34,14 +34,14 @@ module ICU
|
|
34
34
|
|
35
35
|
it "should parse and have the right basic details" do
|
36
36
|
@p.error.should be_nil
|
37
|
-
@t.
|
37
|
+
@t.sp_signature.should == "Gonzaga Chess Classic 2010 Challengers Section|Herbert Scarry|6|2010-01-29|56"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should have correct details for selected players" do
|
41
|
-
@t.player(2).
|
42
|
-
@t.player(4).
|
43
|
-
@t.player(45).
|
44
|
-
@t.player(56).
|
41
|
+
@t.player(2).sp_signature.should == "Mullooly, Neil M.|6438||1083||6.0|1|123456|WWWWWW|WBWBWB|TTTTTT" # winner
|
42
|
+
@t.player(4).sp_signature.should == "Gallagher, Mark|12138||1036||4.0|9|123456|WLWWWL|WBWBWB|FTTTTT" # had one bye
|
43
|
+
@t.player(45).sp_signature.should == "Catre, Loredan|||507||3.5|18|123456|WDLWLW|BWBWBW|FTTTFT" # had two byes
|
44
|
+
@t.player(56).sp_signature.should == "McDonnell, Cathal|||498||0.0|54|1|L|-|F" # last
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should have consistent ranks" do
|
@@ -53,7 +53,7 @@ module ICU
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should serialize to the text export format" do
|
56
|
-
@t.serialize('
|
56
|
+
@t.serialize('SPExport').should == @s
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -66,14 +66,14 @@ module ICU
|
|
66
66
|
|
67
67
|
it "should parse and have the right basic details" do
|
68
68
|
@p.error.should be_nil
|
69
|
-
@t.
|
69
|
+
@t.sp_signature.should == "U - 19 All Ireland||3|2010-04-11|4"
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should have correct details for selected players" do
|
73
|
-
@t.player(1).
|
74
|
-
@t.player(2).
|
75
|
-
@t.player(3).
|
76
|
-
@t.player(4).
|
73
|
+
@t.player(1).sp_signature.should == "Griffiths, Ryan-Rhys|6897||2225||3.0|1|123|WWW|WWB|TTT"
|
74
|
+
@t.player(2).sp_signature.should == "Flynn, Jamie|5226||1633||2.0|2|123|WLW|WBW|TTT"
|
75
|
+
@t.player(3).sp_signature.should == "Hulleman, Leon|6409||1466||1.0|3|123|LWL|BBW|TTT"
|
76
|
+
@t.player(4).sp_signature.should == "Dunne, Thomas|10914||||0.0|4|123|LLL|BWB|TTT"
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should have consistent ranks" do
|
@@ -85,7 +85,7 @@ module ICU
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should serialize to the text export format" do
|
88
|
-
@t.rerank.renumber.serialize('
|
88
|
+
@t.rerank.renumber.serialize('SPExport').should == @s
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -97,16 +97,16 @@ module ICU
|
|
97
97
|
|
98
98
|
it "should parse and have the right basic details" do
|
99
99
|
@p.error.should be_nil
|
100
|
-
@t.
|
100
|
+
@t.sp_signature.should == "Limerick Club Championship 2009||7|2009-09-15|19"
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should have correct details for selected players" do
|
104
|
-
@t.player(15).
|
105
|
-
@t.player(6).
|
106
|
-
@t.player(19).
|
107
|
-
@t.player(17).
|
108
|
-
@t.player(18).
|
109
|
-
@t.player(16).
|
104
|
+
@t.player(15).sp_signature.should == "Talazec, Laurent|10692||1570||5.5|1|1234567|WWWDDDW|WWBWBWB|FTTTTTT" # winner
|
105
|
+
@t.player(6).sp_signature.should == "Foenander, Phillip|7168||1434||4.0|7|1234567|WLWLLWW|BWBWBWB|TTFFTTT" # had some byes
|
106
|
+
@t.player(19).sp_signature.should == "Wall, Robert|||||3.0|14|34567|WWLWL|WWBBW|FTTTT" # didn't play 1st 2 rounds
|
107
|
+
@t.player(17).sp_signature.should == "Freeman, Conor|||||2.0|16|1234567|DDLWLLL|--BWBWB|FFTTTTT" # had byes and bonus (in BONUS)
|
108
|
+
@t.player(18).sp_signature.should == "Freeman, Ruiri|||||2.0|17|1234567|DDLLLLW|--WBBWB|FFTTTTF" # had byes and bonus (in BONUS)
|
109
|
+
@t.player(16).sp_signature.should == "O'Connor, David|||||1.0|19|123|WLL|WBW|FTF" # last
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should have consistent ranks" do
|
@@ -126,14 +126,14 @@ module ICU
|
|
126
126
|
|
127
127
|
it "should parse and have the right basic details" do
|
128
128
|
@p.error.should be_nil
|
129
|
-
@t.
|
129
|
+
@t.sp_signature.should == "U16 Inter Provincials 2010|David B Murray|3|2010-02-02|18"
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should have correct details for selected players" do
|
133
|
-
@t.player(15).
|
134
|
-
@t.player(18).
|
135
|
-
@t.player(8).
|
136
|
-
@t.player(10).
|
133
|
+
@t.player(15).sp_signature.should == "Gupta, Radhika|||1247||3.0|1|123|WWW|BBW|TTT" # won all his games
|
134
|
+
@t.player(18).sp_signature.should == "Hurley, Thomas|6292||820||1.0|14|1|W|B|F" # scored just 1 from a bye in R1
|
135
|
+
@t.player(8).sp_signature.should == "Berney, Mark|10328||1948||2.0|3|23|WW|BW|TT" # didn't play in round 1
|
136
|
+
@t.player(10).sp_signature.should == "O'Donnell, Conor E.|10792||1073||2.0|10|123|LWW|WBW|TFT" # got just 1 point for a bye
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should have consistent ranks" do
|
@@ -153,15 +153,15 @@ module ICU
|
|
153
153
|
|
154
154
|
it "should parse and have the right basic details" do
|
155
155
|
@p.error.should be_nil
|
156
|
-
@t.
|
156
|
+
@t.sp_signature.should == "Mulcahy Cup 2010|Stephen Short|6|2010-01-15|50"
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should have correct details for selection of players who got bonuses (in MEMO)" do
|
160
|
-
@t.player(23).
|
161
|
-
@t.player(26).
|
162
|
-
@t.player(15).
|
163
|
-
@t.player(46).
|
164
|
-
@t.player(38).
|
160
|
+
@t.player(23).sp_signature.should == "Long, Killian|10293|2|1506||2.5|33|123456|WDLLWL|WWBWBB|TFTTTT"
|
161
|
+
@t.player(26).sp_signature.should == "Bradley, Michael|6756|27|1413||3.0|26|123456|DDLWWL|BWWBWW|TFTTTT"
|
162
|
+
@t.player(15).sp_signature.should == "Twomey, Pat|1637|22|1656||4.5|7|123456|WDLWWW|WWWBWB|FFTTTT"
|
163
|
+
@t.player(46).sp_signature.should == "O'Riordan, Pat|10696||900||2.0|42|123456|LDDLDD|BWBWWB|TTTTFT"
|
164
|
+
@t.player(38).sp_signature.should == "Gill, Craig I.|10637|28|1081||2.0|43|123456|LLWDDL|BWBWWB|TTTTFT"
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should have consistent ranks" do
|
@@ -177,22 +177,14 @@ module ICU
|
|
177
177
|
|
178
178
|
it "should parse and have the right basic details" do
|
179
179
|
@p.error.should be_nil
|
180
|
-
@t.
|
180
|
+
@t.sp_signature.should == "National Club Championship 2010|Gerry Graham|4|2010-05-08|77"
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should have correct details for selection of players, including ICU IDs" do
|
184
|
-
@t.player(2).
|
185
|
-
@t.player(5).
|
186
|
-
@t.player(8).
|
187
|
-
@t.player(67).
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should have correct details for selection of players, including international ratings when so configured" do
|
191
|
-
@t = @p.parse_file(SAMPLES + 'ncc', :start => "2010-05-08", :rating => :intl)
|
192
|
-
@t.player(2).signature.should == "Szabo, Gergely|12379|1205064||4.0|4|1234|WWWW|WBWB|TTTT"
|
193
|
-
@t.player(5).signature.should == "Daly, Colm|295|2500434||3.5|7|1234|WWWD|WBWB|TTTT"
|
194
|
-
@t.player(8).signature.should == "Vega, Marcos Llaneza||2253585||3.0|16|1234|DDWW|BWBW|TTTT"
|
195
|
-
@t.player(67).signature.should == "Lee, Shane|780|||1.0|52|134|DLD|WWW|TTT"
|
184
|
+
@t.player(2).sp_signature.should == "Szabo, Gergely|12379|1205064||2530|4.0|4|1234|WWWW|WBWB|TTTT"
|
185
|
+
@t.player(5).sp_signature.should == "Daly, Colm|295|2500434|2314||3.5|7|1234|WWWD|WBWB|TTTT"
|
186
|
+
@t.player(8).sp_signature.should == "Vega, Marcos Llaneza||2253585|2475||3.0|16|1234|DDWW|BWBW|TTTT"
|
187
|
+
@t.player(67).sp_signature.should == "Lee, Shane|780||1633||1.0|52|134|DLD|WWW|TTT"
|
196
188
|
end
|
197
189
|
end
|
198
190
|
|
@@ -279,14 +271,14 @@ module ICU
|
|
279
271
|
|
280
272
|
it "should parse and have the right basic details" do
|
281
273
|
@p.error.should be_nil
|
282
|
-
@t.
|
274
|
+
@t.sp_signature.should == "National Club Championship 2010|Gerry Graham|4|2010-05-08|77"
|
283
275
|
end
|
284
276
|
|
285
277
|
it "should have correct details for selection of players, including ICU IDs" do
|
286
|
-
@t.player(2).
|
287
|
-
@t.player(5).
|
288
|
-
@t.player(8).
|
289
|
-
@t.player(67).
|
278
|
+
@t.player(2).sp_signature.should == "Szabo, Gergely|12379|1205064||2530|4.0|4|1234|WWWW|WBWB|TTTT"
|
279
|
+
@t.player(5).sp_signature.should == "Daly, Colm|295|2500434|2314||3.5|7|1234|WWWD|WBWB|TTTT"
|
280
|
+
@t.player(8).sp_signature.should == "Vega, Marcos Llaneza||2253585|2475||3.0|16|1234|DDWW|BWBW|TTTT"
|
281
|
+
@t.player(67).sp_signature.should == "Lee, Shane|780||1633||1.0|52|134|DLD|WWW|TTT"
|
290
282
|
end
|
291
283
|
end
|
292
284
|
|
@@ -311,9 +303,9 @@ module ICU
|
|
311
303
|
|
312
304
|
it "should parse and the name should be in UTF-8" do
|
313
305
|
lambda { @t = @p.parse_file!(SAMPLES + 'munster_u10_2011.zip', :start => "2011-01-20") }.should_not raise_error
|
314
|
-
@t.player(1).
|
315
|
-
@t.player(4).
|
316
|
-
@t.player(10).
|
306
|
+
@t.player(1).sp_signature.should == "Kennedy, Stephen|||849||2.0|6|12345|WLWLL|BWBWB|TTTTT"
|
307
|
+
@t.player(4).sp_signature.should == "Sheehan, Ciarán|||||3.0|5|12345|LWWLW|WBWBW|TTTTF"
|
308
|
+
@t.player(10).sp_signature.should == "Sheehan, Adam|||||2.0|7|12345|WLLWL|WBWWB|TTTFT"
|
317
309
|
end
|
318
310
|
end
|
319
311
|
|
@@ -0,0 +1,379 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
module ICU
|
5
|
+
class Tournament
|
6
|
+
def spx_signature
|
7
|
+
[name, rounds, start, players.size].join("|")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class Player
|
11
|
+
def spx_signature
|
12
|
+
[
|
13
|
+
name, id, points,
|
14
|
+
results.map{ |r| r.round }.join(''),
|
15
|
+
results.map{ |r| r.score }.join(''),
|
16
|
+
results.map{ |r| r.colour || "-" }.join(''),
|
17
|
+
results.map{ |r| r.rateable ? 'T' : 'F' }.join(''),
|
18
|
+
].join("|")
|
19
|
+
end
|
20
|
+
def spx_signature2
|
21
|
+
[
|
22
|
+
results.map{ |r| r.round }.join(''),
|
23
|
+
results.map{ |r| r.score }.join(''),
|
24
|
+
results.map{ |r| r.rateable ? 'T' : 'F' }.join(''),
|
25
|
+
].join("|")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ICU
|
31
|
+
class Tournament
|
32
|
+
describe SPExport do
|
33
|
+
def samples
|
34
|
+
File.dirname(__FILE__) + '/samples/spx/'
|
35
|
+
end
|
36
|
+
|
37
|
+
context "documentation example" do
|
38
|
+
before(:each) do
|
39
|
+
@x = <<EXPORT
|
40
|
+
No Name Feder Intl Id Loc Id Rtg Loc Title Total 1 2 3
|
41
|
+
|
42
|
+
1 Duck, Daffy IRL 12345 2200 im 2 0:D 3:W 2:D
|
43
|
+
2 Mouse, Minerva 1234568 1900 1.5 3:D 0:D 1:D
|
44
|
+
3 Mouse, Mickey USA 1234567 gm 1 2:D 1:L 0:D
|
45
|
+
EXPORT
|
46
|
+
@p = ICU::Tournament::SPExport.new
|
47
|
+
@opt = { :name => "Mickey Mouse Masters", :start => "2012-01-01" }
|
48
|
+
@t = ICU::Tournament::SPExport.new.parse(@x, @opt)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should parse without exception" do
|
52
|
+
lambda { @p.parse!(@x, @opt) }.should_not raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should parse without error" do
|
56
|
+
@p.parse(@x, @opt)
|
57
|
+
@p.error.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "players should have all the right names and numbers" do
|
61
|
+
@t.player(1).name.should == "Duck, Daffy"
|
62
|
+
@t.player(2).name.should == "Mouse, Minerva"
|
63
|
+
@t.player(3).name.should == "Mouse, Mickey"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "players should have correct ICU IDs" do
|
67
|
+
@t.player(1).id.should == 12345
|
68
|
+
@t.player(2).id.should be_nil
|
69
|
+
@t.player(3).id.should be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "players should have correct FIDE IDs" do
|
73
|
+
@t.player(1).fide.should be_nil
|
74
|
+
@t.player(2).fide.should == 1234568
|
75
|
+
@t.player(3).fide.should == 1234567
|
76
|
+
end
|
77
|
+
|
78
|
+
it "players should have correct ICU ratings" do
|
79
|
+
@t.player(1).rating.should == 2200
|
80
|
+
@t.player(2).rating.should be_nil
|
81
|
+
@t.player(3).rating.should be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
it "players should have correct FIDE ratings" do
|
85
|
+
@t.player(1).fide_rating.should be_nil
|
86
|
+
@t.player(2).fide_rating.should == 1900
|
87
|
+
@t.player(3).fide_rating.should be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "players should have correct titles" do
|
91
|
+
@t.player(1).title.should == "IM"
|
92
|
+
@t.player(2).title.should be_nil
|
93
|
+
@t.player(3).title.should == "GM"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "players should have correct federations" do
|
97
|
+
@t.player(1).fed.should == "IRL"
|
98
|
+
@t.player(2).fed.should be_nil
|
99
|
+
@t.player(3).fed.should == "USA"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "players should have correct scores" do
|
103
|
+
@t.player(1).points.should == 2.0
|
104
|
+
@t.player(2).points.should == 1.5
|
105
|
+
@t.player(3).points.should == 1.0
|
106
|
+
end
|
107
|
+
|
108
|
+
it "players should have correct ranks" do
|
109
|
+
@t.player(1).rank.should == 1
|
110
|
+
@t.player(2).rank.should == 2
|
111
|
+
@t.player(3).rank.should == 3
|
112
|
+
end
|
113
|
+
|
114
|
+
it "players should have correct results" do
|
115
|
+
@t.player(1).spx_signature2.should == '123|DWD|FTT'
|
116
|
+
@t.player(2).spx_signature2.should == '123|DDD|TFT'
|
117
|
+
@t.player(3).spx_signature2.should == '123|DLD|TTF'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "serialisation" do
|
122
|
+
before(:each) do
|
123
|
+
name = "Bangor Masters"
|
124
|
+
start = "2009-11-09"
|
125
|
+
@t = ICU::Tournament.new(name, start)
|
126
|
+
@t.add_player(ICU::Player.new('Bobby', 'Fischer', 10))
|
127
|
+
@t.add_player(ICU::Player.new('Garry', 'Kasparov', 20))
|
128
|
+
@t.add_player(ICU::Player.new('Mark', 'Orr', 30, :id => 1350, :fide => 2500035, :fed => 'IRL', :rating => 2200, :fide_rating => 2250))
|
129
|
+
@t.add_result(ICU::Result.new(1, 10, 'D', :opponent => 30))
|
130
|
+
@t.add_result(ICU::Result.new(2, 20, 'W', :opponent => 30))
|
131
|
+
@t.add_result(ICU::Result.new(3, 20, 'L', :opponent => 10))
|
132
|
+
@p = ICU::Tournament::SPExport.new
|
133
|
+
@x = @t.serialize('SPExport')
|
134
|
+
@r = @p.parse(@x, :name => name, :start => start)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should round trip" do
|
138
|
+
@p.error.should be_nil
|
139
|
+
@r.spx_signature.should == "Bangor Masters|3|2009-11-09|3"
|
140
|
+
@r.player(1).spx_signature.should == "Fischer, Bobby||1.5|123|DLW|---|TFT"
|
141
|
+
@r.player(2).spx_signature.should == "Kasparov, Garry||1.0|123|LWL|---|FTT"
|
142
|
+
@r.player(3).spx_signature.should == "Orr, Mark|1350|0.5|123|DLL|---|TTF"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should have default columns" do
|
146
|
+
@x.should match(/^No\s*Name\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
147
|
+
@x.should match(/1\s*Fischer,\s*Bobby\s*1\.5\s*3:D\s*0?:L?\s*2:W\s*/)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "can have custom columns" do
|
151
|
+
@x = @t.serialize('SPExport', :columns => [])
|
152
|
+
@x.should match(/^No\s*Name\s*1\s*2\s*3\s*/)
|
153
|
+
@x = @t.serialize('SPExport', :columns => [:points])
|
154
|
+
@x.should match(/^No\s*Name\s*Total\s*1\s*2\s*3\s*/)
|
155
|
+
@x = @t.serialize('SPExport', :columns => [:points, :id])
|
156
|
+
@x.should match(/^No\s*Name\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
157
|
+
@x = @t.serialize('SPExport', :columns => [:points, :id, :fed])
|
158
|
+
@x.should match(/^No\s*Name\s*Feder\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
159
|
+
@x = @t.serialize('SPExport', :columns => [:points, :id, :fed, :fed, :rubbish, :fide])
|
160
|
+
@x.should match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
161
|
+
@x = @t.serialize('SPExport', :columns => [:fed, :fide, :points, :id, :rating])
|
162
|
+
@x.should match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Loc\s*Total\s*1\s*2\s*3\s*/)
|
163
|
+
@x = @t.serialize('SPExport', :columns => [:fed, :fide, :fide_rating, :points, :id, :rating])
|
164
|
+
@x.should match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Rtg\s*Loc\s*Total\s*1\s*2\s*3\s*/)
|
165
|
+
@x.should match(/3\s*Orr,\s*Mark\s*IRL\s*2500035\s*1350\s*2250\s*2200\s*0.5\s*1:D\s*2:L\s*:\s*/)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "invisible bonuses" do
|
170
|
+
before(:each) do
|
171
|
+
@x = <<EXPORT
|
172
|
+
No Name Total 1 2 3
|
173
|
+
|
174
|
+
1 Daffy Duck 2.0 0: 3:W 2:D
|
175
|
+
2 Mouse, Minerva 1.5 3:D 0: 1:D
|
176
|
+
3 Mouse, Mickey 1.0 2:D 1:L 0:D
|
177
|
+
EXPORT
|
178
|
+
@p = ICU::Tournament::SPExport.new
|
179
|
+
@t = @p.parse!(@x, :name => "Mickey Mouse Masters", :start => "2012-01-01")
|
180
|
+
end
|
181
|
+
|
182
|
+
it "players should have correct results" do
|
183
|
+
@t.player(1).spx_signature2.should == '123|DWD|FTT'
|
184
|
+
@t.player(2).spx_signature2.should == '123|DDD|TFT'
|
185
|
+
@t.player(3).spx_signature2.should == '123|DLD|TTF'
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "invisible bonuses extreme example" do
|
190
|
+
before(:each) do
|
191
|
+
@x = <<EXPORT
|
192
|
+
No Name Total 1 2 3
|
193
|
+
|
194
|
+
1 Daffy Duck 2.5 : : :
|
195
|
+
2 Mouse, Minerva 2.0 : : :
|
196
|
+
3 Mouse, Mickey 1.0 : : :
|
197
|
+
EXPORT
|
198
|
+
@p = ICU::Tournament::SPExport.new
|
199
|
+
@t = @p.parse!(@x, :name => "Mickey Mouse Masters", :start => "2012-01-01")
|
200
|
+
end
|
201
|
+
|
202
|
+
it "players should have correct results" do
|
203
|
+
@t.player(1).spx_signature2.should == '123|WWD|FFF'
|
204
|
+
@t.player(2).spx_signature2.should == '123|WDD|FFF'
|
205
|
+
@t.player(3).spx_signature2.should == '123|DDL|FFF'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "odds and ends" do
|
210
|
+
before(:each) do
|
211
|
+
@x = <<EXPORT
|
212
|
+
No Name Total 1 2 3
|
213
|
+
|
214
|
+
1 Daffy Duck 2.0 0:= 3:+ 2:d
|
215
|
+
2 Mouse, Minerva 1.0 3:= : 1:D
|
216
|
+
3 Mouse, Mickey 1.0 2:= 1:- 0:D
|
217
|
+
EXPORT
|
218
|
+
@p = ICU::Tournament::SPExport.new
|
219
|
+
@t = @p.parse!(@x, :name => "Mickey Mouse Masters", :start => "2012-01-01")
|
220
|
+
end
|
221
|
+
|
222
|
+
it "players should have all the right names and numbers" do
|
223
|
+
@t.player(1).name.should == "Duck, Daffy"
|
224
|
+
@t.player(2).name.should == "Mouse, Minerva"
|
225
|
+
@t.player(3).name.should == "Mouse, Mickey"
|
226
|
+
end
|
227
|
+
|
228
|
+
it "players should have correct results" do
|
229
|
+
@t.player(1).spx_signature2.should == '123|DWD|FFT'
|
230
|
+
@t.player(2).spx_signature2.should == '123|DLD|FFT'
|
231
|
+
@t.player(3).spx_signature2.should == '123|DLD|FFF'
|
232
|
+
end
|
233
|
+
|
234
|
+
it "players should have correct ranks given default name tie-break" do
|
235
|
+
@t.player(1).rank.should == 1
|
236
|
+
@t.player(2).rank.should == 3
|
237
|
+
@t.player(3).rank.should == 2
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "strings and encoding" do
|
242
|
+
before(:each) do
|
243
|
+
@p = ICU::Tournament::SPExport.new
|
244
|
+
@x = <<EXPORT
|
245
|
+
No Name Total 1 2
|
246
|
+
|
247
|
+
1 Dück, Dâffy 1.5 2:W 2:D
|
248
|
+
2 Möuse, Mickéy 0.5 1:L 1:D
|
249
|
+
EXPORT
|
250
|
+
@opt = { :name => "Test", :start => "2011-02-05" }
|
251
|
+
end
|
252
|
+
|
253
|
+
it "UTF-8" do
|
254
|
+
t = @p.parse(@x, @opt)
|
255
|
+
@p.error.should be_nil
|
256
|
+
t.player(1).name.should == "Dück, Dâffy"
|
257
|
+
t.player(2).name.should == "Möuse, Mickéy"
|
258
|
+
end
|
259
|
+
|
260
|
+
it "Latin-1" do
|
261
|
+
t = @p.parse(@x.encode("ISO-8859-1"), @opt)
|
262
|
+
@p.error.should be_nil
|
263
|
+
t.player(1).name.should == "Dück, Dâffy"
|
264
|
+
t.player(2).name.should == "Möuse, Mickéy"
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "errors" do
|
269
|
+
before(:each) do
|
270
|
+
@p = ICU::Tournament::SPExport.new
|
271
|
+
@opt = { :name => "Test", :start => "2011-02-05" }
|
272
|
+
end
|
273
|
+
|
274
|
+
it "correct example" do
|
275
|
+
data = <<EXPORT
|
276
|
+
No Name Total 1 2
|
277
|
+
|
278
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
279
|
+
2 Mouse, Mickey 0.5 1:L 1:D
|
280
|
+
EXPORT
|
281
|
+
lambda { @p.parse!(data, @opt) }.should_not raise_error
|
282
|
+
end
|
283
|
+
|
284
|
+
it "no header" do
|
285
|
+
data = <<EXPORT
|
286
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
287
|
+
2 Mouse, Mickey 0.5 1:L 1:L
|
288
|
+
EXPORT
|
289
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/header/)
|
290
|
+
end
|
291
|
+
|
292
|
+
it "invalid header" do
|
293
|
+
data = <<EXPORT
|
294
|
+
Xx Name Total 1 2
|
295
|
+
|
296
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
297
|
+
2 Mouse, Mickey 0.5 1:L 1:D
|
298
|
+
EXPORT
|
299
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/header/)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "missing round 1" do
|
303
|
+
data = <<EXPORT
|
304
|
+
No Name Total 2 3
|
305
|
+
|
306
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
307
|
+
2 Mouse, Mickey 0.0 1:L 1:L
|
308
|
+
EXPORT
|
309
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/round 1/)
|
310
|
+
end
|
311
|
+
|
312
|
+
it "missing round 2" do
|
313
|
+
data = <<EXPORT
|
314
|
+
No Name Total 1 3
|
315
|
+
|
316
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
317
|
+
2 Mouse, Mickey 0.0 1:L 1:L
|
318
|
+
EXPORT
|
319
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/round 2/)
|
320
|
+
end
|
321
|
+
|
322
|
+
it "incorrect total" do
|
323
|
+
data = <<EXPORT
|
324
|
+
No Name Total 1 2
|
325
|
+
|
326
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
327
|
+
2 Mouse, Mickey 1.0 1:L 1:D
|
328
|
+
EXPORT
|
329
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/total/)
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
it "mismatched results" do
|
334
|
+
data = <<EXPORT
|
335
|
+
No Name Total 1 2
|
336
|
+
|
337
|
+
1 Duck, Daffy 1.5 2:W 2:D
|
338
|
+
2 Mouse, Mickey 0.0 1:L 1:L
|
339
|
+
EXPORT
|
340
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/result/)
|
341
|
+
end
|
342
|
+
|
343
|
+
it "invalid attribute, title for example)" do
|
344
|
+
data = <<EXPORT
|
345
|
+
No Name Title Total 1 2
|
346
|
+
|
347
|
+
1 Duck, Daffy mg 1.5 2:W 2:D
|
348
|
+
2 Mouse, Mickey 0.5 1:L 1:D
|
349
|
+
EXPORT
|
350
|
+
lambda { @p.parse!(data, @opt) }.should raise_error(/title/)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
context "Gonzaga Challengers 2010 file" do
|
355
|
+
before(:each) do
|
356
|
+
@p = ICU::Tournament::SPExport.new
|
357
|
+
@t = @p.parse_file(samples + 'gonzaga_challengers_2010.txt', :name => "Gonzaga Chess Classic 2010 Challengers Section", :start => "2010-01-29")
|
358
|
+
@s = open(samples + 'gonzaga_challengers_2010.txt') { |f| f.read }
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should parse and have the right basic details" do
|
362
|
+
@p.error.should be_nil
|
363
|
+
@t.spx_signature.should == "Gonzaga Chess Classic 2010 Challengers Section|6|2010-01-29|56"
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should have correct details for selected players" do
|
367
|
+
@t.player(2).spx_signature.should == "Mullooly, Neil M.|6438|6.0|123456|WWWWWW|------|TTTTTT" # winner
|
368
|
+
@t.player(4).spx_signature.should == "Gallagher, Mark|12138|4.0|123456|WLWWWL|------|FTTTTT" # had one bye
|
369
|
+
@t.player(45).spx_signature.should == "Catre, Loredan||3.5|123456|WDLWLW|------|FTTTFT" # had two byes
|
370
|
+
@t.player(56).spx_signature.should == "McDonnell, Cathal||0.0|123456|LLLLLL|------|FFFFFF" # last, all defaults
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should have consistent ranks" do
|
374
|
+
@t.players.map{ |p| p.rank }.sort.join('').should == (1..@t.players.size).to_a.join('')
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|