# encoding: UTF-8 require File.expand_path(File.dirname(__FILE__) + '/spec_helper') module ICU class Tournament describe Krause do def check_player(num, first, last, other={}) p = @t.player(num) p.first_name.should == first p.last_name.should == last [:gender, :title, :rating, :fide_rating, :fed, :id, :fide, :dob, :rank].each do |key| p.send(key).should == other[key] if other.has_key?(key) end end def check_results(num, results, points) p = @t.player(num) p.results.size.should == results p.points.should == points end context "a typical tournament" do before(:all) do krause = < true) end it "should have a name, city and federation" do @t.name.should == 'Las Vegas National Open' @t.city.should == 'Las Vegas' @t.fed.should == 'USA' end it "should have start and end dates" do @t.start.should == '2008-06-07' @t.finish.should == '2008-06-09' end it "should have a number of rounds, a type and a time control" do @t.rounds.should == 3 @t.last_round.should == 3 @t.type.should == 'All-Play-All' @t.time_control.should == '60 in 2hr, 30 in 1hr, rest in 1hr' end it "should have an arbiter and deputies" do @t.arbiter.should == 'Hans Scmidt' @t.deputy.should == 'Gerry Graham, Herbert Scarry' end it "should have players and their details" do @t.should have(3).players check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :fide_rating => 1985, :fed => 'IRL', :fide => 2501171, :dob => '1964-06-10', :rank => 2) check_player(2, 'Mark', 'Orr', :gender => 'M', :fide_rating => 2258, :fed => 'IRL', :fide => 2500035, :dob => '1955-11-09', :rank => 1, :title => 'IM') check_player(3, 'Viktor', 'Bologan', :gender => 'M', :fide_rating => 2663, :fed => 'MDA', :fide => 13900048, :dob => '1971-01-01', :rank => 3, :title => 'GM') end it "should have correct results for each player" do check_results(1, 2, 1.0) check_results(2, 2, 2.0) check_results(3, 2, 0.0) end it "should have correct round dates" do @t.round_dates.join('|').should == '2008-06-07|2008-06-08|2008-06-09' end it "the parser should retain comment lines" do comments = < 'F', :rating => 1900, :fed => 'USA', :id => 1234567, :dob => '1928-05-15', :rank => 2) check_player(2, 'Daffy', 'Duck', :gender => 'M', :rating => 2200, :fed => 'IRL', :id => 7654321, :dob => '1937-04-17', :rank => 1, :title => 'IM') check_player(3, 'Mickey', 'Mouse', :gender => 'M', :rating => 2600, :fed => 'USA', :id => 1726354, :dob => '1928-05-15', :rank => 3, :title => 'GM') end it "should have correct results for each player" do check_results(1, 2, 1.0) check_results(2, 2, 2.0) check_results(3, 2, 0.0) end it "the parser should retain comment lines" do @p.comments.should == "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n" end end context "the README serialisation example" do before(:all) do @t = ICU::Tournament.new('World Championship', '1972-07-11') @t.add_player(ICU::Player.new('Robert J.', 'Fischer', 1)) @t.add_player(ICU::Player.new('Boris V.', 'Spassky', 2)) @t.add_result(ICU::Result.new(1, 1, 'L', :opponent => 2, :colour => 'B')) @t.add_result(ICU::Result.new(2, 1, 'L', :opponent => 2, :colour => 'W', :rateable => false)) @t.add_result(ICU::Result.new(3, 1, 'W', :opponent => 2, :colour => 'B')) @t.add_result(ICU::Result.new(4, 1, 'D', :opponent => 2, :colour => 'W')) serializer = ICU::Tournament::Krause.new @k = serializer.serialize(@t) end it "should produce a valid tournament" do @t.invalid.should be_false end it "should produce output that looks reasonable" do @k.should match(/Fischer,Robert J\./) end end context "serialisation" do before(:each) do @krause = < true) t.serialize('Krause', :fide => true).should == @krause t.serialize('Krause').should_not == @krause end it "should not serialize coorectly if mixed ID types are used" do t = @p.parse!(@krause, :fide => true) t.serialize('Krause').should_not == @krause end it "should serialize coorectly if FIDE IDs are used consistently" do t = @p.parse!(@krause, :fide => true) t.serialize('Krause', :fide => true).should == @krause end end context "auto-ranking" do before(:all) do @krause = < 2501171, :fide => nil) check_player(2, 'Mark', 'Orr', :id => 2500035, :fide => nil) check_player(3, 'Viktor', 'Bologan', :id => nil, :fide => nil) end it "should have FIDE IDs if option is used" do @t = @p.parse(@krause, :fide => true) check_player(1, 'Gearoidin', 'Ui Laighleis', :fide => 2501171, :id => nil) check_player(2, 'Mark', 'Orr', :fide => 2500035, :id => nil) check_player(3, 'Viktor', 'Bologan', :fide => nil, :id => nil) end end context "renumbering" do before(:all) do @krause = < 1985, :id => 2501171, :dob => '1964-06-10', :fed => 'IRL', :gender => 'f')) @t.add_player(ICU::Player.new('Mark', 'Orr', 2, :rating => 2258, :id => 2500035, :dob => '1955-11-09', :fed => 'IRL', :title => 'm')) @t.add_player(ICU::Player.new('Viktor', 'Bologan', 3, :rating => 2663, :id => 13900048, :dob => '1971-01-01', :fed => 'MDA', :title => 'g')) @t.add_result(ICU::Result.new(1, 1, 'L', :opponent => 2, :colour => 'B')) @t.add_result(ICU::Result.new(2, 1, 'W', :opponent => 3, :colour => 'W')) @t.add_result(ICU::Result.new(3, 2, 'W', :opponent => 3, :colour => 'B')) @output = @p.serialize(@t) end it "should serialise" do @output.should == @krause end end context "errors" do before(:each) do @k = <