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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a381a56e723de1cfb4dd03d9b48d30bec0392949664a0ec79fb8436c293e0eef
|
4
|
+
data.tar.gz: c3e6cb085ec3023bed84e7b9a1a081b542572150e63ee17a8c518cb37c36a46c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79f24f02e5cc402a54b88dc3843666277ea05ce0713b3ed3130294518a04579693a8779fe0a5e38b8890ee69b604d79b4864ab830226db40812812b3d15d3d37
|
7
|
+
data.tar.gz: 6d3db507492a9cccbdab10be94fc1fbd8de9b2a3f436c3746443c053eeec1b9157797fb23ee3dc3b4765110ce427b49d5a5e4ca53101f723828517af454063c5
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ For reading or writing files of chess tournament data. Original project name on
|
|
4
4
|
|
5
5
|
== Install
|
6
6
|
|
7
|
-
For Ruby 1.9.2, 1.9.3, 2.0.0 (version 1.1.2 was the last compatible with Ruby 1.8.7).
|
7
|
+
For Ruby 1.9.2, 1.9.3, 2.0.0, 2.2.1 (version 1.1.2 was the last compatible with Ruby 1.8.7).
|
8
8
|
|
9
9
|
gem install icu_tournament
|
10
10
|
|
@@ -74,3 +74,7 @@ On error, the _parse_ method returns _nil_ and an error message can be retrieved
|
|
74
74
|
== Author
|
75
75
|
|
76
76
|
Mark Orr, rating officer for the Irish Chess Union (ICU[http://icu.ie]).
|
77
|
+
|
78
|
+
== Current Maintainer
|
79
|
+
|
80
|
+
David Murray, rating officer for the Irish Chess Union. Contact ratings@icu.ie.
|
@@ -119,7 +119,6 @@ module ICU
|
|
119
119
|
# Canonicalise and set the first name(s).
|
120
120
|
def first_name=(first_name)
|
121
121
|
name = Name.new(first_name, 'Last')
|
122
|
-
raise "invalid first name" unless name.first.length > 0
|
123
122
|
@first_name = name.first
|
124
123
|
end
|
125
124
|
|
@@ -235,4 +234,4 @@ module ICU
|
|
235
234
|
end
|
236
235
|
end
|
237
236
|
end
|
238
|
-
end
|
237
|
+
end
|
@@ -129,7 +129,7 @@ module ICU
|
|
129
129
|
def opponent=(opponent)
|
130
130
|
@opponent = case opponent
|
131
131
|
when nil then nil
|
132
|
-
when
|
132
|
+
when Integer then opponent
|
133
133
|
when /^\s*$/ then nil
|
134
134
|
else opponent.to_i
|
135
135
|
end
|
@@ -198,4 +198,4 @@ module ICU
|
|
198
198
|
true
|
199
199
|
end
|
200
200
|
end
|
201
|
-
end
|
201
|
+
end
|
@@ -379,6 +379,44 @@ module ICU
|
|
379
379
|
self
|
380
380
|
end
|
381
381
|
|
382
|
+
# Make an educated guess at round dates.
|
383
|
+
# If only one round, it is on the start date
|
384
|
+
# If start and end date match, all rounds are on that day
|
385
|
+
# If there are exactly two rounds, round 1 on the start day, round 2 on the finish day
|
386
|
+
# If there are between n and 2n rounds in n consecutive days, then
|
387
|
+
# start with one round a day, switch to two rounds a day when that's needed
|
388
|
+
# If there are 7 rounds Saturday - Sunday > 1 week: two on the first 3 weekend dates, one on the final Sunday
|
389
|
+
# This covers most Irish tournaments. Returns an empty array if it could not guess
|
390
|
+
def guess_round_dates
|
391
|
+
return [@start] if rounds == 1
|
392
|
+
return [] if @finish.nil?
|
393
|
+
|
394
|
+
round_dates = []
|
395
|
+
start_date = ::Date.parse(@start)
|
396
|
+
finish_date = ::Date.parse(@finish)
|
397
|
+
ndays = (finish_date - start_date).to_i + 1
|
398
|
+
if ndays == 1
|
399
|
+
rounds.times { round_dates << start }
|
400
|
+
elsif rounds == 2
|
401
|
+
round_dates << start
|
402
|
+
round_dates << finish
|
403
|
+
elsif ndays <= rounds and rounds <= ndays * 2
|
404
|
+
double_rounds = rounds - ndays
|
405
|
+
(0...ndays).each do |r|
|
406
|
+
round_dates << start_date + r
|
407
|
+
if r >= (ndays - double_rounds)
|
408
|
+
round_dates << start_date + r
|
409
|
+
end
|
410
|
+
end
|
411
|
+
elsif rounds == 7 and start_date.wday == 6 and finish_date.wday == 0 and ndays > 7
|
412
|
+
2.times { round_dates << start_date }
|
413
|
+
2.times { round_dates << start_date + 1 }
|
414
|
+
2.times { round_dates << finish_date - 1 }
|
415
|
+
round_dates << finish_date
|
416
|
+
end
|
417
|
+
return round_dates
|
418
|
+
end
|
419
|
+
|
382
420
|
# Is a tournament invalid? Either returns false (if it's valid) or an error message.
|
383
421
|
# Has the same _rerank_ option as validate!.
|
384
422
|
def invalid(options={})
|
@@ -336,7 +336,7 @@ module ICU
|
|
336
336
|
if old_player.id
|
337
337
|
old_player.merge(opponent)
|
338
338
|
old_result = @player.find_result(@round)
|
339
|
-
raise "
|
339
|
+
raise "result for player (#{@player.name}) in round #{@round} does not match previous result for opponent (#{old_player.name})" unless old_result
|
340
340
|
raise "mismatched results for player (#{old_player.name}): #{result.inspect} #{old_result.inspect}" unless result.eql?(old_result)
|
341
341
|
else
|
342
342
|
old_result = old_player.find_result(@round)
|
@@ -326,9 +326,13 @@ module ICU
|
|
326
326
|
krause << "\n"
|
327
327
|
end
|
328
328
|
rounds = t.last_round
|
329
|
-
|
329
|
+
round_dates = t.round_dates
|
330
|
+
if round_dates.empty?
|
331
|
+
round_dates = t.guess_round_dates.map { |d| d.to_s }
|
332
|
+
end
|
333
|
+
if round_dates.size == rounds && rounds > 0
|
330
334
|
krause << "132 #{' ' * 85}"
|
331
|
-
|
335
|
+
round_dates.each{ |d| krause << d.sub(/^../, ' ') }
|
332
336
|
krause << "\n"
|
333
337
|
end
|
334
338
|
t.players.each{ |p| krause << p.to_krause(rounds, arg) }
|
@@ -433,11 +437,18 @@ module ICU
|
|
433
437
|
full_byes << round
|
434
438
|
return 0.0
|
435
439
|
end
|
436
|
-
data = "#{data} -" if data.match(
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
440
|
+
data = "#{data} -" if data.match(/^(\d+)? (w|b|-)$/)
|
441
|
+
if data.match(/^(0{1,4}|[1-9]\d{0,3}) (w|b|-) (1|0|=|\+|-)$/)
|
442
|
+
opponent = $1.to_i
|
443
|
+
colour = $2
|
444
|
+
score = $3
|
445
|
+
elsif data.match(/- (1|0|=|\+|-)$/)
|
446
|
+
opponent = 0
|
447
|
+
colour = "-"
|
448
|
+
score = $1
|
449
|
+
else
|
450
|
+
raise "invalid result '#{data}'"
|
451
|
+
end
|
441
452
|
options = Hash.new
|
442
453
|
options[:opponent] = opponent unless opponent == 0
|
443
454
|
options[:colour] = colour unless colour == '-'
|
@@ -459,7 +470,7 @@ module ICU
|
|
459
470
|
return false unless total <= sum + full_byes.size * 1.0 + half_byes.size * 0.5
|
460
471
|
full_byes.each_index do |i|
|
461
472
|
bye = full_byes[i]
|
462
|
-
if bye.class ==
|
473
|
+
if bye.class == Integer
|
463
474
|
# Round number - create a half-point bye in that round.
|
464
475
|
result = Result.new(bye, player, '=')
|
465
476
|
@results << ['none', player, "extra bye for player #{player} in round #{bye}", result]
|
data/lib/icu_tournament/util.rb
CHANGED
@@ -72,7 +72,7 @@ module ICU
|
|
72
72
|
names.each do |name|
|
73
73
|
attr_accessor(name) do |val|
|
74
74
|
tmp = val.to_i
|
75
|
-
raise "invalid integer (#{val}) for #{name}" unless val.is_a?(
|
75
|
+
raise "invalid integer (#{val}) for #{name}" unless val.is_a?(Integer) || (val.is_a?(::String) && val.include?(tmp.to_s))
|
76
76
|
tmp
|
77
77
|
end
|
78
78
|
end
|
@@ -83,7 +83,7 @@ module ICU
|
|
83
83
|
attr_accessor(name) do |val|
|
84
84
|
tmp = case val
|
85
85
|
when nil then nil
|
86
|
-
when
|
86
|
+
when Integer then val
|
87
87
|
when /^\s*$/ then nil
|
88
88
|
else val.to_i
|
89
89
|
end
|
@@ -108,7 +108,7 @@ module ICU
|
|
108
108
|
attr_accessor(name) do |val|
|
109
109
|
tmp = case val
|
110
110
|
when nil then nil
|
111
|
-
when
|
111
|
+
when Integer then val
|
112
112
|
when /^\s*$/ then nil
|
113
113
|
else val.to_i
|
114
114
|
end
|
@@ -166,4 +166,4 @@ module ICU
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
169
|
-
end
|
169
|
+
end
|
data/spec/player_spec.rb
CHANGED
@@ -4,213 +4,211 @@ module ICU
|
|
4
4
|
describe Player do
|
5
5
|
context "a typical player" do
|
6
6
|
it "should have a name, number and some results" do
|
7
|
-
|
7
|
+
expect do
|
8
8
|
player = Player.new('Mark', 'Orr', 1)
|
9
9
|
player.add_result(Result.new(1, 1, 'W', :opponent => 37, :score => 'W', :colour => 'W'))
|
10
10
|
player.add_result(Result.new(2, 1, 'W', :opponent => 13, :score => 'W', :colour => 'B'))
|
11
11
|
player.add_result(Result.new(3, 1, 'W', :opponent => 7, :score => 'D', :colour => 'W'))
|
12
|
-
end.
|
12
|
+
end.not_to raise_error
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context "names" do
|
17
17
|
it "should be specified in constructor" do
|
18
18
|
p = Player.new('Mark', 'Orr', 1)
|
19
|
-
p.first_name.
|
20
|
-
p.last_name.
|
21
|
-
p.original_name.
|
19
|
+
expect(p.first_name).to eq('Mark')
|
20
|
+
expect(p.last_name).to eq('Orr')
|
21
|
+
expect(p.original_name).to eq('Orr, Mark')
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be resettable via accessors" do
|
25
25
|
p = Player.new('Mark', 'Orr', 1)
|
26
26
|
p.first_name= 'Gary'
|
27
27
|
p.last_name= 'Kasparov'
|
28
|
-
p.first_name.
|
29
|
-
p.last_name.
|
30
|
-
p.original_name.
|
28
|
+
expect(p.first_name).to eq('Gary')
|
29
|
+
expect(p.last_name).to eq('Kasparov')
|
30
|
+
expect(p.original_name).to eq('Orr, Mark')
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should not contain invalid characters" do
|
34
|
-
|
35
|
-
lambda { Player.new('Mark', '*!', 1) }.should raise_error(/invalid last name/)
|
34
|
+
expect { Player.new('Mark', '*!', 1) }.to raise_error(/invalid last name/)
|
36
35
|
end
|
37
36
|
|
38
|
-
it "should not have empty last name
|
39
|
-
|
40
|
-
lambda { Player.new('', 'Orr', 1) }.should raise_error(/invalid first name/)
|
37
|
+
it "should not have empty last name" do
|
38
|
+
expect { Player.new('Mark', '', 1) }.to raise_error(/invalid last name/)
|
41
39
|
end
|
42
40
|
|
43
41
|
it "both names can be returned together" do
|
44
42
|
p = Player.new('Mark', 'Orr', 1)
|
45
|
-
p.name.
|
43
|
+
expect(p.name).to eq('Orr, Mark')
|
46
44
|
end
|
47
45
|
|
48
46
|
it "names should be automatically canonicalised" do
|
49
47
|
p = Player.new(' maRk J l ', ' ORR', 1)
|
50
|
-
p.name.
|
48
|
+
expect(p.name).to eq('Orr, Mark J. L.')
|
51
49
|
p.first_name = 'z'
|
52
|
-
p.name.
|
50
|
+
expect(p.name).to eq('Orr, Z.')
|
53
51
|
p.last_name = " o meFiSto "
|
54
|
-
p.name.
|
55
|
-
p.original_name.
|
52
|
+
expect(p.name).to eq("O'Mefisto, Z.")
|
53
|
+
expect(p.original_name).to eq('ORR, maRk J l')
|
56
54
|
end
|
57
55
|
|
58
56
|
it "the original name is resetable" do
|
59
57
|
p = Player.new('Mark', 'Orr', 1)
|
60
|
-
p.name.
|
61
|
-
p.original_name.
|
58
|
+
expect(p.name).to eq('Orr, Mark')
|
59
|
+
expect(p.original_name).to eq('Orr, Mark')
|
62
60
|
p.original_name = 'Cronin, April'
|
63
|
-
p.name.
|
64
|
-
p.original_name.
|
61
|
+
expect(p.name).to eq('Orr, Mark')
|
62
|
+
expect(p.original_name).to eq('Cronin, April')
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
66
|
context "number" do
|
69
67
|
it "should just be an integer" do
|
70
|
-
Player.new('Mark', 'Orr', 3).num.
|
71
|
-
Player.new('Mark', 'Orr', -7).num.
|
72
|
-
Player.new('Mark', 'Orr', ' -4 ').num.
|
73
|
-
Player.new('Mark', 'Orr', '0').num.
|
74
|
-
|
68
|
+
expect(Player.new('Mark', 'Orr', 3).num).to eq(3)
|
69
|
+
expect(Player.new('Mark', 'Orr', -7).num).to eq(-7)
|
70
|
+
expect(Player.new('Mark', 'Orr', ' -4 ').num).to eq(-4)
|
71
|
+
expect(Player.new('Mark', 'Orr', '0').num).to eq(0)
|
72
|
+
expect { Player.new('Mark', 'Orr', ' ') }.to raise_error(/invalid integer/)
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
76
|
context "local ID" do
|
79
77
|
it "defaults to nil" do
|
80
|
-
Player.new('Mark', 'Orr', 3).id.
|
78
|
+
expect(Player.new('Mark', 'Orr', 3).id).to be_nil
|
81
79
|
end
|
82
80
|
|
83
81
|
it "should be a positive integer" do
|
84
|
-
Player.new('Mark', 'Orr', 3, :id => 1350).id.
|
85
|
-
Player.new('Stephen', 'Brady', 4, :id => ' 90 ').id.
|
86
|
-
|
82
|
+
expect(Player.new('Mark', 'Orr', 3, :id => 1350).id).to eq(1350)
|
83
|
+
expect(Player.new('Stephen', 'Brady', 4, :id => ' 90 ').id).to eq(90)
|
84
|
+
expect { Player.new('Mark', 'Orr', 3, :id => ' 0 ') }.to raise_error(/invalid positive integer/)
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
90
88
|
context "FIDE ID" do
|
91
89
|
it "defaults to nil" do
|
92
|
-
Player.new('Stephen', 'Brady', 1).fide_id.
|
90
|
+
expect(Player.new('Stephen', 'Brady', 1).fide_id).to be_nil
|
93
91
|
end
|
94
92
|
|
95
93
|
it "should be a positive integer" do
|
96
|
-
Player.new('Stephen', 'Brady', 1, :fide_id => 2500124).fide_id.
|
97
|
-
Player.new('Gary', 'Kasparov', 2, :fide_id => '4100018').fide_id.
|
98
|
-
|
94
|
+
expect(Player.new('Stephen', 'Brady', 1, :fide_id => 2500124).fide_id).to eq(2500124)
|
95
|
+
expect(Player.new('Gary', 'Kasparov', 2, :fide_id => '4100018').fide_id).to eq(4100018)
|
96
|
+
expect { Player.new('Mark', 'Orr', 3, :fide_id => ' 0 ') }.to raise_error(/invalid positive integer/)
|
99
97
|
end
|
100
98
|
end
|
101
99
|
|
102
100
|
context "federation" do
|
103
101
|
it "defaults to nil" do
|
104
|
-
Player.new('Mark', 'Orr', 3).fed.
|
105
|
-
Player.new('Mark', 'Orr', 3, :fed => ' ').fed.
|
102
|
+
expect(Player.new('Mark', 'Orr', 3).fed).to be_nil
|
103
|
+
expect(Player.new('Mark', 'Orr', 3, :fed => ' ').fed).to be_nil
|
106
104
|
end
|
107
105
|
|
108
106
|
it "should consist of at least three letters" do
|
109
|
-
Player.new('Gary', 'Kasparov', 1, :fed => 'RUS').fed.
|
110
|
-
Player.new('Mark', 'Orr', 3, :fed => ' Ireland ').fed.
|
111
|
-
|
107
|
+
expect(Player.new('Gary', 'Kasparov', 1, :fed => 'RUS').fed).to eq('RUS')
|
108
|
+
expect(Player.new('Mark', 'Orr', 3, :fed => ' Ireland ').fed).to eq('IRL')
|
109
|
+
expect { Player.new('Danny', 'Kopec', 3, :fed => 'US') }.to raise_error(/invalid federation/)
|
112
110
|
end
|
113
111
|
|
114
112
|
it "should correct common code errors" do
|
115
|
-
Player.new('Ricardo', 'Calvo', 1, :fed => 'SPA').fed.
|
116
|
-
Player.new('Mark', 'Orr', 2, :fed => 'Icu').fed.
|
117
|
-
Player.new('Florin', 'Gheorghiu', 3, :fed => 'ROM').fed.
|
113
|
+
expect(Player.new('Ricardo', 'Calvo', 1, :fed => 'SPA').fed).to eq('ESP')
|
114
|
+
expect(Player.new('Mark', 'Orr', 2, :fed => 'Icu').fed).to eq('IRL')
|
115
|
+
expect(Player.new('Florin', 'Gheorghiu', 3, :fed => 'ROM').fed).to eq('ROU')
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
121
119
|
context "title" do
|
122
120
|
it "defaults to nil" do
|
123
|
-
Player.new('Mark', 'Orr', 3).title.
|
124
|
-
Player.new('Mark', 'Orr', 3, :title => ' ').title.
|
121
|
+
expect(Player.new('Mark', 'Orr', 3).title).to be_nil
|
122
|
+
expect(Player.new('Mark', 'Orr', 3, :title => ' ').title).to be_nil
|
125
123
|
end
|
126
124
|
|
127
125
|
it "should be one of national, candidate, FIDE, international or grand master" do
|
128
|
-
Player.new('Gary', 'Kasparov', 1, :title => 'GM').title.
|
129
|
-
Player.new('Mark', 'Orr', 2, :title => ' im ').title.
|
130
|
-
Player.new('Mark', 'Quinn', 2, :title => 'm').title.
|
131
|
-
Player.new('Pia', 'Cramling', 3, :title => ' wg ').title.
|
132
|
-
Player.new('Philip', 'Short', 4, :title => 'F ').title.
|
133
|
-
Player.new('Gearoidin', 'Ui Laighleis', 5, :title => 'wc').title.
|
134
|
-
Player.new('Gearoidin', 'Ui Laighleis', 7, :title => 'wm').title.
|
135
|
-
Player.new('Eamon', 'Keogh', 6, :title => 'nm').title.
|
136
|
-
|
126
|
+
expect(Player.new('Gary', 'Kasparov', 1, :title => 'GM').title).to eq('GM')
|
127
|
+
expect(Player.new('Mark', 'Orr', 2, :title => ' im ').title).to eq('IM')
|
128
|
+
expect(Player.new('Mark', 'Quinn', 2, :title => 'm').title).to eq('IM')
|
129
|
+
expect(Player.new('Pia', 'Cramling', 3, :title => ' wg ').title).to eq('WGM')
|
130
|
+
expect(Player.new('Philip', 'Short', 4, :title => 'F ').title).to eq('FM')
|
131
|
+
expect(Player.new('Gearoidin', 'Ui Laighleis', 5, :title => 'wc').title).to eq('WCM')
|
132
|
+
expect(Player.new('Gearoidin', 'Ui Laighleis', 7, :title => 'wm').title).to eq('WIM')
|
133
|
+
expect(Player.new('Eamon', 'Keogh', 6, :title => 'nm').title).to eq('NM')
|
134
|
+
expect { Player.new('Mark', 'Orr', 3, :title => 'Dr') }.to raise_error(/invalid chess title/)
|
137
135
|
end
|
138
136
|
end
|
139
137
|
|
140
138
|
context "rating" do
|
141
139
|
it "defaults to nil" do
|
142
|
-
Player.new('Mark', 'Orr', 3).rating.
|
143
|
-
Player.new('Mark', 'Orr', 3, :rating => ' ').rating.
|
140
|
+
expect(Player.new('Mark', 'Orr', 3).rating).to be_nil
|
141
|
+
expect(Player.new('Mark', 'Orr', 3, :rating => ' ').rating).to be_nil
|
144
142
|
end
|
145
143
|
|
146
144
|
it "should be a positive integer" do
|
147
|
-
Player.new('Gary', 'Kasparov', 1, :rating => 2800).rating.
|
148
|
-
Player.new('Mark', 'Orr', 2, :rating => ' 2100 ').rating.
|
149
|
-
|
150
|
-
|
145
|
+
expect(Player.new('Gary', 'Kasparov', 1, :rating => 2800).rating).to eq(2800)
|
146
|
+
expect(Player.new('Mark', 'Orr', 2, :rating => ' 2100 ').rating).to eq(2100)
|
147
|
+
expect { Player.new('Mark', 'Orr', 3, :rating => -2100) }.to raise_error(/invalid positive integer/)
|
148
|
+
expect { Player.new('Mark', 'Orr', 3, :rating => 'IM') }.to raise_error(/invalid positive integer/)
|
151
149
|
end
|
152
150
|
end
|
153
151
|
|
154
152
|
context "FIDE rating" do
|
155
153
|
it "defaults to nil" do
|
156
|
-
Player.new('Mark', 'Orr', 3).fide_rating.
|
157
|
-
Player.new('Mark', 'Orr', 3, :fide_rating => ' ').fide_rating.
|
154
|
+
expect(Player.new('Mark', 'Orr', 3).fide_rating).to be_nil
|
155
|
+
expect(Player.new('Mark', 'Orr', 3, :fide_rating => ' ').fide_rating).to be_nil
|
158
156
|
end
|
159
157
|
|
160
158
|
it "should be a positive integer" do
|
161
|
-
Player.new('Gary', 'Kasparov', 1, :fide_rating => 2800).fide_rating.
|
162
|
-
Player.new('Mark', 'Orr', 2, :fide_rating => ' 2200 ').fide_rating.
|
163
|
-
|
164
|
-
|
159
|
+
expect(Player.new('Gary', 'Kasparov', 1, :fide_rating => 2800).fide_rating).to eq(2800)
|
160
|
+
expect(Player.new('Mark', 'Orr', 2, :fide_rating => ' 2200 ').fide_rating).to eq(2200)
|
161
|
+
expect { Player.new('Mark', 'Orr', 3, :fide_rating => -2100) }.to raise_error(/invalid positive integer/)
|
162
|
+
expect { Player.new('Mark', 'Orr', 3, :fide_rating => 'IM') }.to raise_error(/invalid positive integer/)
|
165
163
|
end
|
166
164
|
end
|
167
165
|
|
168
166
|
context "rank" do
|
169
167
|
it "defaults to nil" do
|
170
|
-
Player.new('Mark', 'Orr', 3).rank.
|
168
|
+
expect(Player.new('Mark', 'Orr', 3).rank).to be_nil
|
171
169
|
end
|
172
170
|
|
173
171
|
it "should be a positive integer" do
|
174
|
-
Player.new('Mark', 'Orr', 3, :rank => 1).rank.
|
175
|
-
Player.new('Gary', 'Kasparov', 4, :rank => ' 29 ').rank.
|
176
|
-
|
177
|
-
|
172
|
+
expect(Player.new('Mark', 'Orr', 3, :rank => 1).rank).to eq(1)
|
173
|
+
expect(Player.new('Gary', 'Kasparov', 4, :rank => ' 29 ').rank).to eq(29)
|
174
|
+
expect { Player.new('Mark', 'Orr', 3, :rank => 0) }.to raise_error(/invalid positive integer/)
|
175
|
+
expect { Player.new('Mark', 'Orr', 3, :rank => ' -1 ') }.to raise_error(/invalid positive integer/)
|
178
176
|
end
|
179
177
|
end
|
180
178
|
|
181
179
|
context "date of birth" do
|
182
180
|
it "defaults to nil" do
|
183
|
-
Player.new('Mark', 'Orr', 3).dob.
|
184
|
-
Player.new('Mark', 'Orr', 3, :dob => ' ').dob.
|
181
|
+
expect(Player.new('Mark', 'Orr', 3).dob).to be_nil
|
182
|
+
expect(Player.new('Mark', 'Orr', 3, :dob => ' ').dob).to be_nil
|
185
183
|
end
|
186
184
|
|
187
185
|
it "should be a yyyy-mm-dd date" do
|
188
|
-
Player.new('Mark', 'Orr', 3, :dob => '1955-11-09').dob.
|
189
|
-
|
186
|
+
expect(Player.new('Mark', 'Orr', 3, :dob => '1955-11-09').dob).to eq('1955-11-09')
|
187
|
+
expect { Player.new('Mark', 'Orr', 3, :dob => 'X') }.to raise_error(/invalid.*dob/)
|
190
188
|
end
|
191
189
|
end
|
192
190
|
|
193
191
|
context "gender" do
|
194
192
|
it "defaults to nil" do
|
195
|
-
Player.new('Mark', 'Orr', 3).gender.
|
196
|
-
Player.new('Mark', 'Orr', 3, :gender => ' ').gender.
|
193
|
+
expect(Player.new('Mark', 'Orr', 3).gender).to be_nil
|
194
|
+
expect(Player.new('Mark', 'Orr', 3, :gender => ' ').gender).to be_nil
|
197
195
|
end
|
198
196
|
|
199
197
|
it "should be either M or F" do
|
200
|
-
Player.new('Mark', 'Orr', 3, :gender => 'male').gender.
|
201
|
-
Player.new('April', 'Cronin', 3, :gender => 'woman').gender.
|
198
|
+
expect(Player.new('Mark', 'Orr', 3, :gender => 'male').gender).to eq('M')
|
199
|
+
expect(Player.new('April', 'Cronin', 3, :gender => 'woman').gender).to eq('F')
|
202
200
|
end
|
203
201
|
|
204
202
|
it "should raise an exception if the gender is not specified properly" do
|
205
|
-
|
203
|
+
expect { Player.new('Mark', 'Orr', 3, :gender => 'X') }.to raise_error(/invalid gender/)
|
206
204
|
end
|
207
205
|
end
|
208
206
|
|
209
207
|
context "results and points" do
|
210
208
|
it "should initialise to an empty array" do
|
211
209
|
results = Player.new('Mark', 'Orr', 3).results
|
212
|
-
results.
|
213
|
-
results.size.
|
210
|
+
expect(results).to be_instance_of Array
|
211
|
+
expect(results.size).to eq(0)
|
214
212
|
end
|
215
213
|
|
216
214
|
it "can be added to" do
|
@@ -219,21 +217,21 @@ module ICU
|
|
219
217
|
player.add_result(Result.new(2, 3, 'D', :opponent => 2))
|
220
218
|
player.add_result(Result.new(3, 3, 'L', :opponent => 4))
|
221
219
|
results = player.results
|
222
|
-
results.
|
223
|
-
results.size.
|
224
|
-
player.points.
|
220
|
+
expect(results).to be_instance_of Array
|
221
|
+
expect(results.size).to eq(3)
|
222
|
+
expect(player.points).to eq(1.5)
|
225
223
|
end
|
226
224
|
|
227
225
|
it "should not allow mismatched player numbers" do
|
228
226
|
player = Player.new('Mark', 'Orr', 3)
|
229
|
-
|
227
|
+
expect { player.add_result(Result.new(1, 4, 'W', :opponent => 1)) }.to raise_error(/player number .* matched/)
|
230
228
|
end
|
231
229
|
|
232
230
|
it "should enforce unique round numbers" do
|
233
231
|
player = Player.new('Mark', 'Orr', 3)
|
234
232
|
player.add_result(Result.new(1, 3, 'W', :opponent => 1))
|
235
233
|
player.add_result(Result.new(2, 3, 'D', :opponent => 2))
|
236
|
-
|
234
|
+
expect { player.add_result(Result.new(2, 3, 'L', :opponent => 4)) }.to raise_error(/does not match/)
|
237
235
|
end
|
238
236
|
end
|
239
237
|
|
@@ -246,10 +244,10 @@ module ICU
|
|
246
244
|
end
|
247
245
|
|
248
246
|
it "should find results by round number" do
|
249
|
-
@p.find_result(1).opponent.
|
250
|
-
@p.find_result(2).opponent.
|
251
|
-
@p.find_result(3).opponent.
|
252
|
-
@p.find_result(4).
|
247
|
+
expect(@p.find_result(1).opponent).to eq(37)
|
248
|
+
expect(@p.find_result(2).opponent).to eq(13)
|
249
|
+
expect(@p.find_result(3).opponent).to eq(7)
|
250
|
+
expect(@p.find_result(4)).to be_nil
|
253
251
|
end
|
254
252
|
end
|
255
253
|
|
@@ -263,9 +261,9 @@ module ICU
|
|
263
261
|
|
264
262
|
it "should find and remove a result by round number" do
|
265
263
|
result = @p.remove_result(1)
|
266
|
-
result.inspect.
|
267
|
-
@p.results.size.
|
268
|
-
@p.results.map(&:round).join("|").
|
264
|
+
expect(result.inspect).to eq("R1P1O37WWR")
|
265
|
+
expect(@p.results.size).to eq(2)
|
266
|
+
expect(@p.results.map(&:round).join("|")).to eq("2|3")
|
269
267
|
end
|
270
268
|
end
|
271
269
|
|
@@ -278,12 +276,12 @@ module ICU
|
|
278
276
|
|
279
277
|
it "takes on the ID, rating, title and fed of the other player but not the player number" do
|
280
278
|
@p1.merge(@p2)
|
281
|
-
@p1.num.
|
282
|
-
@p1.id.
|
283
|
-
@p1.rating.
|
284
|
-
@p1.title.
|
285
|
-
@p1.fed.
|
286
|
-
@p1.fide_id.
|
279
|
+
expect(@p1.num).to eq(1)
|
280
|
+
expect(@p1.id).to eq(1350)
|
281
|
+
expect(@p1.rating).to eq(2100)
|
282
|
+
expect(@p1.title).to eq('IM')
|
283
|
+
expect(@p1.fed).to eq('IRL')
|
284
|
+
expect(@p1.fide_id).to eq(2500035)
|
287
285
|
end
|
288
286
|
|
289
287
|
it "should have a kind of symmetry" do
|
@@ -293,7 +291,7 @@ module ICU
|
|
293
291
|
end
|
294
292
|
|
295
293
|
it "cannot be done with unequal objects" do
|
296
|
-
|
294
|
+
expect { @p1.merge(@p3) }.to raise_error(/cannot merge.*not equal/)
|
297
295
|
end
|
298
296
|
end
|
299
297
|
|
@@ -306,13 +304,13 @@ module ICU
|
|
306
304
|
|
307
305
|
it "should renumber successfully if the map has the relevant player numbers" do
|
308
306
|
map = { 10 => 1, 20 => 2, 30 => 3 }
|
309
|
-
@p.renumber(map).num.
|
310
|
-
@p.results.map{ |r| r.opponent }.sort.join('').
|
307
|
+
expect(@p.renumber(map).num).to eq(1)
|
308
|
+
expect(@p.results.map{ |r| r.opponent }.sort.join('')).to eq('23')
|
311
309
|
end
|
312
310
|
|
313
311
|
it "should raise exception if a player number is not in the map" do
|
314
|
-
|
315
|
-
|
312
|
+
expect { @p.renumber({ 100 => 1, 20 => 2, 30 => 3 }) }.to raise_error(/player.*10.*not found/)
|
313
|
+
expect { @p.renumber({ 10 => 1, 200 => 2, 30 => 3 }) }.to raise_error(/opponent.*20.*not found/)
|
316
314
|
end
|
317
315
|
end
|
318
316
|
|
@@ -326,21 +324,21 @@ module ICU
|
|
326
324
|
end
|
327
325
|
|
328
326
|
it "any player is equal to itself" do
|
329
|
-
(@mark1 == @mark1).
|
327
|
+
expect(@mark1 == @mark1).to be_truthy
|
330
328
|
end
|
331
329
|
|
332
330
|
it "two players are equal if their names are the same and their federations do not conflict" do
|
333
|
-
(@mark1 == @mark2).
|
331
|
+
expect(@mark1 == @mark2).to be_truthy
|
334
332
|
end
|
335
333
|
|
336
334
|
it "two players cannot be equal if they have different names" do
|
337
|
-
(@mark1 == @mark4).
|
338
|
-
(@mark1 == @john1).
|
335
|
+
expect(@mark1 == @mark4).to be_falsey
|
336
|
+
expect(@mark1 == @john1).to be_falsey
|
339
337
|
end
|
340
338
|
|
341
339
|
it "two players cannot be equal if they have different federations" do
|
342
|
-
(@mark2 == @mark3).
|
343
|
-
(@mark1 == @mark3).
|
340
|
+
expect(@mark2 == @mark3).to be_falsey
|
341
|
+
expect(@mark1 == @mark3).to be_truthy
|
344
342
|
end
|
345
343
|
end
|
346
344
|
|
@@ -354,21 +352,21 @@ module ICU
|
|
354
352
|
end
|
355
353
|
|
356
354
|
it "any player is equal to itself" do
|
357
|
-
@mark1.eql?(@mark1).
|
358
|
-
@mark1.eql?(@mark1).
|
355
|
+
expect(@mark1.eql?(@mark1)).to be_truthy
|
356
|
+
expect(@mark1.eql?(@mark1)).to be_truthy
|
359
357
|
end
|
360
358
|
|
361
359
|
it "two players are equal as long as their ID, rating and title do not conflict" do
|
362
|
-
@mark1.eql?(@mark2).
|
363
|
-
@mark3.eql?(@mark4).
|
364
|
-
@mark4.eql?(@mark5).
|
360
|
+
expect(@mark1.eql?(@mark2)).to be_truthy
|
361
|
+
expect(@mark3.eql?(@mark4)).to be_truthy
|
362
|
+
expect(@mark4.eql?(@mark5)).to be_truthy
|
365
363
|
end
|
366
364
|
|
367
365
|
it "two players are not equal if their ID, rating or title conflict" do
|
368
|
-
@mark2.eql?(@mark3).
|
369
|
-
@mark2.eql?(@mark4).
|
370
|
-
@mark2.eql?(@mark5).
|
366
|
+
expect(@mark2.eql?(@mark3)).to be_falsey
|
367
|
+
expect(@mark2.eql?(@mark4)).to be_falsey
|
368
|
+
expect(@mark2.eql?(@mark5)).to be_falsey
|
371
369
|
end
|
372
370
|
end
|
373
371
|
end
|
374
|
-
end
|
372
|
+
end
|