icu_tournament 1.9.3 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +5 -1
- data/lib/icu_tournament/player.rb +1 -2
- data/lib/icu_tournament/result.rb +2 -2
- data/lib/icu_tournament/tournament.rb +38 -0
- data/lib/icu_tournament/tournament_fcsv.rb +1 -1
- data/lib/icu_tournament/tournament_krause.rb +19 -8
- data/lib/icu_tournament/util.rb +4 -4
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/player_spec.rb +118 -120
- data/spec/result_spec.rb +66 -66
- data/spec/team_spec.rb +16 -16
- data/spec/tie_break_spec.rb +51 -51
- data/spec/tournament_fcsv_spec.rb +94 -94
- data/spec/tournament_krause_spec.rb +170 -151
- data/spec/tournament_sp_spec.rb +89 -89
- data/spec/tournament_spec.rb +323 -276
- data/spec/tournament_spx_spec.rb +95 -95
- data/spec/util_spec.rb +127 -127
- metadata +59 -77
@@ -6,17 +6,17 @@ module ICU
|
|
6
6
|
describe Krause do
|
7
7
|
def check_player(num, first, last, other={})
|
8
8
|
p = @t.player(num)
|
9
|
-
p.first_name.
|
10
|
-
p.last_name.
|
9
|
+
expect(p.first_name).to eq(first)
|
10
|
+
expect(p.last_name).to eq(last)
|
11
11
|
[:gender, :title, :rating, :fide_rating, :fed, :id, :fide_id, :dob, :rank].each do |key|
|
12
|
-
p.send(key).
|
12
|
+
expect(p.send(key)).to eq(other[key]) if other.has_key?(key)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def check_results(num, results, points)
|
17
17
|
p = @t.player(num)
|
18
|
-
p.results.size.
|
19
|
-
p.points.
|
18
|
+
expect(p.results.size).to eq(results)
|
19
|
+
expect(p.points).to eq(points)
|
20
20
|
end
|
21
21
|
|
22
22
|
context "a typical tournament" do
|
@@ -47,30 +47,30 @@ KRAUSE
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should have a name, city and federation" do
|
50
|
-
@t.name.
|
51
|
-
@t.city.
|
52
|
-
@t.fed.
|
50
|
+
expect(@t.name).to eq('Las Vegas National Open')
|
51
|
+
expect(@t.city).to eq('Las Vegas')
|
52
|
+
expect(@t.fed).to eq('USA')
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should have start and end dates" do
|
56
|
-
@t.start.
|
57
|
-
@t.finish.
|
56
|
+
expect(@t.start).to eq('2008-06-07')
|
57
|
+
expect(@t.finish).to eq('2008-06-09')
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should have a number of rounds, a type and a time control" do
|
61
|
-
@t.rounds.
|
62
|
-
@t.last_round.
|
63
|
-
@t.type.
|
64
|
-
@t.time_control.
|
61
|
+
expect(@t.rounds).to eq(3)
|
62
|
+
expect(@t.last_round).to eq(3)
|
63
|
+
expect(@t.type).to eq('All-Play-All')
|
64
|
+
expect(@t.time_control).to eq('60 in 2hr, 30 in 1hr, rest in 1hr')
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should have an arbiter and deputies" do
|
68
|
-
@t.arbiter.
|
69
|
-
@t.deputy.
|
68
|
+
expect(@t.arbiter).to eq('Hans Scmidt')
|
69
|
+
expect(@t.deputy).to eq('Gerry Graham, Herbert Scarry')
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should have players and their details" do
|
73
|
-
@t.
|
73
|
+
expect(@t.players.size).to eq(3)
|
74
74
|
check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :fide_rating => 1985, :fed => 'IRL', :fide_id => 2501171, :dob => '1964-06-10', :rank => 2)
|
75
75
|
check_player(2, 'Mark', 'Orr', :gender => 'M', :fide_rating => 2258, :fed => 'IRL', :fide_id => 2500035, :dob => '1955-11-09', :rank => 1, :title => 'IM')
|
76
76
|
check_player(3, 'Viktor', 'Bologan', :gender => 'M', :fide_rating => 2663, :fed => 'MDA', :fide_id => 13900048, :dob => '1971-01-01', :rank => 3, :title => 'GM')
|
@@ -83,7 +83,7 @@ KRAUSE
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should have correct round dates" do
|
86
|
-
@t.round_dates.join('|').
|
86
|
+
expect(@t.round_dates.join('|')).to eq('2008-06-07|2008-06-08|2008-06-09')
|
87
87
|
end
|
88
88
|
|
89
89
|
it "the parser should retain comment lines" do
|
@@ -94,7 +94,7 @@ KRAUSE
|
|
94
94
|
0 1 2 3 4 5 6 7 8 9 0 1 2
|
95
95
|
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
|
96
96
|
COMMENTS
|
97
|
-
@p.comments.
|
97
|
+
expect(@p.comments).to eq(comments)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -115,22 +115,22 @@ KRAUSE
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should have a name and federation" do
|
118
|
-
@t.name.
|
119
|
-
@t.fed.
|
118
|
+
expect(@t.name).to eq('Fantasy Tournament')
|
119
|
+
expect(@t.fed).to eq('IRL')
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should have a various dates" do
|
123
|
-
@t.start.
|
124
|
-
@t.finish.
|
125
|
-
@t.round_dates.join('|').
|
123
|
+
expect(@t.start).to eq('2009-09-09')
|
124
|
+
expect(@t.finish).to eq('2009-09-11')
|
125
|
+
expect(@t.round_dates.join('|')).to eq('2009-09-09|2009-09-10|2009-09-11')
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should have a number of rounds" do
|
129
|
-
@t.rounds.
|
129
|
+
expect(@t.rounds).to eq(3)
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should have players and their details" do
|
133
|
-
@t.
|
133
|
+
expect(@t.players.size).to eq(3)
|
134
134
|
check_player(1, 'Minerva', 'Mouse', :gender => 'F', :rating => 1900, :fed => 'USA', :fide_id => 1234567, :dob => '1928-05-15', :rank => 2)
|
135
135
|
check_player(2, 'Daffy', 'Duck', :gender => 'M', :rating => 2200, :fed => 'IRL', :fide_id => 7654321, :dob => '1937-04-17', :rank => 1, :title => 'IM')
|
136
136
|
check_player(3, 'Mickey', 'Mouse', :gender => 'M', :rating => 2600, :fed => 'USA', :fide_id => 1726354, :dob => '1928-05-15', :rank => 3, :title => 'GM')
|
@@ -143,7 +143,7 @@ KRAUSE
|
|
143
143
|
end
|
144
144
|
|
145
145
|
it "the parser should retain comment lines" do
|
146
|
-
@p.comments.
|
146
|
+
expect(@p.comments).to eq("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n")
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -161,11 +161,11 @@ KRAUSE
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should produce a valid tournament" do
|
164
|
-
@t.invalid.
|
164
|
+
expect(@t.invalid).to be_falsey
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should produce output that looks reasonable" do
|
168
|
-
@k.
|
168
|
+
expect(@k).to match(/Fischer,Robert J\./)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -194,23 +194,23 @@ KRAUSE
|
|
194
194
|
|
195
195
|
it "should serialize back to the original if the input is fully canonicalised" do
|
196
196
|
t = @p.parse!(@krause, :fide => true)
|
197
|
-
ICU::Tournament::Krause.new.serialize(t, :fide => true).
|
197
|
+
expect(ICU::Tournament::Krause.new.serialize(t, :fide => true)).to eq(@krause)
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should serialize using the convenience method of the tournament object" do
|
201
201
|
t = @p.parse!(@krause, :fide => true)
|
202
|
-
t.serialize('Krause', :fide => true).
|
202
|
+
expect(t.serialize('Krause', :fide => true)).to eq(@krause)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should serialize only if :fide option is used correctly" do
|
206
206
|
t = @p.parse!(@krause, :fide => true)
|
207
|
-
t.serialize('Krause', :fide => true).
|
208
|
-
t.serialize('Krause').
|
207
|
+
expect(t.serialize('Krause', :fide => true)).to eq(@krause)
|
208
|
+
expect(t.serialize('Krause')).not_to eq(@krause)
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should not serialize correctly if mixed rating types are used" do
|
212
212
|
t = @p.parse!(@krause, :fide => true)
|
213
|
-
t.serialize('Krause').
|
213
|
+
expect(t.serialize('Krause')).not_to eq(@krause)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -228,9 +228,9 @@ KRAUSE
|
|
228
228
|
end
|
229
229
|
|
230
230
|
it "should have rankings automatically set" do
|
231
|
-
@t.player(1).rank.
|
232
|
-
@t.player(2).rank.
|
233
|
-
@t.player(3).rank.
|
231
|
+
expect(@t.player(1).rank).to eq(2)
|
232
|
+
expect(@t.player(2).rank).to eq(1)
|
233
|
+
expect(@t.player(3).rank).to eq(3)
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
@@ -293,12 +293,16 @@ REORDERED
|
|
293
293
|
|
294
294
|
it "should serialise correctly after renumbering by rank" do
|
295
295
|
@t.renumber
|
296
|
-
@p.serialize(@t).
|
296
|
+
expect(@p.serialize(@t)).to eq(@reordered)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
300
|
context "serialisation of a manually built tournament" do
|
301
301
|
before(:all) do
|
302
|
+
@dates = <<DATES
|
303
|
+
132 08-06-07 08-06-08 08-06-09
|
304
|
+
DATES
|
305
|
+
@dates.strip!
|
302
306
|
@krause = <<KRAUSE
|
303
307
|
012 Las Vegas National Open
|
304
308
|
042 2008-06-07
|
@@ -319,8 +323,17 @@ KRAUSE
|
|
319
323
|
end
|
320
324
|
|
321
325
|
it "should serialise" do
|
322
|
-
@output.
|
326
|
+
expect(@output).to eq(@krause)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should add round dates" do
|
330
|
+
@t.rounds = 3
|
331
|
+
@t.finish = ::Date.parse('2008-06-09')
|
332
|
+
output = @p.serialize(@t)
|
333
|
+
expect(output).not_to eq(@krause)
|
334
|
+
expect(output).to match(@dates)
|
323
335
|
end
|
336
|
+
|
324
337
|
end
|
325
338
|
|
326
339
|
context "customised serialisation with ICU IDs" do
|
@@ -340,52 +353,52 @@ KRAUSE
|
|
340
353
|
|
341
354
|
it "should include all data without any explict cusromisation" do
|
342
355
|
text = @t.serialize('Krause')
|
343
|
-
text.
|
344
|
-
text.
|
345
|
-
text.
|
356
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin 1985 IRL 3364 1964-06-10 1.0 2/)
|
357
|
+
expect(text).to match(/001 2 m Orr,Mark 2258 IRL 1350 1955-11-09 2.0 1/)
|
358
|
+
expect(text).to match(/001 3 g Svidler,Peter 2663 RUS 16790 1971-01-01 0.0 3/)
|
346
359
|
end
|
347
360
|
|
348
361
|
it "should omitt ratings and IDs if FIDE option is chosen" do
|
349
362
|
text = @t.serialize('Krause', :fide => true)
|
350
|
-
text.
|
351
|
-
text.
|
352
|
-
text.
|
363
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin IRL 1964-06-10 1.0 2/)
|
364
|
+
expect(text).to match(/001 2 m Orr,Mark IRL 1955-11-09 2.0 1/)
|
365
|
+
expect(text).to match(/001 3 g Svidler,Peter RUS 1971-01-01 0.0 3/)
|
353
366
|
end
|
354
367
|
|
355
368
|
it "should omitt all optional data if the :only option is an empty hash" do
|
356
369
|
text = @t.serialize('Krause', :only => [])
|
357
|
-
text.
|
358
|
-
text.
|
359
|
-
text.
|
370
|
+
expect(text).to match(/001 1 Ui Laighleis,Gearoidin 1.0 /)
|
371
|
+
expect(text).to match(/001 2 Orr,Mark 2.0 /)
|
372
|
+
expect(text).to match(/001 3 Svidler,Peter 0.0 /)
|
360
373
|
end
|
361
374
|
|
362
375
|
it "should should be able to include a subset of attributes, test 1" do
|
363
376
|
text = @t.serialize('Krause', :only => [:gender, "dob", :id, "rubbish"])
|
364
|
-
text.
|
365
|
-
text.
|
366
|
-
text.
|
377
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin 3364 1964-06-10 1.0 /)
|
378
|
+
expect(text).to match(/001 2 Orr,Mark 1350 1955-11-09 2.0 /)
|
379
|
+
expect(text).to match(/001 3 Svidler,Peter 16790 1971-01-01 0.0 /)
|
367
380
|
end
|
368
381
|
|
369
382
|
it "should should be able to include a subset of attributes, test 2" do
|
370
383
|
text = @t.serialize('Krause', :only => [:rank, "title", :fed, "rating"])
|
371
|
-
text.
|
372
|
-
text.
|
373
|
-
text.
|
384
|
+
expect(text).to match(/001 1 Ui Laighleis,Gearoidin 1985 IRL 1.0 2/)
|
385
|
+
expect(text).to match(/001 2 m Orr,Mark 2258 IRL 2.0 1/)
|
386
|
+
expect(text).to match(/001 3 g Svidler,Peter 2663 RUS 0.0 3/)
|
374
387
|
end
|
375
388
|
|
376
389
|
it "should should be able to include all attributes" do
|
377
390
|
text = @t.serialize('Krause', :only => [:gender, :title, :rating, :fed, :id, :dob, :rank])
|
378
|
-
text.
|
379
|
-
text.
|
380
|
-
text.
|
391
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin 1985 IRL 3364 1964-06-10 1.0 2/)
|
392
|
+
expect(text).to match(/001 2 m Orr,Mark 2258 IRL 1350 1955-11-09 2.0 1/)
|
393
|
+
expect(text).to match(/001 3 g Svidler,Peter 2663 RUS 16790 1971-01-01 0.0 3/)
|
381
394
|
end
|
382
395
|
|
383
396
|
it "the :only and :except options are logical opposites" do
|
384
|
-
@t.serialize('Krause', :only => [:gender, :title, :rating]).
|
385
|
-
@t.serialize('Krause', :only => [:gender]).
|
386
|
-
@t.serialize('Krause', :only => [:gender, :title, "rating", :fed, :id, :dob]).
|
387
|
-
@t.serialize('Krause', :only => [:gender, :title, :rating, :fed, "id", :dob, :rank]).
|
388
|
-
@t.serialize('Krause', :only => []).
|
397
|
+
expect(@t.serialize('Krause', :only => [:gender, :title, :rating])).to eq(@t.serialize('Krause', :except => [:fed, :id, "dob", :rank]))
|
398
|
+
expect(@t.serialize('Krause', :only => [:gender])).to eq(@t.serialize('Krause', :except => [:fed, :id, :dob, :rank, :title, :rating]))
|
399
|
+
expect(@t.serialize('Krause', :only => [:gender, :title, "rating", :fed, :id, :dob])).to eq(@t.serialize('Krause', :except => [:rank]))
|
400
|
+
expect(@t.serialize('Krause', :only => [:gender, :title, :rating, :fed, "id", :dob, :rank])).to eq(@t.serialize('Krause', :except => []))
|
401
|
+
expect(@t.serialize('Krause', :only => [])).to eq(@t.serialize('Krause', :except => [:gender, :title, :rating, :fed, :id, :dob, :rank]))
|
389
402
|
end
|
390
403
|
end
|
391
404
|
|
@@ -406,44 +419,44 @@ KRAUSE
|
|
406
419
|
|
407
420
|
it "should include all data without any explict cusromisation" do
|
408
421
|
text = @t.serialize('Krause', :fide => true)
|
409
|
-
text.
|
410
|
-
text.
|
411
|
-
text.
|
422
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964-06-10 1.0 2/)
|
423
|
+
expect(text).to match(/001 2 m Orr,Mark 2258 IRL 2500035 1955-11-09 2.0 1/)
|
424
|
+
expect(text).to match(/001 3 g Svidler,Peter 2663 RUS 4102142 1971-01-01 0.0 3/)
|
412
425
|
end
|
413
426
|
|
414
427
|
it "should omitt ratings and IDs if FIDE option is not chosen" do
|
415
428
|
text = @t.serialize('Krause')
|
416
|
-
text.
|
417
|
-
text.
|
418
|
-
text.
|
429
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin IRL 1964-06-10 1.0 2/)
|
430
|
+
expect(text).to match(/001 2 m Orr,Mark IRL 1955-11-09 2.0 1/)
|
431
|
+
expect(text).to match(/001 3 g Svidler,Peter RUS 1971-01-01 0.0 3/)
|
419
432
|
end
|
420
433
|
|
421
434
|
it "should omitt all optional data if the :only option is an empty hash" do
|
422
435
|
text = @t.serialize('Krause', :only => [])
|
423
|
-
text.
|
424
|
-
text.
|
425
|
-
text.
|
436
|
+
expect(text).to match(/001 1 Ui Laighleis,Gearoidin 1.0 /)
|
437
|
+
expect(text).to match(/001 2 Orr,Mark 2.0 /)
|
438
|
+
expect(text).to match(/001 3 Svidler,Peter 0.0 /)
|
426
439
|
end
|
427
440
|
|
428
441
|
it "should should be able to include a subset of attributes, test 1" do
|
429
442
|
text = @t.serialize('Krause', :only => [:gender, "dob", :id], :fide => true)
|
430
|
-
text.
|
431
|
-
text.
|
432
|
-
text.
|
443
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin 2501171 1964-06-10 1.0 /)
|
444
|
+
expect(text).to match(/001 2 Orr,Mark 2500035 1955-11-09 2.0 /)
|
445
|
+
expect(text).to match(/001 3 Svidler,Peter 4102142 1971-01-01 0.0 /)
|
433
446
|
end
|
434
447
|
|
435
448
|
it "should should be able to include a subset of attributes, test 2" do
|
436
449
|
text = @t.serialize('Krause', :only => [:rank, "title", :fed, "rating", :rubbish], :fide => true)
|
437
|
-
text.
|
438
|
-
text.
|
439
|
-
text.
|
450
|
+
expect(text).to match(/001 1 Ui Laighleis,Gearoidin 1985 IRL 1.0 2/)
|
451
|
+
expect(text).to match(/001 2 m Orr,Mark 2258 IRL 2.0 1/)
|
452
|
+
expect(text).to match(/001 3 g Svidler,Peter 2663 RUS 0.0 3/)
|
440
453
|
end
|
441
454
|
|
442
455
|
it "should should be able to include all attributes" do
|
443
456
|
text = @t.serialize('Krause', :only => [:gender, :title, :rating, :fed, :id, :dob, :rank], :fide => true)
|
444
|
-
text.
|
445
|
-
text.
|
446
|
-
text.
|
457
|
+
expect(text).to match(/001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964-06-10 1.0 2/)
|
458
|
+
expect(text).to match(/001 2 m Orr,Mark 2258 IRL 2500035 1955-11-09 2.0 1/)
|
459
|
+
expect(text).to match(/001 3 g Svidler,Peter 2663 RUS 4102142 1971-01-01 0.0 3/)
|
447
460
|
end
|
448
461
|
end
|
449
462
|
|
@@ -477,85 +490,85 @@ KRAUSE
|
|
477
490
|
end
|
478
491
|
|
479
492
|
it "the unaltered example is valid Krause" do
|
480
|
-
|
493
|
+
expect { @p.parse!(@k) }.not_to raise_error
|
481
494
|
end
|
482
495
|
|
483
496
|
it "removing the line on which the tournament name is specified should cause an error" do
|
484
|
-
|
497
|
+
expect { @p.parse!(@k.sub('012 Gonzaga Classic', '')) }.to raise_error(/name missing/)
|
485
498
|
end
|
486
499
|
|
487
500
|
it "blanking the tournament name should cause an error" do
|
488
501
|
@k.sub!('Gonzaga Classic', '')
|
489
|
-
|
502
|
+
expect { @p.parse!(@k) }.to raise_error(/name missing/)
|
490
503
|
end
|
491
504
|
|
492
505
|
it "the start cannot be later than the end date" do
|
493
|
-
|
506
|
+
expect { @p.parse!(@k.sub('2008-02-21', '2008-03-21')) }.to raise_error(/start.*after.*end/)
|
494
507
|
end
|
495
508
|
|
496
509
|
it "blanking the start date should cause an error" do
|
497
|
-
|
510
|
+
expect { @p.parse!(@k.sub('2008-02-21', '')) }.to raise_error(/start date missing/)
|
498
511
|
end
|
499
512
|
|
500
513
|
it "the first and last round dates should match the tournament start and end dates" do
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
514
|
+
expect { @p.parse!(@k.sub('08.02.21', '08.02.20')) }.to raise_error(/first round.*not match.*start/)
|
515
|
+
expect { @p.parse!(@k.sub('08.02.21', '08.02.22')) }.to raise_error(/first round.*not match.*start/)
|
516
|
+
expect { @p.parse!(@k.sub('08.02.25', '08.02.24')) }.to raise_error(/last round.*not match.*end/)
|
517
|
+
expect { @p.parse!(@k.sub('08.02.25', '08.02.26')) }.to raise_error(/last round.*not match.*end/)
|
505
518
|
end
|
506
519
|
|
507
520
|
it "the round dates should never decrease" do
|
508
|
-
|
521
|
+
expect { @p.parse!(@k.sub('08.02.24', '08.02.22')) }.to raise_error(/round 3.*after.*round 4/)
|
509
522
|
end
|
510
523
|
|
511
524
|
it "bad round dates can be ignored" do
|
512
|
-
|
513
|
-
|
525
|
+
expect { @p.parse!(@k.sub('08.02.21', '08.02.20'), :round_dates => "ignore") }.not_to raise_error
|
526
|
+
expect { @p.parse!(@k.sub('08.02.24', '08.02.22'), :round_dates => "ignore") }.not_to raise_error
|
514
527
|
end
|
515
528
|
|
516
529
|
it "creating a duplicate player number should cause an error" do
|
517
|
-
|
530
|
+
expect { @p.parse!(@k.sub(' 2 ', ' 1 ')) }.to raise_error(/player number/)
|
518
531
|
end
|
519
532
|
|
520
533
|
it "creating a duplicate rank number should not cause an error becuse the tournament will be reranked" do
|
521
534
|
t = @p.parse!(@k.sub('4.0 1', '4.0 2'))
|
522
|
-
t.player(1).rank.
|
535
|
+
expect(t.player(1).rank).to eq(1)
|
523
536
|
end
|
524
537
|
|
525
538
|
it "referring to a non-existant player number should cause an error" do
|
526
|
-
|
539
|
+
expect { @p.parse!(@k.sub(' 3 b 1', '33 b 1')) }.to raise_error(/opponent number/)
|
527
540
|
end
|
528
541
|
|
529
542
|
it "inconsistent colours should cause an error" do
|
530
|
-
|
543
|
+
expect { @p.parse!(@k.sub('3 b 1', '3 w 1')) }.to raise_error(/result/)
|
531
544
|
end
|
532
545
|
|
533
546
|
it "inconsistent scores should cause an error" do
|
534
|
-
|
547
|
+
expect { @p.parse!(@k.sub('3 b 1', '3 b =')) }.to raise_error(/result/)
|
535
548
|
end
|
536
549
|
|
537
550
|
it "inconsistent totals should cause an error" do
|
538
|
-
|
551
|
+
expect { @p.parse!(@k.sub('3.5', '4.0')) }.to raise_error(/total/)
|
539
552
|
end
|
540
553
|
|
541
554
|
it "invalid federations should cause an error unless an option is used" do
|
542
555
|
@k.sub!('SCO', 'XYZ')
|
543
|
-
|
544
|
-
|
545
|
-
@t.player(5).fed.
|
546
|
-
@t.player(1).fed.
|
547
|
-
|
548
|
-
@t.player(5).fed.
|
549
|
-
@t.player(1).fed.
|
556
|
+
expect { @p.parse!(@k) }.to raise_error(/federation/)
|
557
|
+
expect { @t = @p.parse!(@k, :fed => "skip") }.not_to raise_error
|
558
|
+
expect(@t.player(5).fed).to be_nil
|
559
|
+
expect(@t.player(1).fed).to eq("IRL")
|
560
|
+
expect { @t = @p.parse!(@k, :fed => "ignore") }.not_to raise_error
|
561
|
+
expect(@t.player(5).fed).to be_nil
|
562
|
+
expect(@t.player(1).fed).to be_nil
|
550
563
|
end
|
551
564
|
|
552
565
|
it "an invalid DOB is silently ignored" do
|
553
|
-
|
554
|
-
@t.player(1).dob.
|
566
|
+
expect { @t = @p.parse!(@k.sub(/1993-12-20/, '1993 ')) }.not_to raise_error
|
567
|
+
expect(@t.player(1).dob).to be_nil
|
555
568
|
end
|
556
569
|
|
557
570
|
it "removing any player that somebody else has played should cause an error" do
|
558
|
-
|
571
|
+
expect { @p.parse!(@k.sub(/^001 12.*$/, '')) }.to raise_error(/opponent/)
|
559
572
|
end
|
560
573
|
end
|
561
574
|
|
@@ -576,7 +589,7 @@ KRAUSE
|
|
576
589
|
check_player(1, 'Gearoìdin', 'Uì Laighlèis')
|
577
590
|
check_player(2, 'Mârk', 'Örr')
|
578
591
|
check_player(3, 'Viktor', 'Bologan')
|
579
|
-
@t.name.
|
592
|
+
expect(@t.name).to eq("Läs Végas National Opeñ")
|
580
593
|
end
|
581
594
|
|
582
595
|
it "should handle Latin-1" do
|
@@ -585,7 +598,7 @@ KRAUSE
|
|
585
598
|
check_player(1, 'Gearoìdin', 'Uì Laighlèis')
|
586
599
|
check_player(2, 'Mârk', 'Örr')
|
587
600
|
check_player(3, 'Viktor', 'Bologan')
|
588
|
-
@t.name.
|
601
|
+
expect(@t.name).to eq("Läs Végas National Opeñ")
|
589
602
|
end
|
590
603
|
end
|
591
604
|
|
@@ -606,9 +619,9 @@ KRAUSE
|
|
606
619
|
check_player(1, 'Gearoidin', 'Ui Laighleis')
|
607
620
|
check_player(2, 'Mark', 'Orr')
|
608
621
|
check_player(3, 'Viktor', 'Bologan')
|
609
|
-
@t.player(1).original_name.
|
610
|
-
@t.player(2).original_name.
|
611
|
-
@t.player(3).original_name.
|
622
|
+
expect(@t.player(1).original_name).to eq("ui laighleis, GEAROIDIN")
|
623
|
+
expect(@t.player(2).original_name).to eq("ORR, mark")
|
624
|
+
expect(@t.player(3).original_name).to eq("BOLOGAN, VIKTOR")
|
612
625
|
end
|
613
626
|
end
|
614
627
|
|
@@ -620,49 +633,49 @@ KRAUSE
|
|
620
633
|
|
621
634
|
it "should error on a non-existant valid file" do
|
622
635
|
file = "#{@s}/not_there.tab"
|
623
|
-
|
636
|
+
expect { @p.parse_file!(file) }.to raise_error
|
624
637
|
t = @p.parse_file(file)
|
625
|
-
t.
|
626
|
-
@p.error.
|
638
|
+
expect(t).to be_nil
|
639
|
+
expect(@p.error).to match(/no such file/i)
|
627
640
|
end
|
628
641
|
|
629
642
|
it "should error on an invalid file" do
|
630
643
|
file = "#{@s}/invalid.tab"
|
631
|
-
|
644
|
+
expect { @p.parse_file!(file) }.to raise_error
|
632
645
|
t = @p.parse_file(file)
|
633
|
-
t.
|
634
|
-
@p.error.
|
646
|
+
expect(t).to be_nil
|
647
|
+
expect(@p.error).to match(/tournament name missing/i)
|
635
648
|
end
|
636
649
|
|
637
650
|
it "should parse a valid file" do
|
638
651
|
file = "#{@s}/valid.tab"
|
639
|
-
|
652
|
+
expect { @p.parse_file!(file) }.not_to raise_error
|
640
653
|
t = @p.parse_file(file)
|
641
|
-
t.
|
642
|
-
t.players.size.
|
654
|
+
expect(t).to be_an_instance_of(ICU::Tournament)
|
655
|
+
expect(t.players.size).to eq(12)
|
643
656
|
end
|
644
657
|
|
645
658
|
it "should parse a file with UTF-8 encoding" do
|
646
659
|
file = "#{@s}/utf-8.tab"
|
647
|
-
|
660
|
+
expect { @t = @p.parse_file!(file) }.not_to raise_error
|
648
661
|
check_player(1, 'Gearoìdin', 'Uì Laighlèis')
|
649
662
|
check_player(2, 'Mârk', 'Örr')
|
650
663
|
check_player(3, 'Viktor', 'Bologan')
|
651
|
-
@t.name.
|
664
|
+
expect(@t.name).to eq("Läs Végas National Opeñ")
|
652
665
|
end
|
653
666
|
|
654
667
|
it "should parse a file with Latin-1 encoding" do
|
655
668
|
file = "#{@s}/latin-1.tab"
|
656
|
-
|
669
|
+
expect { @t = @p.parse_file!(file) }.not_to raise_error
|
657
670
|
check_player(1, 'Gearoìdin', 'Uì Laighlèis')
|
658
671
|
check_player(2, 'Mârk', 'Örr')
|
659
672
|
check_player(3, 'Viktor', 'Bologan')
|
660
|
-
@t.name.
|
673
|
+
expect(@t.name).to eq("Läs Végas National Opeñ")
|
661
674
|
end
|
662
675
|
|
663
676
|
it "should parse a large file with total scores as much as 10.0" do
|
664
677
|
file = "#{@s}/armstrong_2011.tab"
|
665
|
-
|
678
|
+
expect { @t = @p.parse_file!(file) }.not_to raise_error
|
666
679
|
end
|
667
680
|
end
|
668
681
|
|
@@ -678,7 +691,7 @@ KRAUSE
|
|
678
691
|
001 1 Ui Laighleis,Gearoidin 0.5 2 b 0 2 w 0
|
679
692
|
001 2 Or,Mark 2.0 1 w 1 1 b 1
|
680
693
|
KRAUSE
|
681
|
-
|
694
|
+
expect { @p.parse!(@k) }.to raise_error(/total/)
|
682
695
|
end
|
683
696
|
|
684
697
|
it "cannot repair mismatched totals if totals are underestimated" do
|
@@ -688,7 +701,7 @@ KRAUSE
|
|
688
701
|
001 1 Ui Laighleis,Gearoidin 0.0 2 b 0 0000 - -
|
689
702
|
001 2 Orr,Mark 1.5 1 w 1 0000 - +
|
690
703
|
KRAUSE
|
691
|
-
|
704
|
+
expect { @p.parse!(@k) }.to raise_error(/total/)
|
692
705
|
end
|
693
706
|
|
694
707
|
it "cannot repair overestimated totals if there are not enough byes" do
|
@@ -698,7 +711,7 @@ KRAUSE
|
|
698
711
|
001 1 Ui Laighleis,Gearoidin 1.5 2 b 0 0000 - -
|
699
712
|
001 2 Orr,Mark 2.0 1 w 1 0000 - +
|
700
713
|
KRAUSE
|
701
|
-
|
714
|
+
expect { @p.parse!(@k) }.to raise_error(/total/)
|
702
715
|
end
|
703
716
|
|
704
717
|
it "can repair overestimated totals if there are enough byes" do
|
@@ -709,9 +722,9 @@ KRAUSE
|
|
709
722
|
001 2 ORR,Mark 2.0 1 w 1 0000 - +
|
710
723
|
KRAUSE
|
711
724
|
@t = @p.parse!(@k)
|
712
|
-
@t.
|
725
|
+
expect(@t).not_to be_nil
|
713
726
|
check_results(1, 2, 1.0)
|
714
|
-
@t.player(1).find_result(2).score.
|
727
|
+
expect(@t.player(1).find_result(2).score).to eq('W')
|
715
728
|
end
|
716
729
|
|
717
730
|
it "extreme example" do
|
@@ -724,11 +737,11 @@ KRAUSE
|
|
724
737
|
001 4 Knox,Angela 2.5 0000 - - 3 w 1 0000 - -
|
725
738
|
KRAUSE
|
726
739
|
@t = @p.parse!(@k)
|
727
|
-
@t.
|
728
|
-
@t.player(1).results.map(&:score).join('').
|
729
|
-
@t.player(2).results.map(&:score).join('').
|
730
|
-
@t.player(3).results.map(&:score).join('').
|
731
|
-
@t.player(4).results.map(&:score).join('').
|
740
|
+
expect(@t).not_to be_nil
|
741
|
+
expect(@t.player(1).results.map(&:score).join('')).to eq('LWW')
|
742
|
+
expect(@t.player(2).results.map(&:score).join('')).to eq('WWD')
|
743
|
+
expect(@t.player(3).results.map(&:score).join('')).to eq('DLD')
|
744
|
+
expect(@t.player(4).results.map(&:score).join('')).to eq('WWD')
|
732
745
|
end
|
733
746
|
|
734
747
|
it "should work on the documentation example" do
|
@@ -745,7 +758,7 @@ KRAUSE
|
|
745
758
|
001 1 Mouse,Minerva 1.0 2 2 b 0 0000 - +
|
746
759
|
001 2 Mouse,Mickey 1.5 1 1 w 1 0000 - =
|
747
760
|
KRAUSE
|
748
|
-
@t.serialize('Krause').
|
761
|
+
expect(@t.serialize('Krause')).to eq(output)
|
749
762
|
end
|
750
763
|
end
|
751
764
|
|
@@ -758,17 +771,17 @@ KRAUSE
|
|
758
771
|
it "should handle Bunratty Masters 2011" do
|
759
772
|
file = "#{@s}/bunratty_masters_2011.tab"
|
760
773
|
@t = @p.parse_file(file, :fed => :skip, :fide => true)
|
761
|
-
@t.
|
762
|
-
@t.start.
|
763
|
-
@t.finish.
|
774
|
+
expect(@t).not_to be_nil
|
775
|
+
expect(@t.start).to eq("2011-02-25")
|
776
|
+
expect(@t.finish).to eq("2011-02-27")
|
764
777
|
check_player(1, 'Nigel', 'Short', :gender => 'M', :fide_rating => 2658, :fed => 'ENG', :rating => nil, :rank => 5, :title => 'GM')
|
765
778
|
check_results(1, 6, 4.0)
|
766
779
|
check_player(16, 'Jonathan', "O'Connor", :gender => 'M', :fide_rating => 2111, :fed => nil, :rating => nil, :rank => 25, :title => nil)
|
767
780
|
check_results(16, 6, 2.5)
|
768
|
-
@t.player(16).results.map(&:score).join('').
|
781
|
+
expect(@t.player(16).results.map(&:score).join('')).to eq('DWLDDL')
|
769
782
|
check_player(24, 'David', 'Murray', :gender => 'M', :fide_rating => 2023, :fed => nil, :rating => nil, :rank => 34, :title => nil)
|
770
783
|
check_results(24, 2, 0.5)
|
771
|
-
@t.player(24).results.map(&:score).join('').
|
784
|
+
expect(@t.player(24).results.map(&:score).join('')).to eq('LD')
|
772
785
|
check_player(26, 'Alexandra', 'Wilson', :gender => 'F', :fide_rating => 2020, :fed => 'ENG', :rating => nil, :rank => 29, :title => 'WFM')
|
773
786
|
check_results(26, 6, 2.0)
|
774
787
|
end
|
@@ -776,9 +789,9 @@ KRAUSE
|
|
776
789
|
it "should handle Bunratty Major 2011" do
|
777
790
|
file = "#{@s}/bunratty_major_2011.tab"
|
778
791
|
@t = @p.parse_file(file, :fed => :ignore)
|
779
|
-
@t.
|
780
|
-
@t.start.
|
781
|
-
@t.finish.
|
792
|
+
expect(@t).not_to be_nil
|
793
|
+
expect(@t.start).to eq("2011-02-25")
|
794
|
+
expect(@t.finish).to eq("2011-02-27")
|
782
795
|
check_player(1, 'Dan', 'Clancy', :gender => 'M', :fide_rating => nil, :fed => nil, :id => 204, :rating => nil, :rank => 12)
|
783
796
|
check_results(1, 6, 4)
|
784
797
|
check_player(10, 'Phillip', 'Foenander', :gender => 'M', :fide_rating => nil, :fed => nil, :id => 7168, :rating => nil, :rank => 18)
|
@@ -789,27 +802,33 @@ KRAUSE
|
|
789
802
|
|
790
803
|
it "should handle bunratty_minor_2011.tab" do
|
791
804
|
file = "#{@s}/bunratty_minor_2011.tab"
|
792
|
-
|
805
|
+
expect { @p.parse_file!(file, :fed => :ignore) }.not_to raise_error
|
793
806
|
end
|
794
807
|
|
795
808
|
it "should handle Bunratty Challengers 2011" do
|
796
809
|
file = "#{@s}/bunratty_challengers_2011.tab"
|
797
|
-
|
810
|
+
expect { @p.parse_file!(file, :fed => :ignore) }.not_to raise_error
|
798
811
|
end
|
799
812
|
|
800
813
|
it "should handle Irish Intermediate Championships 2011" do
|
801
814
|
file = "#{@s}/irish_intermediate_champs_2011.tab"
|
802
|
-
|
815
|
+
expect { @p.parse_file!(file) }.not_to raise_error
|
803
816
|
end
|
804
817
|
|
805
818
|
it "should handle Irish Junior Championships 2011" do
|
806
819
|
file = "#{@s}/irish_junior_champs_2011.tab"
|
807
|
-
|
820
|
+
expect { @p.parse_file!(file) }.not_to raise_error
|
821
|
+
end
|
822
|
+
|
823
|
+
it "should handle Cork Major 2018 (Swiss Master format)" do
|
824
|
+
file = "#{@s}/cork_major_2018_swissmaster.tab"
|
825
|
+
@t = @p.parse_file(file, :fed => :ignore)
|
826
|
+
check_results(1, 6, 3.5)
|
808
827
|
end
|
809
828
|
|
810
829
|
it "should handle a file with a BOM" do
|
811
830
|
file = "#{@s}/armstrong_2012_with_bom.tab"
|
812
|
-
|
831
|
+
expect { @p.parse_file!(file) }.not_to raise_error
|
813
832
|
end
|
814
833
|
end
|
815
834
|
end
|