icu_tournament 1.3.11 → 1.3.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,22 +71,28 @@ module ICU
71
71
  # * the result round numbers are consistent (no more than one game per player per round)
72
72
  # * the tournament dates (start, finish, round dates), if there are any, are consistent
73
73
  # * the player ranks are consistent with their scores
74
+ # * there are no players with duplicate ICU IDs or duplicate FIDE IDs
74
75
  #
75
76
  # Side effects of calling <em>validate!</em> or _invalid_ include:
76
77
  #
77
78
  # * the number of rounds will be set if not set already
78
79
  # * the finish date will be set if not set already and if there are round dates
79
80
  #
80
- # Optionally, additional validation checks can be performed given a tournament
81
- # parser/serializer. For example:
81
+ # Optionally, additional validation checks, appropriate for a given
82
+ # serializer, may be performed. For example:
82
83
  #
83
84
  # t.validate!(:type => ICU::Tournament.ForeignCSV.new)
84
85
  #
85
- # Or equivalently:
86
+ # or equivalently,
86
87
  #
87
88
  # t.validate!(:type => 'ForeignCSV')
88
89
  #
89
- # Such additional validation is always performed before a tournament is serialized.
90
+ # which, amongst other tests, checks that there is at least one player with an ICU number and
91
+ # that all such players have a least one game against a FIDE rated opponent. This is an example
92
+ # of a specialized check that is only appropriate for a particular serializer. If it raises an
93
+ # exception then the tournament cannot be serialized that way.
94
+ #
95
+ # Validation is automatically performed just before a tournament is serialized.
90
96
  # For example, the following are equivalent and will throw an exception if
91
97
  # the tournament is invalid according to either the general rules or the rules
92
98
  # specific for the type used:
@@ -401,7 +407,17 @@ module ICU
401
407
  # Check players.
402
408
  def check_players
403
409
  raise "the number of players (#{@player.size}) must be at least 2" if @player.size < 2
410
+ ids = Hash.new
411
+ fide_ids = Hash.new
404
412
  @player.each do |num, p|
413
+ if p.id
414
+ raise "duplicate ICU IDs, players #{p.num} and #{ids[p.id]}" if ids[p.id]
415
+ ids[p.id] = num
416
+ end
417
+ if p.fide_id
418
+ raise "duplicate FIDE IDs, players #{p.num} and #{fide_ids[p.fide_id]}" if fide_ids[p.fide_id]
419
+ fide_ids[p.fide_id] = num
420
+ end
405
421
  raise "player #{num} has no results" if p.results.size == 0
406
422
  p.results.each do |r|
407
423
  next unless r.opponent
@@ -248,8 +248,8 @@ module ICU
248
248
  case pair[0]
249
249
  when :fed then val = val && val.match(/^[A-Z]{3}$/i) ? val.upcase : nil
250
250
  when :gender then val = val.to_i > 0 ? %w(M F)[val.to_i-1] : nil
251
- when :id then val = val.to_i > 0 ? val : nil
252
- when :fide_id then val = val.to_i > 0 ? val : nil
251
+ when :id then val = val.match(/^\s*([1-9]\d*)\s*$/) ? $1 : nil
252
+ when :fide_id then val = val.match(/^\s*([1-9]\d*)\s*$/) ? $1 : nil
253
253
  when :rating then val = val.to_i > 0 ? val : nil
254
254
  when :fide_rating then val = val.to_i > 0 ? val : nil
255
255
  when :title then val = val.to_i > 0 ? %w(GM WGM IM WIM FM WFM)[val.to_i-1] : nil
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Tournament
5
- VERSION = "1.3.11"
5
+ VERSION = "1.3.12"
6
6
  end
7
7
  end
@@ -162,11 +162,11 @@ module ICU
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.should == "Long, Killian|10293|2|1506||2.5|33|123456|WDLLWL|WWBWBB|TFTTTT"
166
- @t.player(26).sp_signature.should == "Bradley, Michael|6756|27|1413||3.0|26|123456|DDLWWL|BWWBWW|TFTTTT"
167
- @t.player(15).sp_signature.should == "Twomey, Pat|1637|22|1656||4.5|7|123456|WDLWWW|WWWBWB|FFTTTT"
165
+ @t.player(23).sp_signature.should == "Long, Killian|10293||1506||2.5|33|123456|WDLLWL|WWBWBB|TFTTTT"
166
+ @t.player(26).sp_signature.should == "Bradley, Michael|6756||1413||3.0|26|123456|DDLWWL|BWWBWW|TFTTTT"
167
+ @t.player(15).sp_signature.should == "Twomey, Pat|1637||1656||4.5|7|123456|WDLWWW|WWWBWB|FFTTTT"
168
168
  @t.player(46).sp_signature.should == "O'Riordan, Pat|10696||900||2.0|42|123456|LDDLDD|BWBWWB|TTTTFT"
169
- @t.player(38).sp_signature.should == "Gill, Craig I.|10637|28|1081||2.0|43|123456|LLWDDL|BWBWWB|TTTTFT"
169
+ @t.player(38).sp_signature.should == "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
@@ -489,6 +489,12 @@ EOS
489
489
  team1.add_member(2)
490
490
  @t.invalid.should match(/already.*member/)
491
491
  end
492
+
493
+ it "should not be valid if two players share the same ICU or FIDE ID" do
494
+ @t.player(1).id = 1350
495
+ @t.player(2).id = 1350
496
+ @t.invalid.should match(/duplicate.*ICU/)
497
+ end
492
498
  end
493
499
 
494
500
  context "renumbering" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 3
8
- - 11
9
- version: 1.3.11
8
+ - 12
9
+ version: 1.3.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Orr
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-11 00:00:00 +00:00
17
+ date: 2011-03-13 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency