sanichi-chess_icu 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/tournament.rb +12 -2
- data/lib/tournament_krause.rb +3 -2
- data/spec/tournament_krause_spec.rb +26 -0
- data/spec/tournament_spec.rb +19 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/tournament.rb
CHANGED
@@ -153,6 +153,17 @@ with inconsitent ranking, it will be reranked (i.e. the method _rerank_ will be
|
|
153
153
|
@round_dates[round-1]
|
154
154
|
end
|
155
155
|
|
156
|
+
# Return the greatest round number according to the players results (which may not be the same as the set number of rounds).
|
157
|
+
def last_round
|
158
|
+
last_round = 0
|
159
|
+
@player.values.each do |p|
|
160
|
+
p.results.each do |r|
|
161
|
+
last_round = r.round if r.round > last_round
|
162
|
+
end
|
163
|
+
end
|
164
|
+
last_round
|
165
|
+
end
|
166
|
+
|
156
167
|
# Set the tournament web site. Should be either unknown (_nil_) or a reasonably valid looking URL.
|
157
168
|
def site=(site)
|
158
169
|
@site = site.to_s.strip
|
@@ -319,11 +330,10 @@ with inconsitent ranking, it will be reranked (i.e. the method _rerank_ will be
|
|
319
330
|
# if the number of rounds has been set, it should agree with the largest round from the results.
|
320
331
|
def check_rounds
|
321
332
|
round = Hash.new
|
322
|
-
round_last =
|
333
|
+
round_last = last_round
|
323
334
|
@player.values.each do |p|
|
324
335
|
p.results.each do |r|
|
325
336
|
round[r.round] = true
|
326
|
-
round_last = r.round if r.round > round_last
|
327
337
|
end
|
328
338
|
end
|
329
339
|
(1..round_last).each { |r| raise "there are no results for round #{r}" unless round[r] }
|
data/lib/tournament_krause.rb
CHANGED
@@ -190,12 +190,13 @@ The following lists Krause data identification numbers, their description and, w
|
|
190
190
|
team.members.each{ |m| krause << sprintf(' %4d', m) }
|
191
191
|
krause << "\n"
|
192
192
|
end
|
193
|
-
|
193
|
+
rounds = t.last_round
|
194
|
+
if t.round_dates.size == rounds && rounds > 0
|
194
195
|
krause << "132 #{' ' * 85}"
|
195
196
|
t.round_dates.each{ |d| krause << d.sub(/^../, ' ') }
|
196
197
|
krause << "\n"
|
197
198
|
end
|
198
|
-
t.players.each{ |p| krause << p.to_krause(
|
199
|
+
t.players.each{ |p| krause << p.to_krause(rounds) }
|
199
200
|
krause
|
200
201
|
end
|
201
202
|
|
@@ -62,6 +62,7 @@ KRAUSE
|
|
62
62
|
|
63
63
|
it "should have a number of rounds, a type and a time control" do
|
64
64
|
@t.rounds.should == 3
|
65
|
+
@t.last_round.should == 3
|
65
66
|
@t.type.should == 'All-Play-All'
|
66
67
|
@t.time_control.should == '60 in 2hr, 30 in 1hr, rest in 1hr'
|
67
68
|
end
|
@@ -229,6 +230,31 @@ REORDERED
|
|
229
230
|
end
|
230
231
|
end
|
231
232
|
|
233
|
+
context "serialisation of a manually build tournament" do
|
234
|
+
before(:all) do
|
235
|
+
@krause = <<KRAUSE
|
236
|
+
012 Las Vegas National Open
|
237
|
+
042 2008-06-07
|
238
|
+
001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964-06-10 1.0 2 b 0 3 w 1
|
239
|
+
001 2 m Orr,Mark 2258 IRL 2500035 1955-11-09 2.0 1 w 1 3 b 1
|
240
|
+
001 3 g Bologan,Viktor 2663 MDA 13900048 1971-01-01 0.0 1 b 0 2 w 0
|
241
|
+
KRAUSE
|
242
|
+
@p = Krause.new
|
243
|
+
@t = Tournament.new('Las Vegas National Open', '2008-06-07')
|
244
|
+
@t.add_player(Player.new('Gearoidin', 'Ui Laighleis', 1, :rating => 1985, :id => 2501171, :dob => '1964-06-10', :fed => 'IRL', :gender => 'f'))
|
245
|
+
@t.add_player(Player.new('Mark', 'Orr', 2, :rating => 2258, :id => 2500035, :dob => '1955-11-09', :fed => 'IRL', :title => 'm'))
|
246
|
+
@t.add_player(Player.new('Viktor', 'Bologan', 3, :rating => 2663, :id => 13900048, :dob => '1971-01-01', :fed => 'MDA', :title => 'g'))
|
247
|
+
@t.add_result(ICU::Result.new(1, 1, 'L', :opponent => 2, :colour => 'B'))
|
248
|
+
@t.add_result(ICU::Result.new(2, 1, 'W', :opponent => 3, :colour => 'W'))
|
249
|
+
@t.add_result(ICU::Result.new(3, 2, 'W', :opponent => 3, :colour => 'B'))
|
250
|
+
@output = @p.serialize(@t)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should serialise manually build tournaments" do
|
254
|
+
@output.should == @krause
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
232
258
|
context "errors" do
|
233
259
|
before(:each) do
|
234
260
|
@k = <<KRAUSE
|
data/spec/tournament_spec.rb
CHANGED
@@ -147,6 +147,25 @@ module ICU
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
+
context "last_round" do
|
151
|
+
before(:each) do
|
152
|
+
@t = Tournament.new('Edinburgh Masters', '2009-11-09')
|
153
|
+
@t.add_player(@mark = Player.new('Mark', 'Orr', 1))
|
154
|
+
@t.add_player(@gary = Player.new('Gary', 'Kasparov', 2))
|
155
|
+
@t.add_player(@boby = Player.new('Bobby', 'Fischer', 3))
|
156
|
+
end
|
157
|
+
|
158
|
+
it "depends on the players results" do
|
159
|
+
@t.last_round.should == 0
|
160
|
+
@t.add_result(Result.new(1, 1, 'W', :opponent => 2))
|
161
|
+
@t.last_round.should == 1
|
162
|
+
@t.add_result(Result.new(2, 2, 'D', :opponent => 3))
|
163
|
+
@t.last_round.should == 2
|
164
|
+
@t.add_result(Result.new(5, 3, 'L', :opponent => 1))
|
165
|
+
@t.last_round.should == 5
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
150
169
|
context "round date" do
|
151
170
|
before(:each) do
|
152
171
|
@t = Tournament.new('Edinburgh Masters', '2009-11-09')
|