icu_tournament 1.9.3 → 1.10.0
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.
- 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
data/spec/tournament_sp_spec.rb
CHANGED
@@ -33,32 +33,32 @@ module ICU
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should parse and have the right basic details" do
|
36
|
-
@p.error.
|
37
|
-
@t.sp_signature.
|
36
|
+
expect(@p.error).to be_nil
|
37
|
+
expect(@t.sp_signature).to eq("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).sp_signature.
|
42
|
-
@t.player(4).sp_signature.
|
43
|
-
@t.player(45).sp_signature.
|
44
|
-
@t.player(56).sp_signature.
|
41
|
+
expect(@t.player(2).sp_signature).to eq("Mullooly, Neil M.|6438||1083||6.0|1|123456|WWWWWW|WBWBWB|TTTTTT") # winner
|
42
|
+
expect(@t.player(4).sp_signature).to eq("Gallagher, Mark|12138||1036||4.0|9|123456|WLWWWL|WBWBWB|FTTTTT") # had one bye
|
43
|
+
expect(@t.player(45).sp_signature).to eq("Catre, Loredan|||507||3.5|18|123456|WDLWLW|BWBWBW|FTTTFT") # had two byes
|
44
|
+
expect(@t.player(56).sp_signature).to eq("McDonnell, Cathal|||498||0.0|54|1|L|-|F") # last
|
45
45
|
end
|
46
46
|
|
47
47
|
it "original names should be preserved" do
|
48
|
-
@t.player(2).original_name.
|
49
|
-
@t.player(4).original_name.
|
48
|
+
expect(@t.player(2).original_name).to eq("MULLOOLY, neil m")
|
49
|
+
expect(@t.player(4).original_name).to eq("Gallagher, Mark")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should have consistent ranks" do
|
53
|
-
@t.players.map{ |p| p.rank }.sort.join('').
|
53
|
+
expect(@t.players.map{ |p| p.rank }.sort.join('')).to eq((1..@t.players.size).to_a.join(''))
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should have the correct tie breaks" do
|
57
|
-
@t.tie_breaks.join('|').
|
57
|
+
expect(@t.tie_breaks.join('|')).to eq("buchholz|harkness|progressive")
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should serialize to the text export format" do
|
61
|
-
@t.serialize('SPExport', :only => [:id, :points]).
|
61
|
+
expect(@t.serialize('SPExport', :only => [:id, :points])).to eq(@s)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -70,27 +70,27 @@ module ICU
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should parse and have the right basic details" do
|
73
|
-
@p.error.
|
74
|
-
@t.sp_signature.
|
73
|
+
expect(@p.error).to be_nil
|
74
|
+
expect(@t.sp_signature).to eq("U - 19 All Ireland||3|2010-04-11|4")
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should have correct details for selected players" do
|
78
|
-
@t.player(1).sp_signature.
|
79
|
-
@t.player(2).sp_signature.
|
80
|
-
@t.player(3).sp_signature.
|
81
|
-
@t.player(4).sp_signature.
|
78
|
+
expect(@t.player(1).sp_signature).to eq("Griffiths, Ryan-Rhys|6897||2225||3.0|1|123|WWW|WWB|TTT")
|
79
|
+
expect(@t.player(2).sp_signature).to eq("Flynn, Jamie|5226||1633||2.0|2|123|WLW|WBW|TTT")
|
80
|
+
expect(@t.player(3).sp_signature).to eq("Hulleman, Leon|6409||1466||1.0|3|123|LWL|BBW|TTT")
|
81
|
+
expect(@t.player(4).sp_signature).to eq("Dunne, Thomas|10914||||0.0|4|123|LLL|BWB|TTT")
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should have consistent ranks" do
|
85
|
-
@t.players.map{ |p| p.rank }.sort.join('').
|
85
|
+
expect(@t.players.map{ |p| p.rank }.sort.join('')).to eq((1..@t.players.size).to_a.join(''))
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should have the no tie breaks" do
|
89
|
-
@t.tie_breaks.join('|').
|
89
|
+
expect(@t.tie_breaks.join('|')).to eq("")
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should serialize to the text export format" do
|
93
|
-
@t.rerank.renumber.serialize('SPExport', :only => [:id, :points]).
|
93
|
+
expect(@t.rerank.renumber.serialize('SPExport', :only => [:id, :points])).to eq(@s)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -101,25 +101,25 @@ module ICU
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should parse and have the right basic details" do
|
104
|
-
@p.error.
|
105
|
-
@t.sp_signature.
|
104
|
+
expect(@p.error).to be_nil
|
105
|
+
expect(@t.sp_signature).to eq("Limerick Club Championship 2009||7|2009-09-15|19")
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should have correct details for selected players" do
|
109
|
-
@t.player(15).sp_signature.
|
110
|
-
@t.player(6).sp_signature.
|
111
|
-
@t.player(19).sp_signature.
|
112
|
-
@t.player(17).sp_signature.
|
113
|
-
@t.player(18).sp_signature.
|
114
|
-
@t.player(16).sp_signature.
|
109
|
+
expect(@t.player(15).sp_signature).to eq("Talazec, Laurent|10692||1570||5.5|1|1234567|WWWDDDW|WWBWBWB|FTTTTTT") # winner
|
110
|
+
expect(@t.player(6).sp_signature).to eq("Foenander, Phillip|7168||1434||4.0|7|1234567|WLWLLWW|BWBWBWB|TTFFTTT") # had some byes
|
111
|
+
expect(@t.player(19).sp_signature).to eq("Wall, Robert|||||3.0|14|34567|WWLWL|WWBBW|FTTTT") # didn't play 1st 2 rounds
|
112
|
+
expect(@t.player(17).sp_signature).to eq("Freeman, Conor|||||2.0|16|1234567|DDLWLLL|--BWBWB|FFTTTTT") # had byes and bonus (in BONUS)
|
113
|
+
expect(@t.player(18).sp_signature).to eq("Freeman, Ruiri|||||2.0|17|1234567|DDLLLLW|--WBBWB|FFTTTTF") # had byes and bonus (in BONUS)
|
114
|
+
expect(@t.player(16).sp_signature).to eq("O'Connor, David|||||1.0|19|123|WLL|WBW|FTF") # last
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should have consistent ranks" do
|
118
|
-
@t.players.map{ |p| p.rank }.sort.join('').
|
118
|
+
expect(@t.players.map{ |p| p.rank }.sort.join('')).to eq((1..@t.players.size).to_a.join(''))
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should have the correct tie breaks" do
|
122
|
-
@t.tie_breaks.join('|').
|
122
|
+
expect(@t.tie_breaks.join('|')).to eq("harkness|buchholz|progressive")
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -130,23 +130,23 @@ module ICU
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should parse and have the right basic details" do
|
133
|
-
@p.error.
|
134
|
-
@t.sp_signature.
|
133
|
+
expect(@p.error).to be_nil
|
134
|
+
expect(@t.sp_signature).to eq("U16 Inter Provincials 2010|David B Murray|3|2010-02-02|18")
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should have correct details for selected players" do
|
138
|
-
@t.player(15).sp_signature.
|
139
|
-
@t.player(18).sp_signature.
|
140
|
-
@t.player(8).sp_signature.
|
141
|
-
@t.player(10).sp_signature.
|
138
|
+
expect(@t.player(15).sp_signature).to eq("Gupta, Radhika|||1247||3.0|1|123|WWW|BBW|TTT") # won all his games
|
139
|
+
expect(@t.player(18).sp_signature).to eq("Hurley, Thomas|6292||820||1.0|14|1|W|B|F") # scored just 1 from a bye in R1
|
140
|
+
expect(@t.player(8).sp_signature).to eq("Berney, Mark|10328||1948||2.0|3|23|WW|BW|TT") # didn't play in round 1
|
141
|
+
expect(@t.player(10).sp_signature).to eq("O'Donnell, Conor E.|10792||1073||2.0|10|123|LWW|WBW|TFT") # got just 1 point for a bye
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should have consistent ranks" do
|
145
|
-
@t.players.map{ |p| p.rank }.sort.join('').
|
145
|
+
expect(@t.players.map{ |p| p.rank }.sort.join('')).to eq((1..@t.players.size).to_a.join(''))
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should have the correct tie breaks" do
|
149
|
-
@t.tie_breaks.join('|').
|
149
|
+
expect(@t.tie_breaks.join('|')).to eq("neustadtl")
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -157,20 +157,20 @@ module ICU
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should parse and have the right basic details" do
|
160
|
-
@p.error.
|
161
|
-
@t.sp_signature.
|
160
|
+
expect(@p.error).to be_nil
|
161
|
+
expect(@t.sp_signature).to eq("Mulcahy Cup 2010|Stephen Short|6|2010-01-15|50")
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should have correct details for selection of players who got bonuses (in MEMO)" do
|
165
|
-
@t.player(23).sp_signature.
|
166
|
-
@t.player(26).sp_signature.
|
167
|
-
@t.player(15).sp_signature.
|
168
|
-
@t.player(46).sp_signature.
|
169
|
-
@t.player(38).sp_signature.
|
165
|
+
expect(@t.player(23).sp_signature).to eq("Long, Killian|10293||1506||2.5|33|123456|WDLLWL|WWBWBB|TFTTTT")
|
166
|
+
expect(@t.player(26).sp_signature).to eq("Bradley, Michael|6756||1413||3.0|26|123456|DDLWWL|BWWBWW|TFTTTT")
|
167
|
+
expect(@t.player(15).sp_signature).to eq("Twomey, Pat|1637||1656||4.5|7|123456|WDLWWW|WWWBWB|FFTTTT")
|
168
|
+
expect(@t.player(46).sp_signature).to eq("O'Riordan, Pat|10696||900||2.0|42|123456|LDDLDD|BWBWWB|TTTTFT")
|
169
|
+
expect(@t.player(38).sp_signature).to eq("Gill, Craig I.|10637||1081||2.0|43|123456|LLWDDL|BWBWWB|TTTTFT")
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should have consistent ranks" do
|
173
|
-
@t.players.map{ |p| p.rank }.sort.join('').
|
173
|
+
expect(@t.players.map{ |p| p.rank }.sort.join('')).to eq((1..@t.players.size).to_a.join(''))
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -181,15 +181,15 @@ module ICU
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should parse and have the right basic details" do
|
184
|
-
@p.error.
|
185
|
-
@t.sp_signature.
|
184
|
+
expect(@p.error).to be_nil
|
185
|
+
expect(@t.sp_signature).to eq("National Club Championship 2010|Gerry Graham|4|2010-05-08|77")
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should have correct details for selection of players, including ICU IDs" do
|
189
|
-
@t.player(2).sp_signature.
|
190
|
-
@t.player(5).sp_signature.
|
191
|
-
@t.player(8).sp_signature.
|
192
|
-
@t.player(67).sp_signature.
|
189
|
+
expect(@t.player(2).sp_signature).to eq("Szabo, Gergely|12379|1205064||2530|4.0|4|1234|WWWW|WBWB|TTTT")
|
190
|
+
expect(@t.player(5).sp_signature).to eq("Daly, Colm|295|2500434|2314||3.5|7|1234|WWWD|WBWB|TTTT")
|
191
|
+
expect(@t.player(8).sp_signature).to eq("Vega, Marcos Llaneza||2253585|2475||3.0|16|1234|DDWW|BWBW|TTTT")
|
192
|
+
expect(@t.player(67).sp_signature).to eq("Lee, Shane|780||1633||1.0|52|134|DLD|WWW|TTT")
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -200,22 +200,22 @@ module ICU
|
|
200
200
|
|
201
201
|
it "should not parse because of the invalid federation" do
|
202
202
|
t = @p.parse_file(SAMPLES + 'drog_a.zip', :start => "2010-06-04")
|
203
|
-
t.
|
204
|
-
@p.error.
|
203
|
+
expect(t).to be_nil
|
204
|
+
expect(@p.error).to match(/invalid federation/i)
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should parse if instructed to skip bad feds" do
|
208
208
|
t = @p.parse_file(SAMPLES + 'drog_a.zip', :start => "2010-06-04", :fed => :skip)
|
209
|
-
@p.error.
|
210
|
-
t.player(5).fed.
|
211
|
-
t.player(6).fed.
|
209
|
+
expect(@p.error).to be_nil
|
210
|
+
expect(t.player(5).fed).to be_nil
|
211
|
+
expect(t.player(6).fed).to eq("ESP")
|
212
212
|
end
|
213
213
|
|
214
214
|
it "should parse if instructed to skip all feds" do
|
215
215
|
t = @p.parse_file(SAMPLES + 'drog_a.zip', :start => "2010-06-04", :fed => 'ignore')
|
216
|
-
@p.error.
|
217
|
-
t.player(5).fed.
|
218
|
-
t.player(6).fed.
|
216
|
+
expect(@p.error).to be_nil
|
217
|
+
expect(t.player(5).fed).to be_nil
|
218
|
+
expect(t.player(6).fed).to be_nil
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -226,10 +226,10 @@ module ICU
|
|
226
226
|
|
227
227
|
it "should parse" do
|
228
228
|
@t = @p.parse_file(SAMPLES + 'limerick_cc_2011.zip', :start => "2010-10-15")
|
229
|
-
@p.error.
|
230
|
-
@t.name.
|
231
|
-
@t.rounds.
|
232
|
-
@t.arbiter.
|
229
|
+
expect(@p.error).to be_nil
|
230
|
+
expect(@t.name).to eq("Unspecified")
|
231
|
+
expect(@t.rounds).to eq(7)
|
232
|
+
expect(@t.arbiter).to be_nil
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -240,10 +240,10 @@ module ICU
|
|
240
240
|
|
241
241
|
it "should parse" do
|
242
242
|
@t = @p.parse_file(SAMPLES + 'phibs_cc_inter_2012.zip', :start => "2012-04-16")
|
243
|
-
@p.error.
|
244
|
-
@t.name.
|
245
|
-
@t.rounds.
|
246
|
-
@t.arbiter.
|
243
|
+
expect(@p.error).to be_nil
|
244
|
+
expect(@t.name).to eq("Phibsboro Club Championship 2012 Inter")
|
245
|
+
expect(@t.rounds).to eq(5)
|
246
|
+
expect(@t.arbiter).to eq("Michael Germaine")
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
@@ -254,8 +254,8 @@ module ICU
|
|
254
254
|
end
|
255
255
|
|
256
256
|
it "should not parse and should have a relevant error" do
|
257
|
-
@t.
|
258
|
-
@p.error.
|
257
|
+
expect(@t).to be_nil
|
258
|
+
expect(@p.error).to match(/invalid ZIP file/i)
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
@@ -266,8 +266,8 @@ module ICU
|
|
266
266
|
end
|
267
267
|
|
268
268
|
it "should not parse and have a should have relevant error" do
|
269
|
-
@t.
|
270
|
-
@p.error.
|
269
|
+
expect(@t).to be_nil
|
270
|
+
expect(@p.error).to match(/invalid ZIP file/i)
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -278,8 +278,8 @@ module ICU
|
|
278
278
|
end
|
279
279
|
|
280
280
|
it "should not parse and should have a relevant error" do
|
281
|
-
@t.
|
282
|
-
@p.error.
|
281
|
+
expect(@t).to be_nil
|
282
|
+
expect(@p.error).to match(/3 files/i)
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
@@ -290,8 +290,8 @@ module ICU
|
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should not parse and should have a relevant error" do
|
293
|
-
@t.
|
294
|
-
@p.error.
|
293
|
+
expect(@t).to be_nil
|
294
|
+
expect(@p.error).to match(/different stem/i)
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
@@ -302,15 +302,15 @@ module ICU
|
|
302
302
|
end
|
303
303
|
|
304
304
|
it "should parse and have the right basic details" do
|
305
|
-
@p.error.
|
306
|
-
@t.sp_signature.
|
305
|
+
expect(@p.error).to be_nil
|
306
|
+
expect(@t.sp_signature).to eq("National Club Championship 2010|Gerry Graham|4|2010-05-08|77")
|
307
307
|
end
|
308
308
|
|
309
309
|
it "should have correct details for selection of players, including ICU IDs" do
|
310
|
-
@t.player(2).sp_signature.
|
311
|
-
@t.player(5).sp_signature.
|
312
|
-
@t.player(8).sp_signature.
|
313
|
-
@t.player(67).sp_signature.
|
310
|
+
expect(@t.player(2).sp_signature).to eq("Szabo, Gergely|12379|1205064||2530|4.0|4|1234|WWWW|WBWB|TTTT")
|
311
|
+
expect(@t.player(5).sp_signature).to eq("Daly, Colm|295|2500434|2314||3.5|7|1234|WWWD|WBWB|TTTT")
|
312
|
+
expect(@t.player(8).sp_signature).to eq("Vega, Marcos Llaneza||2253585|2475||3.0|16|1234|DDWW|BWBW|TTTT")
|
313
|
+
expect(@t.player(67).sp_signature).to eq("Lee, Shane|780||1633||1.0|52|134|DLD|WWW|TTT")
|
314
314
|
end
|
315
315
|
end
|
316
316
|
|
@@ -320,11 +320,11 @@ module ICU
|
|
320
320
|
end
|
321
321
|
|
322
322
|
it "should not parse unless ZIP format is signalled with an option" do
|
323
|
-
|
323
|
+
expect { @p.parse_file!(SAMPLES + 'nccz.piz', :start => "2010-05-08") }.to raise_error(/cannot find/i)
|
324
324
|
end
|
325
325
|
|
326
326
|
it "should parse if ZIP format is signalled with an option" do
|
327
|
-
|
327
|
+
expect { @p.parse_file!(SAMPLES + 'nccz.piz', :zip => true, :start => "2010-05-08") }.not_to raise_error
|
328
328
|
end
|
329
329
|
end
|
330
330
|
|
@@ -334,10 +334,10 @@ module ICU
|
|
334
334
|
end
|
335
335
|
|
336
336
|
it "should parse and the name should be in UTF-8" do
|
337
|
-
|
338
|
-
@t.player(1).sp_signature.
|
339
|
-
@t.player(4).sp_signature.
|
340
|
-
@t.player(10).sp_signature.
|
337
|
+
expect { @t = @p.parse_file!(SAMPLES + 'munster_u10_2011.zip', :start => "2011-01-20") }.not_to raise_error
|
338
|
+
expect(@t.player(1).sp_signature).to eq("Kennedy, Stephen|||849||2.0|6|12345|WLWLL|BWBWB|TTTTT")
|
339
|
+
expect(@t.player(4).sp_signature).to eq("Sheehan, Ciarán|||||3.0|5|12345|LWWLW|WBWBW|TTTTF")
|
340
|
+
expect(@t.player(10).sp_signature).to eq("Sheehan, Adam|||||2.0|7|12345|WLLWL|WBWWB|TTTFT")
|
341
341
|
end
|
342
342
|
end
|
343
343
|
|
@@ -348,7 +348,7 @@ module ICU
|
|
348
348
|
end
|
349
349
|
|
350
350
|
it "should default the start date if not supplied" do
|
351
|
-
@t.start.
|
351
|
+
expect(@t.start).to eq("2000-01-01")
|
352
352
|
end
|
353
353
|
end
|
354
354
|
end
|
data/spec/tournament_spec.rb
CHANGED
@@ -4,7 +4,7 @@ module ICU
|
|
4
4
|
describe Tournament do
|
5
5
|
context "a basic tournament" do
|
6
6
|
it "has a name, start date, some players and some results" do
|
7
|
-
|
7
|
+
expect do
|
8
8
|
t = Tournament.new('Bangor Bash', '2009-11-09')
|
9
9
|
t.add_player(Player.new('Bobby', 'Fischer', 1))
|
10
10
|
t.add_player(Player.new('Garry', 'Kasparov', 2))
|
@@ -13,7 +13,7 @@ module ICU
|
|
13
13
|
t.add_result(Result.new(2, 2, 'L', :opponent => 3, :colour => 'W'))
|
14
14
|
t.add_result(Result.new(3, 3, 'W', :opponent => 1, :colour => 'W'))
|
15
15
|
t.validate!
|
16
|
-
end.
|
16
|
+
end.not_to raise_error
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -39,7 +39,7 @@ EOS
|
|
39
39
|
|
40
40
|
it "should serialize to Krause" do
|
41
41
|
parser = ICU::Tournament::Krause.new
|
42
|
-
parser.serialize(@t).
|
42
|
+
expect(parser.serialize(@t)).to eq(@s)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -49,17 +49,17 @@ EOS
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "must be specified in constructor" do
|
52
|
-
@t.name.
|
52
|
+
expect(@t.name).to eq('Edinburgh Masters')
|
53
53
|
end
|
54
54
|
|
55
55
|
it "can be replaced by accessor" do
|
56
56
|
@t.name = 'Bangor Bashers'
|
57
|
-
@t.name.
|
57
|
+
expect(@t.name).to eq('Bangor Bashers')
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should not be blank or without letters" do
|
61
|
-
|
62
|
-
|
61
|
+
expect { Tournament.new(' ', '2009-11-09') }.to raise_error(/invalid.*name/)
|
62
|
+
expect { @t.name = '333' }.to raise_error(/invalid.*name/)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -69,21 +69,21 @@ EOS
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "may be specified in constructor" do
|
72
|
-
@t.city.
|
72
|
+
expect(@t.city).to eq('Edinburgh')
|
73
73
|
end
|
74
74
|
|
75
75
|
it "can be replaced by accessor" do
|
76
76
|
@t.city = 'Glasgow'
|
77
|
-
@t.city.
|
77
|
+
expect(@t.city).to eq('Glasgow')
|
78
78
|
end
|
79
79
|
|
80
80
|
it "can be set to nil" do
|
81
81
|
@t.city = ''
|
82
|
-
@t.city.
|
82
|
+
expect(@t.city).to be_nil
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should not be without letters if set" do
|
86
|
-
|
86
|
+
expect { @t.city = '123' }.to raise_error(/invalid.*city/)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -93,26 +93,26 @@ EOS
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "may be specified in constructor" do
|
96
|
-
@t.fed.
|
96
|
+
expect(@t.fed).to eq('SCO')
|
97
97
|
end
|
98
98
|
|
99
99
|
it "can be replaced by accessor" do
|
100
100
|
@t.fed = 'IRL'
|
101
|
-
@t.fed.
|
101
|
+
expect(@t.fed).to eq('IRL')
|
102
102
|
end
|
103
103
|
|
104
104
|
it "can be set to nil" do
|
105
105
|
@t.fed = ''
|
106
|
-
@t.fed.
|
106
|
+
expect(@t.fed).to be_nil
|
107
107
|
end
|
108
108
|
|
109
109
|
it "three letters will automatically be upcased" do
|
110
110
|
@t.fed = 'rus'
|
111
|
-
@t.fed.
|
111
|
+
expect(@t.fed).to eq('RUS')
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should not be without letters if set" do
|
115
|
-
|
115
|
+
expect { @t.fed = '123' }.to raise_error(/invalid.*federation/)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -122,17 +122,17 @@ EOS
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it "must be specified in constructor" do
|
125
|
-
@t.start.
|
125
|
+
expect(@t.start).to eq('2009-11-09')
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can be replaced by accessor" do
|
129
129
|
@t.start = '16th June 2010'
|
130
|
-
@t.start.
|
130
|
+
expect(@t.start).to eq('2010-06-16')
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should be a valid date" do
|
134
|
-
|
135
|
-
|
134
|
+
expect { Tournament.new('Edinburgh Masters', ' ') }.to raise_error(/invalid.*date/)
|
135
|
+
expect { @t.start = 'X' }.to raise_error(/invalid.*date/)
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -142,35 +142,35 @@ EOS
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it "may be specified in constructor" do
|
145
|
-
@t.finish.
|
145
|
+
expect(@t.finish).to eq('2009-11-12')
|
146
146
|
end
|
147
147
|
|
148
148
|
it "can be replaced by accessor" do
|
149
149
|
@t.finish = '16th December 2009'
|
150
|
-
@t.finish.
|
150
|
+
expect(@t.finish).to eq('2009-12-16')
|
151
151
|
end
|
152
152
|
|
153
153
|
it "can be set to nil" do
|
154
154
|
@t.finish = ''
|
155
|
-
@t.finish.
|
155
|
+
expect(@t.finish).to be_nil
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should be a valid date" do
|
159
|
-
|
160
|
-
|
159
|
+
expect { Tournament.new('Edinburgh Masters', '2009-11-09', :finish => 'next week') }.to raise_error(/invalid.*date/)
|
160
|
+
expect { @t.finish = 'X' }.to raise_error(/invalid.*date/)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
context "rounds" do
|
165
165
|
it "defaults to nil" do
|
166
|
-
Tournament.new('Edinburgh Masters', '2009-11-09').rounds.
|
166
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09').rounds).to be_nil
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should be a positive integer or nil" do
|
170
|
-
Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => 3).rounds.
|
171
|
-
Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => ' 10 ').rounds.
|
172
|
-
Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => nil).rounds.
|
173
|
-
|
170
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => 3).rounds).to eq(3)
|
171
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => ' 10 ').rounds).to eq(10)
|
172
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => nil).rounds).to be_nil
|
173
|
+
expect { Tournament.new('Edinburgh Masters', '2009-11-09', :rounds => ' 0 ') }.to raise_error(/invalid.*rounds/)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -183,13 +183,13 @@ EOS
|
|
183
183
|
end
|
184
184
|
|
185
185
|
it "depends on the players results" do
|
186
|
-
@t.last_round.
|
186
|
+
expect(@t.last_round).to eq(0)
|
187
187
|
@t.add_result(Result.new(1, 1, 'W', :opponent => 2))
|
188
|
-
@t.last_round.
|
188
|
+
expect(@t.last_round).to eq(1)
|
189
189
|
@t.add_result(Result.new(2, 2, 'D', :opponent => 3))
|
190
|
-
@t.last_round.
|
190
|
+
expect(@t.last_round).to eq(2)
|
191
191
|
@t.add_result(Result.new(5, 3, 'L', :opponent => 1))
|
192
|
-
@t.last_round.
|
192
|
+
expect(@t.last_round).to eq(5)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -199,26 +199,73 @@ EOS
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should default to none" do
|
202
|
-
@t.round_dates.size.
|
202
|
+
expect(@t.round_dates.size).to eq(0)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should be added one by one in the correct order" do
|
206
206
|
@t.add_round_date('09/11/2009')
|
207
207
|
@t.add_round_date('10th November 2009')
|
208
208
|
@t.add_round_date('2009-11-11')
|
209
|
-
@t.round_dates.join('|').
|
209
|
+
expect(@t.round_dates.join('|')).to eq('2009-11-09|2009-11-10|2009-11-11')
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "guess round date" do
|
214
|
+
before(:each) do
|
215
|
+
@ennis = Tournament.new('Ennis Shield Round 1', '2019-09-24', :rounds => 1)
|
216
|
+
@u12 = Tournament.new('Leinster U12', '2019-01-05', :finish => '2019-01-05', :rounds => 4)
|
217
|
+
@armstrong = Tournament.new('Armstrong Cup Rounds 1-2', '2019-09-28', :finish => '2019-10-14', :rounds => 2)
|
218
|
+
@irish = Tournament.new('Irish Championship', '2019-08-03', :finish => '2019-08-11', :rounds => 9)
|
219
|
+
@malahide = Tournament.new('Malahide Millenium', '2019-05-04', :finish => '2019-05-06', :rounds => 6)
|
220
|
+
@gonzaga = Tournament.new('Gonzaga Classic', '2019-01-25', :finish => '2019-01-27', :rounds => 5)
|
221
|
+
@sona = Tournament.new('Sona Super Cup U14', '2018-10-20', :finish => '2018-11-25', :rounds => 7)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should get one round date when only one round" do
|
225
|
+
guess = @ennis.guess_round_dates
|
226
|
+
expect(guess.join('|')).to eq('2019-09-24')
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should get all rounds on right day when only one day" do
|
230
|
+
guess = @u12.guess_round_dates
|
231
|
+
expect(guess.join('|')).to eq('2019-01-05|2019-01-05|2019-01-05|2019-01-05')
|
232
|
+
end
|
233
|
+
|
234
|
+
it "two rounds" do
|
235
|
+
guess = @armstrong.guess_round_dates
|
236
|
+
expect(guess.join('|')).to eq('2019-09-28|2019-10-14')
|
237
|
+
end
|
238
|
+
|
239
|
+
it "9 rounds in 9 days" do
|
240
|
+
guess = @irish.guess_round_dates
|
241
|
+
expect(guess.join('|')).to eq('2019-08-03|2019-08-04|2019-08-05|2019-08-06|2019-08-07|2019-08-08|2019-08-09|2019-08-10|2019-08-11')
|
242
|
+
end
|
243
|
+
|
244
|
+
it "6 rounds in 3 days" do
|
245
|
+
guess = @malahide.guess_round_dates
|
246
|
+
expect(guess.join('|')).to eq('2019-05-04|2019-05-04|2019-05-05|2019-05-05|2019-05-06|2019-05-06')
|
247
|
+
end
|
248
|
+
|
249
|
+
it "5 rounds in 3 days" do
|
250
|
+
guess = @gonzaga.guess_round_dates
|
251
|
+
expect(guess.join('|')).to eq('2019-01-25|2019-01-26|2019-01-26|2019-01-27|2019-01-27')
|
252
|
+
end
|
253
|
+
|
254
|
+
it "7 rounds in 2 weekends" do
|
255
|
+
guess = @sona.guess_round_dates
|
256
|
+
expect(guess.join('|')).to eq('2018-10-20|2018-10-20|2018-10-21|2018-10-21|2018-11-24|2018-11-24|2018-11-25')
|
210
257
|
end
|
211
258
|
end
|
212
259
|
|
213
260
|
context "site" do
|
214
261
|
it "defaults to nil" do
|
215
|
-
Tournament.new('Edinburgh Masters', '2009-11-09').site.
|
262
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09').site).to be_nil
|
216
263
|
end
|
217
264
|
|
218
265
|
it "should be a reasonably valid looking URL" do
|
219
|
-
Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'https://www.bbc.co.uk').site.
|
220
|
-
Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'www.icu.ie/event.php?id=1').site.
|
221
|
-
|
266
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'https://www.bbc.co.uk').site).to eq('https://www.bbc.co.uk')
|
267
|
+
expect(Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'www.icu.ie/event.php?id=1').site).to eq('http://www.icu.ie/event.php?id=1')
|
268
|
+
expect { Tournament.new('Edinburgh Masters', '2009-11-09', :site => 'X') }.to raise_error(/invalid.*site/)
|
222
269
|
end
|
223
270
|
end
|
224
271
|
|
@@ -228,39 +275,39 @@ EOS
|
|
228
275
|
end
|
229
276
|
|
230
277
|
it "may be specified in constructor" do
|
231
|
-
@t.type.
|
232
|
-
@t.arbiter.
|
233
|
-
@t.deputy.
|
234
|
-
@t.time_control.
|
278
|
+
expect(@t.type).to eq('Swiss')
|
279
|
+
expect(@t.arbiter).to eq('Gerry Graham')
|
280
|
+
expect(@t.deputy).to eq('Herbert Scarry')
|
281
|
+
expect(@t.time_control).to eq('120 minutes')
|
235
282
|
end
|
236
283
|
|
237
284
|
it "can be replaced by accessor" do
|
238
285
|
@t.type = 'all-play-all'
|
239
|
-
@t.type.
|
286
|
+
expect(@t.type).to eq('all-play-all')
|
240
287
|
@t.arbiter = 'Michael Crowe'
|
241
|
-
@t.arbiter.
|
288
|
+
expect(@t.arbiter).to eq('Michael Crowe')
|
242
289
|
@t.deputy = 'Mark Orr'
|
243
|
-
@t.deputy.
|
290
|
+
expect(@t.deputy).to eq('Mark Orr')
|
244
291
|
@t.time_control = '90 minutes'
|
245
|
-
@t.time_control.
|
292
|
+
expect(@t.time_control).to eq('90 minutes')
|
246
293
|
end
|
247
294
|
|
248
295
|
it "can be set to nil" do
|
249
296
|
@t.type = ''
|
250
|
-
@t.type.
|
297
|
+
expect(@t.type).to be_nil
|
251
298
|
@t.arbiter = ''
|
252
|
-
@t.arbiter.
|
299
|
+
expect(@t.arbiter).to be_nil
|
253
300
|
@t.deputy = ''
|
254
|
-
@t.deputy.
|
301
|
+
expect(@t.deputy).to be_nil
|
255
302
|
@t.time_control = ''
|
256
|
-
@t.time_control.
|
303
|
+
expect(@t.time_control).to be_nil
|
257
304
|
end
|
258
305
|
|
259
306
|
it "should be valid" do
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
307
|
+
expect { @t.type = '123' }.to raise_error(/invalid.*type/)
|
308
|
+
expect { @t.arbiter = '123' }.to raise_error(/invalid.*arbiter/)
|
309
|
+
expect { @t.deputy = '123' }.to raise_error(/invalid.*deputy/)
|
310
|
+
expect { @t.time_control = 'abc' }.to raise_error(/invalid.*time.*control/)
|
264
311
|
end
|
265
312
|
end
|
266
313
|
|
@@ -270,28 +317,28 @@ EOS
|
|
270
317
|
end
|
271
318
|
|
272
319
|
it "should an empty tie breaks list by default" do
|
273
|
-
@t.tie_breaks.
|
274
|
-
@t.tie_breaks.
|
320
|
+
expect(@t.tie_breaks).to be_an_instance_of(Array)
|
321
|
+
expect(@t.tie_breaks).to be_empty
|
275
322
|
end
|
276
323
|
|
277
324
|
it "should be settable to one or more valid tie break methods" do
|
278
325
|
@t.tie_breaks = [:neustadtl]
|
279
|
-
@t.tie_breaks.join('|').
|
326
|
+
expect(@t.tie_breaks.join('|')).to eq("neustadtl")
|
280
327
|
@t.tie_breaks = [:neustadtl, :blacks]
|
281
|
-
@t.tie_breaks.join('|').
|
328
|
+
expect(@t.tie_breaks.join('|')).to eq("neustadtl|blacks")
|
282
329
|
@t.tie_breaks = ['Wins', 'Sonneborn-Berger', :harkness]
|
283
|
-
@t.tie_breaks.join('|').
|
330
|
+
expect(@t.tie_breaks.join('|')).to eq("wins|neustadtl|harkness")
|
284
331
|
@t.tie_breaks = []
|
285
|
-
@t.tie_breaks.join('|').
|
332
|
+
expect(@t.tie_breaks.join('|')).to eq("")
|
286
333
|
end
|
287
334
|
|
288
335
|
it "should rasie an error is not given an array" do
|
289
|
-
|
336
|
+
expect { @t.tie_breaks = :neustadtl }.to raise_error(/array/i)
|
290
337
|
end
|
291
338
|
|
292
339
|
it "should rasie an error is given any invalid tie-break methods" do
|
293
|
-
|
294
|
-
|
340
|
+
expect { @t.tie_breaks = ["My Bum"] }.to raise_error(/invalid/i)
|
341
|
+
expect { @t.tie_breaks = [:neustadtl, "Your arse"] }.to raise_error(/invalid/i)
|
295
342
|
end
|
296
343
|
end
|
297
344
|
|
@@ -302,15 +349,15 @@ EOS
|
|
302
349
|
|
303
350
|
it "should have unique numbers" do
|
304
351
|
@t.add_player(Player.new('Mark', 'Orr', 1))
|
305
|
-
|
352
|
+
expect { @t.add_player(Player.new('Bobby', 'Fischer', 1)) }.to raise_error(/player.*unique/)
|
306
353
|
end
|
307
354
|
|
308
355
|
it "can be added one at a time" do
|
309
356
|
@t.add_player(Player.new('Mark', 'Orr', -1))
|
310
357
|
@t.add_player(Player.new('Gary', 'Kasparov', -2))
|
311
358
|
@t.add_player(Player.new('Bobby', 'Fischer', -3))
|
312
|
-
@t.players.size.
|
313
|
-
@t.player(-1).first_name.
|
359
|
+
expect(@t.players.size).to eq(3)
|
360
|
+
expect(@t.player(-1).first_name).to eq('Mark')
|
314
361
|
end
|
315
362
|
end
|
316
363
|
|
@@ -326,38 +373,38 @@ EOS
|
|
326
373
|
@t.add_result(Result.new(1, 1, 'W', :opponent => 2))
|
327
374
|
@t.add_result(Result.new(2, 2, 'D', :opponent => 3))
|
328
375
|
@t.add_result(Result.new(3, 3, 'L', :opponent => 1, :rateable => false))
|
329
|
-
@mark.results.size.
|
330
|
-
@mark.points.
|
331
|
-
@gary.results.size.
|
332
|
-
@gary.points.
|
333
|
-
@boby.results.size.
|
334
|
-
@boby.points.
|
376
|
+
expect(@mark.results.size).to eq(2)
|
377
|
+
expect(@mark.points).to eq(2.0)
|
378
|
+
expect(@gary.results.size).to eq(2)
|
379
|
+
expect(@gary.points).to eq(0.5)
|
380
|
+
expect(@boby.results.size).to eq(2)
|
381
|
+
expect(@boby.points).to eq(0.5)
|
335
382
|
end
|
336
383
|
|
337
384
|
it "results with asymmetric scores cannot be added unless both results are unrateable" do
|
338
385
|
@t.add_result(Result.new(1, 1, 'W', :opponent => 2))
|
339
|
-
|
340
|
-
|
341
|
-
|
386
|
+
expect { @t.add_result(Result.new(1, 2, 'D', :opponent => 1)) }.to raise_error(/result.*match/)
|
387
|
+
expect { @t.add_result(Result.new(1, 2, 'L', :opponent => 1, :rateable => false)) }.to raise_error(/result.*match/)
|
388
|
+
expect { @t.add_result(Result.new(3, 3, 'L', :opponent => 1, :rateable => false)) }.not_to raise_error
|
342
389
|
end
|
343
390
|
|
344
391
|
it "should have a defined player" do
|
345
|
-
|
392
|
+
expect { @t.add_result(Result.new(1, 4, 'L', :opponent => 1)) }.to raise_error(/player.*exist/)
|
346
393
|
end
|
347
394
|
|
348
395
|
it "should have a defined opponent" do
|
349
|
-
|
396
|
+
expect { @t.add_result(Result.new(1, 1, 'W', :opponent => 4)) }.to raise_error(/opponent.*exist/)
|
350
397
|
end
|
351
398
|
|
352
399
|
it "should be consistent with the tournament's number of rounds" do
|
353
|
-
|
400
|
+
expect { @t.add_result(Result.new(4, 1, 'W', :opponent => 2)) }.to raise_error(/round/)
|
354
401
|
end
|
355
402
|
|
356
403
|
it "documentation example should ne correct" do
|
357
404
|
@t.add_result(ICU::Result.new(3, 2, 'L', :opponent => 1, :rateable => false))
|
358
405
|
@t.add_result(ICU::Result.new(3, 1, 'L', :opponent => 2, :rateable => false))
|
359
|
-
@t.player(1).results.first.points.
|
360
|
-
@t.player(2).results.first.points.
|
406
|
+
expect(@t.player(1).results.first.points).to eq(0.0)
|
407
|
+
expect(@t.player(2).results.first.points).to eq(0.0)
|
361
408
|
end
|
362
409
|
end
|
363
410
|
|
@@ -370,10 +417,10 @@ EOS
|
|
370
417
|
end
|
371
418
|
|
372
419
|
it "should find players based on loose equality" do
|
373
|
-
@t.find_player(Player.new('Mark', 'Orr', 4, :fed => 'IRL')).num.
|
374
|
-
@t.find_player(Player.new('Mark', 'Orr', 4, :fed => 'USA')).
|
375
|
-
@t.find_player(Player.new('Mark', 'Sax', 4, :fed => 'IRL')).
|
376
|
-
@t.find_player(Player.new('John', 'Orr', 4, :fed => 'IRL')).
|
420
|
+
expect(@t.find_player(Player.new('Mark', 'Orr', 4, :fed => 'IRL')).num).to eq(3)
|
421
|
+
expect(@t.find_player(Player.new('Mark', 'Orr', 4, :fed => 'USA'))).to be_nil
|
422
|
+
expect(@t.find_player(Player.new('Mark', 'Sax', 4, :fed => 'IRL'))).to be_nil
|
423
|
+
expect(@t.find_player(Player.new('John', 'Orr', 4, :fed => 'IRL'))).to be_nil
|
377
424
|
end
|
378
425
|
end
|
379
426
|
|
@@ -384,21 +431,21 @@ EOS
|
|
384
431
|
|
385
432
|
it "should be able to create a new team, add it and retrieve it" do
|
386
433
|
team = Team.new('Wandering Dragons')
|
387
|
-
@t.add_team(team).
|
388
|
-
@t.get_team(' wandering dragons ').
|
389
|
-
@t.get_team('Blundering Bishops').
|
434
|
+
expect(@t.add_team(team)).to be_an_instance_of Team
|
435
|
+
expect(@t.get_team(' wandering dragons ')).to be_an_instance_of Team
|
436
|
+
expect(@t.get_team('Blundering Bishops')).to be_nil
|
390
437
|
end
|
391
438
|
|
392
439
|
it "should be able to create and add a new team and retrieve it" do
|
393
|
-
@t.add_team('Blundering Bishops').
|
394
|
-
@t.get_team(' blundering bishops ').
|
395
|
-
@t.get_team('Wandering Dragons').
|
440
|
+
expect(@t.add_team('Blundering Bishops')).to be_an_instance_of Team
|
441
|
+
expect(@t.get_team(' blundering bishops ')).to be_an_instance_of Team
|
442
|
+
expect(@t.get_team('Wandering Dragons')).to be_nil
|
396
443
|
end
|
397
444
|
|
398
445
|
it "should throw and exception if there is an attempt to add a team with a name that matches an existing team" do
|
399
|
-
|
400
|
-
|
401
|
-
|
446
|
+
expect { @t.add_team('Blundering Bishops') }.not_to raise_error
|
447
|
+
expect { @t.add_team('Wandering Dragons') }.not_to raise_error
|
448
|
+
expect { @t.add_team(' wandering dragons ') }.to raise_error(/similar.*exists/)
|
402
449
|
end
|
403
450
|
end
|
404
451
|
|
@@ -417,42 +464,42 @@ EOS
|
|
417
464
|
end
|
418
465
|
|
419
466
|
it "should be valid" do
|
420
|
-
@t.invalid.
|
467
|
+
expect(@t.invalid).to be_falsey
|
421
468
|
end
|
422
469
|
|
423
470
|
it "should have side effect of setting number of rounds" do
|
424
|
-
@t.rounds.
|
471
|
+
expect(@t.rounds).to be_nil
|
425
472
|
@t.invalid
|
426
|
-
@t.rounds.
|
473
|
+
expect(@t.rounds).to eq(3)
|
427
474
|
end
|
428
475
|
|
429
476
|
it "should detect an inconsistent start date" do
|
430
477
|
@t.start = '2009-11-10'
|
431
|
-
|
478
|
+
expect { @t.validate! }.to raise_error(/first round.*not match.*start/)
|
432
479
|
end
|
433
480
|
|
434
481
|
it "should detect an inconsistent finish date" do
|
435
482
|
@t.finish = '2009-11-10'
|
436
|
-
|
483
|
+
expect { @t.validate! }.to raise_error(/last round.*not match.*end/)
|
437
484
|
end
|
438
485
|
|
439
486
|
it "should have side effect of setting missing finish date" do
|
440
|
-
@t.finish.
|
487
|
+
expect(@t.finish).to be_nil
|
441
488
|
@t.invalid
|
442
|
-
@t.finish.
|
489
|
+
expect(@t.finish).to eq('2009-11-11')
|
443
490
|
end
|
444
491
|
|
445
492
|
it "should detect inconsistent round dates" do
|
446
493
|
@t.add_round_date('2009-11-12')
|
447
|
-
|
494
|
+
expect { @t.validate! }.to raise_error(/round dates.*match.*rounds/)
|
448
495
|
end
|
449
496
|
|
450
497
|
it "should have the side effect of providing missing ranks if the rerank option is set" do
|
451
|
-
@t.players.select{ |p| p.rank }.size.
|
498
|
+
expect(@t.players.select{ |p| p.rank }.size).to eq(0)
|
452
499
|
@t.invalid(:rerank => true)
|
453
|
-
@t.player(1).rank.
|
454
|
-
@t.player(2).rank.
|
455
|
-
@t.player(3).rank.
|
500
|
+
expect(@t.player(1).rank).to eq(1)
|
501
|
+
expect(@t.player(2).rank).to eq(2)
|
502
|
+
expect(@t.player(3).rank).to eq(3)
|
456
503
|
end
|
457
504
|
|
458
505
|
it "should have the side effect of correcting bad ranks if the rerank option is set" do
|
@@ -460,16 +507,16 @@ EOS
|
|
460
507
|
@t.player(2).rank = 1
|
461
508
|
@t.player(3).rank = 3
|
462
509
|
@t.invalid(:rerank => true)
|
463
|
-
@t.player(1).rank.
|
464
|
-
@t.player(2).rank.
|
465
|
-
@t.player(3).rank.
|
510
|
+
expect(@t.player(1).rank).to eq(1)
|
511
|
+
expect(@t.player(2).rank).to eq(2)
|
512
|
+
expect(@t.player(3).rank).to eq(3)
|
466
513
|
end
|
467
514
|
|
468
515
|
it "should detect missranked players" do
|
469
516
|
@t.player(1).rank = 2
|
470
517
|
@t.player(2).rank = 1
|
471
518
|
@t.player(3).rank = 3
|
472
|
-
|
519
|
+
expect { @t.validate! }.to raise_error(/player 2.*above.*player 1/)
|
473
520
|
end
|
474
521
|
|
475
522
|
it "should be valid if there are teams, every player is in one of them, and no team has an invalid member" do
|
@@ -477,13 +524,13 @@ EOS
|
|
477
524
|
team2 = Team.new('World Champions')
|
478
525
|
@t.add_team(team1)
|
479
526
|
@t.add_team(team2)
|
480
|
-
@t.invalid.
|
527
|
+
expect(@t.invalid).to match(/not.*member/)
|
481
528
|
team1.add_member(1)
|
482
529
|
team2.add_member(2)
|
483
530
|
team2.add_member(3)
|
484
|
-
@t.invalid.
|
531
|
+
expect(@t.invalid).to be_falsey
|
485
532
|
team1.add_member(4)
|
486
|
-
@t.invalid.
|
533
|
+
expect(@t.invalid).to match(/not.*valid/)
|
487
534
|
end
|
488
535
|
|
489
536
|
it "should not be valid if one player is in more than one team" do
|
@@ -494,25 +541,25 @@ EOS
|
|
494
541
|
team2.add_member(3)
|
495
542
|
@t.add_team(team1)
|
496
543
|
@t.add_team(team2)
|
497
|
-
@t.invalid.
|
544
|
+
expect(@t.invalid).to be_falsey
|
498
545
|
team1.add_member(2)
|
499
|
-
@t.invalid.
|
546
|
+
expect(@t.invalid).to match(/already.*member/)
|
500
547
|
end
|
501
548
|
|
502
549
|
it "should not be valid if two players share the same ICU or FIDE ID" do
|
503
550
|
@t.player(1).id = 1350
|
504
551
|
@t.player(2).id = 1350
|
505
|
-
@t.invalid.
|
552
|
+
expect(@t.invalid).to match(/duplicate.*ICU/)
|
506
553
|
end
|
507
554
|
|
508
555
|
it "should allow players to have no results" do
|
509
556
|
(1..3).each { |r| @t.player(1).remove_result(r) }
|
510
|
-
@t.invalid.
|
557
|
+
expect(@t.invalid).to be_falsey
|
511
558
|
end
|
512
559
|
|
513
560
|
it "should not allow asymmetric scores for rateable results" do
|
514
561
|
@t.player(1).find_result(1).score = 'L'
|
515
|
-
@t.invalid.
|
562
|
+
expect(@t.invalid).to match(/result.*reverse/)
|
516
563
|
end
|
517
564
|
|
518
565
|
it "should allow asymmetric scores for unrateable results" do
|
@@ -522,7 +569,7 @@ EOS
|
|
522
569
|
r.rateable = false
|
523
570
|
r.score = 'L'
|
524
571
|
end
|
525
|
-
@t.invalid.
|
572
|
+
expect(@t.invalid).to be_falsey
|
526
573
|
end
|
527
574
|
end
|
528
575
|
|
@@ -538,39 +585,39 @@ EOS
|
|
538
585
|
end
|
539
586
|
|
540
587
|
it "sample tournament is valid but unranked" do
|
541
|
-
@t.invalid.
|
542
|
-
@t.player(10).rank.
|
543
|
-
@t.players.map{ |p| p.num }.join('|').
|
544
|
-
@t.players.map{ |p| p.last_name }.join('|').
|
588
|
+
expect(@t.invalid).to be_falsey
|
589
|
+
expect(@t.player(10).rank).to be_nil
|
590
|
+
expect(@t.players.map{ |p| p.num }.join('|')).to eq('10|20|30')
|
591
|
+
expect(@t.players.map{ |p| p.last_name }.join('|')).to eq('Fischer|Orr|Kasparov')
|
545
592
|
end
|
546
593
|
|
547
594
|
it "should be renumberable by name in the absence of ranking" do
|
548
595
|
@t.renumber
|
549
|
-
@t.invalid.
|
550
|
-
@t.players.map{ |p| p.num }.join('|').
|
551
|
-
@t.players.map{ |p| p.last_name }.join('|').
|
596
|
+
expect(@t.invalid).to be_falsey
|
597
|
+
expect(@t.players.map{ |p| p.num }.join('|')).to eq('1|2|3')
|
598
|
+
expect(@t.players.map{ |p| p.last_name }.join('|')).to eq('Fischer|Kasparov|Orr')
|
552
599
|
end
|
553
600
|
|
554
601
|
it "should be renumberable by rank if the tournament is ranked" do
|
555
602
|
@t.rerank.renumber
|
556
|
-
@t.invalid.
|
557
|
-
@t.players.map{ |p| p.num }.join('|').
|
558
|
-
@t.players.map{ |p| p.rank }.join('|').
|
559
|
-
@t.players.map{ |p| p.last_name }.join('|').
|
603
|
+
expect(@t.invalid).to be_falsey
|
604
|
+
expect(@t.players.map{ |p| p.num }.join('|')).to eq('1|2|3')
|
605
|
+
expect(@t.players.map{ |p| p.rank }.join('|')).to eq('1|2|3')
|
606
|
+
expect(@t.players.map{ |p| p.last_name }.join('|')).to eq('Orr|Kasparov|Fischer')
|
560
607
|
end
|
561
608
|
|
562
609
|
it "should be renumberable by name even if the tourament is ranked" do
|
563
610
|
@t.rerank.renumber(:name)
|
564
|
-
@t.invalid.
|
565
|
-
@t.players.map{ |p| p.num }.join('|').
|
566
|
-
@t.players.map{ |p| p.last_name }.join('|').
|
611
|
+
expect(@t.invalid).to be_falsey
|
612
|
+
expect(@t.players.map{ |p| p.num }.join('|')).to eq('1|2|3')
|
613
|
+
expect(@t.players.map{ |p| p.last_name }.join('|')).to eq('Fischer|Kasparov|Orr')
|
567
614
|
end
|
568
615
|
|
569
616
|
it "should be renumberable by order" do
|
570
617
|
@t.rerank.renumber(:order)
|
571
|
-
@t.invalid.
|
572
|
-
@t.players.map{ |p| p.num }.join('|').
|
573
|
-
@t.players.map{ |p| p.last_name }.join('|').
|
618
|
+
expect(@t.invalid).to be_falsey
|
619
|
+
expect(@t.players.map{ |p| p.num }.join('|')).to eq('1|2|3')
|
620
|
+
expect(@t.players.map{ |p| p.last_name }.join('|')).to eq('Fischer|Orr|Kasparov')
|
574
621
|
end
|
575
622
|
end
|
576
623
|
|
@@ -595,34 +642,34 @@ EOS
|
|
595
642
|
end
|
596
643
|
|
597
644
|
it "should initially be valid but unranked" do
|
598
|
-
@t.invalid.
|
599
|
-
@t.player(1).rank.
|
645
|
+
expect(@t.invalid).to be_falsey
|
646
|
+
expect(@t.player(1).rank).to be_nil
|
600
647
|
end
|
601
648
|
|
602
649
|
it "should have correct default tie break scores" do
|
603
650
|
scores = @t.tie_break_scores
|
604
|
-
scores[1].
|
605
|
-
scores[5].
|
651
|
+
expect(scores[1]).to eq('Fischer, Bobby')
|
652
|
+
expect(scores[5]).to eq('Ui Laighleis, Gearoidin')
|
606
653
|
end
|
607
654
|
|
608
655
|
it "should have correct actual scores" do
|
609
|
-
@t.player(1).points.
|
610
|
-
@t.player(2).points.
|
611
|
-
@t.player(3).points.
|
612
|
-
@t.player(4).points.
|
613
|
-
@t.player(5).points.
|
614
|
-
@t.player(6).points.
|
656
|
+
expect(@t.player(1).points).to eq(3.0)
|
657
|
+
expect(@t.player(2).points).to eq(3.0)
|
658
|
+
expect(@t.player(3).points).to eq(1.0)
|
659
|
+
expect(@t.player(4).points).to eq(1.0)
|
660
|
+
expect(@t.player(5).points).to eq(0.5)
|
661
|
+
expect(@t.player(6).points).to eq(0.5)
|
615
662
|
end
|
616
663
|
|
617
664
|
it "should have correct Buchholz tie break scores" do
|
618
665
|
@t.tie_breaks = ["Buchholz"]
|
619
666
|
scores = @t.tie_break_scores
|
620
|
-
scores[1].
|
621
|
-
scores[2].
|
622
|
-
scores[3].
|
623
|
-
scores[4].
|
624
|
-
scores[5].
|
625
|
-
scores[6].
|
667
|
+
expect(scores[1]).to eq(2.0)
|
668
|
+
expect(scores[2]).to eq(2.5)
|
669
|
+
expect(scores[3]).to eq(7.0)
|
670
|
+
expect(scores[4]).to eq(4.5)
|
671
|
+
expect(scores[5]).to eq(6.5)
|
672
|
+
expect(scores[6]).to eq(4.5)
|
626
673
|
end
|
627
674
|
|
628
675
|
it "Buchholz should be sensitive to unplayed games" do
|
@@ -630,45 +677,45 @@ EOS
|
|
630
677
|
@t.player(6).find_result(1).opponent = nil
|
631
678
|
@t.tie_breaks = ["Buchholz"]
|
632
679
|
scores = @t.tie_break_scores
|
633
|
-
scores[1].
|
634
|
-
scores[2].
|
635
|
-
scores[3].
|
636
|
-
scores[4].
|
637
|
-
scores[5].
|
638
|
-
scores[6].
|
680
|
+
expect(scores[1]).to eq(1.5) # 0.5 from Orr changed to 0
|
681
|
+
expect(scores[2]).to eq(2.5) # didn't play Fischer or Orr so unaffected
|
682
|
+
expect(scores[3]).to eq(6.5) # 3 from Fischer's changed to 2.5
|
683
|
+
expect(scores[4]).to eq(5.0) # 0.5 from Orr changed to 1 (because Orr's unrated loss to Fischer now counts as a draw)
|
684
|
+
expect(scores[5]).to eq(6.5) # 3 from Fischer changed to 2.5, 0.5 from Orr changed to 1 (cancels out)
|
685
|
+
expect(scores[6]).to eq(1.5) # 3 from Fischer changed to 0
|
639
686
|
end
|
640
687
|
|
641
688
|
it "should have correct progressive tie break scores" do
|
642
689
|
@t.tie_breaks = [:progressive]
|
643
690
|
scores = @t.tie_break_scores
|
644
|
-
scores[1].
|
645
|
-
scores[2].
|
646
|
-
scores[3].
|
647
|
-
scores[4].
|
648
|
-
scores[5].
|
649
|
-
scores[6].
|
691
|
+
expect(scores[1]).to eq(6.0)
|
692
|
+
expect(scores[2]).to eq(6.0)
|
693
|
+
expect(scores[3]).to eq(3.0)
|
694
|
+
expect(scores[4]).to eq(1.0)
|
695
|
+
expect(scores[5]).to eq(1.0)
|
696
|
+
expect(scores[6]).to eq(1.0)
|
650
697
|
end
|
651
698
|
|
652
699
|
it "should have correct ratings tie break scores" do
|
653
700
|
@t.tie_breaks = ['ratings']
|
654
701
|
scores = @t.tie_break_scores
|
655
|
-
scores[1].
|
656
|
-
scores[2].
|
657
|
-
scores[3].
|
658
|
-
scores[4].
|
659
|
-
scores[5].
|
660
|
-
scores[6].
|
702
|
+
expect(scores[1]).to eq(4000)
|
703
|
+
expect(scores[2]).to eq(3200)
|
704
|
+
expect(scores[3]).to eq(6800)
|
705
|
+
expect(scores[4]).to eq(5000)
|
706
|
+
expect(scores[5]).to eq(7600)
|
707
|
+
expect(scores[6]).to eq(5800)
|
661
708
|
end
|
662
709
|
|
663
710
|
it "should have correct Neustadtl tie break scores" do
|
664
711
|
@t.tie_breaks = [:neustadtl]
|
665
712
|
scores = @t.tie_break_scores
|
666
|
-
scores[1].
|
667
|
-
scores[2].
|
668
|
-
scores[3].
|
669
|
-
scores[4].
|
670
|
-
scores[5].
|
671
|
-
scores[6].
|
713
|
+
expect(scores[1]).to eq(2.0)
|
714
|
+
expect(scores[2]).to eq(2.5)
|
715
|
+
expect(scores[3]).to eq(1.0)
|
716
|
+
expect(scores[4]).to eq(0.5)
|
717
|
+
expect(scores[5]).to eq(0.25)
|
718
|
+
expect(scores[6]).to eq(0.25)
|
672
719
|
end
|
673
720
|
|
674
721
|
it "Neustadtl should be sensitive to unplayed games" do
|
@@ -676,41 +723,41 @@ EOS
|
|
676
723
|
@t.player(6).find_result(1).opponent = nil
|
677
724
|
@t.tie_breaks = ["Neustadtl"]
|
678
725
|
scores = @t.tie_break_scores
|
679
|
-
scores[1].
|
680
|
-
scores[2].
|
681
|
-
scores[3].
|
682
|
-
scores[4].
|
683
|
-
scores[5].
|
684
|
-
scores[6].
|
726
|
+
expect(scores[1]).to eq(1.5) # 0.5 from Orr changed to 0
|
727
|
+
expect(scores[2]).to eq(2.5) # didn't play Fischer or Orr so unaffected
|
728
|
+
expect(scores[3]).to eq(1.0) # win against Minnie unaffected
|
729
|
+
expect(scores[4]).to eq(1.0) # 0.5 from Orr changed to 1 (because Orr's unrated loss to Fischer now counts as a draw)
|
730
|
+
expect(scores[5]).to eq(0.5) # 0.25 from Orr changed to 0.5
|
731
|
+
expect(scores[6]).to eq(0.25) # loss against Fisher and unplayed against Fisher equivalent
|
685
732
|
end
|
686
733
|
|
687
734
|
it "should have correct Harkness tie break scores" do
|
688
735
|
@t.tie_breaks = ['harkness']
|
689
736
|
scores = @t.tie_break_scores
|
690
|
-
scores[1].
|
691
|
-
scores[2].
|
692
|
-
scores[3].
|
693
|
-
scores[4].
|
694
|
-
scores[5].
|
695
|
-
scores[6].
|
737
|
+
expect(scores[1]).to eq(0.5)
|
738
|
+
expect(scores[2]).to eq(1.0)
|
739
|
+
expect(scores[3]).to eq(3.0)
|
740
|
+
expect(scores[4]).to eq(1.0)
|
741
|
+
expect(scores[5]).to eq(3.0)
|
742
|
+
expect(scores[6]).to eq(1.0)
|
696
743
|
end
|
697
744
|
|
698
745
|
it "should have correct Modified Median tie break scores" do
|
699
746
|
@t.tie_breaks = ['Modified Median']
|
700
747
|
scores = @t.tie_break_scores
|
701
|
-
scores[1].
|
702
|
-
scores[2].
|
703
|
-
scores[3].
|
704
|
-
scores[4].
|
705
|
-
scores[5].
|
706
|
-
scores[6].
|
748
|
+
expect(scores[1]).to eq(1.5)
|
749
|
+
expect(scores[2]).to eq(2.0)
|
750
|
+
expect(scores[3]).to eq(4.0)
|
751
|
+
expect(scores[4]).to eq(1.5)
|
752
|
+
expect(scores[5]).to eq(3.5)
|
753
|
+
expect(scores[6]).to eq(1.5)
|
707
754
|
end
|
708
755
|
|
709
756
|
it "should have correct tie break scores for number of blacks" do
|
710
757
|
@t.tie_breaks = ['Blacks']
|
711
758
|
scores = @t.tie_break_scores
|
712
|
-
scores[3].
|
713
|
-
scores[4].
|
759
|
+
expect(scores[3]).to eq(0)
|
760
|
+
expect(scores[4]).to eq(2)
|
714
761
|
end
|
715
762
|
|
716
763
|
it "number of blacks should should be sensitive to unplayed games" do
|
@@ -718,15 +765,15 @@ EOS
|
|
718
765
|
@t.player(4).find_result(1).opponent = nil
|
719
766
|
@t.tie_breaks = [:blacks]
|
720
767
|
scores = @t.tie_break_scores
|
721
|
-
scores[3].
|
722
|
-
scores[4].
|
768
|
+
expect(scores[3]).to eq(0)
|
769
|
+
expect(scores[4]).to eq(1)
|
723
770
|
end
|
724
771
|
|
725
772
|
it "should have correct tie break scores for number of wins" do
|
726
773
|
@t.tie_breaks = [:wins]
|
727
774
|
scores = @t.tie_break_scores
|
728
|
-
scores[1].
|
729
|
-
scores[6].
|
775
|
+
expect(scores[1]).to eq(3)
|
776
|
+
expect(scores[6]).to eq(0)
|
730
777
|
end
|
731
778
|
|
732
779
|
it "number of wins should should be sensitive to unplayed games" do
|
@@ -734,101 +781,101 @@ EOS
|
|
734
781
|
@t.player(6).find_result(1).opponent = nil
|
735
782
|
@t.tie_breaks = ['WINS']
|
736
783
|
scores = @t.tie_break_scores
|
737
|
-
scores[1].
|
738
|
-
scores[6].
|
784
|
+
expect(scores[1]).to eq(2)
|
785
|
+
expect(scores[6]).to eq(0)
|
739
786
|
end
|
740
787
|
|
741
788
|
it "should use names for tie breaking by default" do
|
742
789
|
@t.rerank
|
743
|
-
@t.player(1).rank.
|
744
|
-
@t.player(2).rank.
|
745
|
-
@t.player(3).rank.
|
746
|
-
@t.player(4).rank.
|
747
|
-
@t.player(6).rank.
|
748
|
-
@t.player(5).rank.
|
790
|
+
expect(@t.player(1).rank).to eq(1) # 3.0/"Fischer"
|
791
|
+
expect(@t.player(2).rank).to eq(2) # 3.0/"Kasparov"
|
792
|
+
expect(@t.player(3).rank).to eq(3) # 1.0/"Mouse,Mickey"
|
793
|
+
expect(@t.player(4).rank).to eq(4) # 1.0/"Mouse,Minnie"
|
794
|
+
expect(@t.player(6).rank).to eq(5) # 0.5/"Ui"
|
795
|
+
expect(@t.player(5).rank).to eq(6) # 0.5/"Orr"
|
749
796
|
end
|
750
797
|
|
751
798
|
it "should be configurable to use Buchholz" do
|
752
799
|
@t.tie_breaks = ['Buchholz']
|
753
800
|
@t.rerank
|
754
|
-
@t.player(2).rank.
|
755
|
-
@t.player(1).rank.
|
756
|
-
@t.player(3).rank.
|
757
|
-
@t.player(4).rank.
|
758
|
-
@t.player(5).rank.
|
759
|
-
@t.player(6).rank.
|
801
|
+
expect(@t.player(2).rank).to eq(1) # 3.0/2.5
|
802
|
+
expect(@t.player(1).rank).to eq(2) # 3.0/2.0
|
803
|
+
expect(@t.player(3).rank).to eq(3) # 1.0/7.0
|
804
|
+
expect(@t.player(4).rank).to eq(4) # 1.0/4.5
|
805
|
+
expect(@t.player(5).rank).to eq(5) # 0.5/6.5
|
806
|
+
expect(@t.player(6).rank).to eq(6) # 0.5/4.5
|
760
807
|
end
|
761
808
|
|
762
809
|
it "should be configurable to use Neustadtl" do
|
763
810
|
@t.tie_breaks = [:neustadtl]
|
764
811
|
@t.rerank
|
765
|
-
@t.player(2).rank.
|
766
|
-
@t.player(1).rank.
|
767
|
-
@t.player(3).rank.
|
768
|
-
@t.player(4).rank.
|
769
|
-
@t.player(6).rank.
|
770
|
-
@t.player(5).rank.
|
812
|
+
expect(@t.player(2).rank).to eq(1) # 3.0/2.5
|
813
|
+
expect(@t.player(1).rank).to eq(2) # 3.0/2.0
|
814
|
+
expect(@t.player(3).rank).to eq(3) # 1.0/1.0
|
815
|
+
expect(@t.player(4).rank).to eq(4) # 1.0/0.5
|
816
|
+
expect(@t.player(6).rank).to eq(5) # 0.5/0.25/"Orr"
|
817
|
+
expect(@t.player(5).rank).to eq(6) # 0.5/0.25/"Ui"
|
771
818
|
end
|
772
819
|
|
773
820
|
it "should be configurable to use number of blacks" do
|
774
821
|
@t.tie_breaks = [:blacks]
|
775
822
|
@t.rerank
|
776
|
-
@t.player(2).rank.
|
777
|
-
@t.player(1).rank.
|
778
|
-
@t.player(4).rank.
|
779
|
-
@t.player(3).rank.
|
780
|
-
@t.player(6).rank.
|
781
|
-
@t.player(5).rank.
|
823
|
+
expect(@t.player(2).rank).to eq(1) # 3.0/2
|
824
|
+
expect(@t.player(1).rank).to eq(2) # 3.0/1
|
825
|
+
expect(@t.player(4).rank).to eq(3) # 1.0/2
|
826
|
+
expect(@t.player(3).rank).to eq(4) # 1.0/1
|
827
|
+
expect(@t.player(6).rank).to eq(5) # 0.5/2
|
828
|
+
expect(@t.player(5).rank).to eq(6) # 0.5/1
|
782
829
|
end
|
783
830
|
|
784
831
|
it "should be configurable to use number of wins" do
|
785
832
|
@t.tie_breaks = [:wins]
|
786
833
|
@t.rerank
|
787
|
-
@t.player(1).rank.
|
788
|
-
@t.player(2).rank.
|
789
|
-
@t.player(3).rank.
|
790
|
-
@t.player(4).rank.
|
791
|
-
@t.player(6).rank.
|
792
|
-
@t.player(5).rank.
|
834
|
+
expect(@t.player(1).rank).to eq(1) # 3.0/3/"Fi"
|
835
|
+
expect(@t.player(2).rank).to eq(2) # 3.0/3/"Ka"
|
836
|
+
expect(@t.player(3).rank).to eq(3) # 1.0/1/"Mic"
|
837
|
+
expect(@t.player(4).rank).to eq(4) # 1.0/1/"Min"
|
838
|
+
expect(@t.player(6).rank).to eq(5) # 0.5/0/"Orr"
|
839
|
+
expect(@t.player(5).rank).to eq(6) # 0.5/0/"Ui"
|
793
840
|
end
|
794
841
|
|
795
842
|
it "should exhibit equivalence between Neustadtl and Sonneborn-Berger" do
|
796
843
|
@t.tie_breaks = ['Sonneborn-Berger']
|
797
844
|
@t.rerank
|
798
|
-
(1..6).inject(''){ |t,r| t << @t.player(r).rank.to_s }.
|
845
|
+
expect((1..6).inject(''){ |t,r| t << @t.player(r).rank.to_s }).to eq('213465')
|
799
846
|
end
|
800
847
|
|
801
848
|
it "should be able to use more than one method" do
|
802
849
|
@t.tie_breaks = [:neustadtl, :buchholz]
|
803
850
|
@t.rerank
|
804
|
-
@t.player(2).rank.
|
805
|
-
@t.player(1).rank.
|
806
|
-
@t.player(3).rank.
|
807
|
-
@t.player(4).rank.
|
808
|
-
@t.player(5).rank.
|
809
|
-
@t.player(6).rank.
|
851
|
+
expect(@t.player(2).rank).to eq(1) # 3.0/2.5
|
852
|
+
expect(@t.player(1).rank).to eq(2) # 3.0/2.0
|
853
|
+
expect(@t.player(3).rank).to eq(3) # 1.0/1.0
|
854
|
+
expect(@t.player(4).rank).to eq(4) # 1.0/0.5
|
855
|
+
expect(@t.player(5).rank).to eq(5) # 0.5/0.25/6.5
|
856
|
+
expect(@t.player(6).rank).to eq(6) # 0.5/0.25/4.5
|
810
857
|
end
|
811
858
|
|
812
859
|
it "should be possible as a side effect of validation" do
|
813
860
|
@t.tie_breaks = [:buchholz]
|
814
|
-
@t.invalid(:rerank => true).
|
815
|
-
@t.player(2).rank.
|
816
|
-
@t.player(1).rank.
|
817
|
-
@t.player(3).rank.
|
818
|
-
@t.player(4).rank.
|
819
|
-
@t.player(5).rank.
|
820
|
-
@t.player(6).rank.
|
861
|
+
expect(@t.invalid(:rerank => true)).to be_falsey
|
862
|
+
expect(@t.player(2).rank).to eq(1) # 3/3
|
863
|
+
expect(@t.player(1).rank).to eq(2) # 3/2
|
864
|
+
expect(@t.player(3).rank).to eq(3) # 1/7
|
865
|
+
expect(@t.player(4).rank).to eq(4) # 1/4
|
866
|
+
expect(@t.player(5).rank).to eq(5) # 1/6
|
867
|
+
expect(@t.player(6).rank).to eq(6) # 0/5
|
821
868
|
end
|
822
869
|
|
823
870
|
it "should be possible as a side effect of validation with multiple tie break methods" do
|
824
871
|
@t.tie_breaks = [:neustadtl, :buchholz]
|
825
|
-
@t.invalid(:rerank => true).
|
826
|
-
@t.player(2).rank.
|
827
|
-
@t.player(1).rank.
|
828
|
-
@t.player(3).rank.
|
829
|
-
@t.player(4).rank.
|
830
|
-
@t.player(5).rank.
|
831
|
-
@t.player(6).rank.
|
872
|
+
expect(@t.invalid(:rerank => true)).to be_falsey
|
873
|
+
expect(@t.player(2).rank).to eq(1) # 3/3
|
874
|
+
expect(@t.player(1).rank).to eq(2) # 3/2
|
875
|
+
expect(@t.player(3).rank).to eq(3) # 1/7
|
876
|
+
expect(@t.player(4).rank).to eq(4) # 1/4
|
877
|
+
expect(@t.player(5).rank).to eq(5) # 1/6
|
878
|
+
expect(@t.player(6).rank).to eq(6) # 0/5
|
832
879
|
end
|
833
880
|
end
|
834
881
|
|
@@ -840,49 +887,49 @@ EOS
|
|
840
887
|
|
841
888
|
it "should parse a valid SwissPerfect file" do
|
842
889
|
t = nil
|
843
|
-
|
844
|
-
t.players.size.
|
845
|
-
t.start.
|
890
|
+
expect { t = @c.parse_file!("#{@s}/sp/nccz.zip", 'SwissPerfect', :start => '2010-05-08') }.not_to raise_error
|
891
|
+
expect(t.players.size).to eq(77)
|
892
|
+
expect(t.start).to eq('2010-05-08')
|
846
893
|
end
|
847
894
|
|
848
895
|
it "should parse a valid CSV file" do
|
849
896
|
t = nil
|
850
|
-
|
851
|
-
t.players.size.
|
897
|
+
expect { t = @c.parse_file!("#{@s}/fcsv/valid.csv", 'ForeignCSV') }.not_to raise_error
|
898
|
+
expect(t.players.size).to eq(16)
|
852
899
|
end
|
853
900
|
|
854
901
|
it "should parse a valid Krause file" do
|
855
902
|
t = nil
|
856
|
-
|
857
|
-
t.players.size.
|
903
|
+
expect { t = @c.parse_file!("#{@s}/krause/valid.tab", 'Krause') }.not_to raise_error
|
904
|
+
expect(t.players.size).to eq(12)
|
858
905
|
end
|
859
906
|
|
860
907
|
it "should ignore options where appropriate" do
|
861
908
|
t = nil
|
862
|
-
|
863
|
-
t.start.
|
909
|
+
expect { t = @c.parse_file!("#{@s}/krause/valid.tab", 'Krause', :start => '2010-05-08') }.not_to raise_error
|
910
|
+
expect(t.start).to eq('2008-02-01')
|
864
911
|
end
|
865
912
|
|
866
913
|
it "should raise exceptions for invalid files" do
|
867
|
-
|
868
|
-
|
869
|
-
|
914
|
+
expect { @c.parse_file!("#{@s}/sp/notenoughfiles.zip", 'SwissPerfect', :start => '2010-05-08') }.to raise_error(/files/)
|
915
|
+
expect { @c.parse_file!("#{@s}/krause/invalid.tab", 'Krause') }.to raise_error(/name/)
|
916
|
+
expect { @c.parse_file!("#{@s}/fcsv/invalid.csv", 'ForeignCSV') }.to raise_error(/termination/)
|
870
917
|
end
|
871
918
|
|
872
919
|
it "should raise exceptions if the wrong type is used" do
|
873
|
-
|
874
|
-
|
875
|
-
|
920
|
+
expect { @c.parse_file!("#{@s}/krause/valid.tab", 'ForeignCSV') }.to raise_error(/expected/)
|
921
|
+
expect { @c.parse_file!("#{@s}/fcsv/valid.csv", 'SwissPerfect') }.to raise_error(/cannot/)
|
922
|
+
expect { @c.parse_file!("#{@s}/sp/nccz.zip", 'Krause') }.to raise_error(/(invalid|conversion)/i)
|
876
923
|
end
|
877
924
|
|
878
925
|
it "should raise an exception if file does not exist" do
|
879
|
-
|
880
|
-
|
881
|
-
|
926
|
+
expect { @c.parse_file!("#{@s}/nosuchfile.cvs", 'ForeignCSV') }.to raise_error(/no such file/i)
|
927
|
+
expect { @c.parse_file!("#{@s}/nosuchfile.zip", 'SwissPerfect') }.to raise_error(/invalid/i)
|
928
|
+
expect { @c.parse_file!("#{@s}/nosuchfile.tab", 'Krause') }.to raise_error(/no such file/i)
|
882
929
|
end
|
883
930
|
|
884
931
|
it "should raise an exception if an invalid type is used" do
|
885
|
-
|
932
|
+
expect { @c.parse_file!("#{@s}/krause/valid.tab", 'NoSuchType') }.to raise_error(/invalid format/i)
|
886
933
|
end
|
887
934
|
end
|
888
935
|
|
@@ -898,12 +945,12 @@ EOS
|
|
898
945
|
end
|
899
946
|
|
900
947
|
it "should pass generic validation" do
|
901
|
-
@t.invalid.
|
948
|
+
expect(@t.invalid).to be_falsey
|
902
949
|
end
|
903
950
|
|
904
951
|
it "should fail type-specific validation when the type supplied is inappropriate" do
|
905
|
-
@t.invalid(:type => String).
|
906
|
-
@t.invalid(:type => "AbCd").
|
952
|
+
expect(@t.invalid(:type => String)).to match(/invalid type/)
|
953
|
+
expect(@t.invalid(:type => "AbCd")).to match(/invalid type/)
|
907
954
|
end
|
908
955
|
end
|
909
956
|
end
|