OSDN Git Service

Merge branch '201312-KinPenalty' into wdoor-stable
[shogi-server/shogi-server.git] / test / TC_league.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 require 'test/unit'
3 require 'fileutils'
4 require 'shogi_server'
5 require 'shogi_server/player'
6 require 'shogi_server/league'
7
8 class TestPersistent < Test::Unit::TestCase
9   def setup
10     @filename = File.join(".", "test.yaml")
11     if File.exists?(@filename)
12       FileUtils.rm(@filename)
13     end
14     @persistent = ShogiServer::League::Persistent.new(@filename)
15     @p = ShogiServer::BasicPlayer.new
16     @p.name = "gps_normal"
17     @p.player_id = "gps_normal_dummy_id"
18   end
19
20   def test_empty_yaml
21     count = 0
22     @persistent.each_group do |group, players|
23       count += 1
24     end
25     assert_equal(count, 0)
26     FileUtils.rm(@filename)
27     count = 0
28     @persistent.each_group do |group, players|
29       count += 1
30     end
31     assert_equal(count, 0)
32   end
33
34   def test_load_player
35     filename = File.join(".", "players.yaml")
36     persistent = ShogiServer::League::Persistent.new(filename)
37     p = ShogiServer::BasicPlayer.new
38     p.player_id = "gps_normal+e293220e3f8a3e59f79f6b0efffaa931"
39     persistent.load_player(p)
40
41     assert_equal(p.name, "gps_normal")
42     assert_in_delta(p.rate, -1752.0, 0.1)
43     assert_equal(p.modified_at.ctime, "Thu May  8 23:50:54 2008")
44     assert_equal(p.rating_group, 0)
45     assert_in_delta(p.win, 3384.04877829976,  0.00001)
46     assert_in_delta(p.loss, 906.949084230512, 0.00001)
47   end
48
49   def test_get_players
50     filename = File.join(".", "players.yaml")
51     persistent = ShogiServer::League::Persistent.new(filename)
52     players = persistent.get_players
53     assert_equal(players.size, 295)
54   end
55 end
56
57
58 class TestLeague < Test::Unit::TestCase
59   def setup
60     @league = ShogiServer::League.new
61     @league.dir = "."
62     @league.setup_players_database
63
64     @p = ShogiServer::BasicPlayer.new
65     @p.name = "test_name"
66   end
67
68   def teardown
69   end
70
71   def test_add_player
72     assert(!@league.find(@p.name))
73     @league.add(@p)
74     assert(@league.find(@p.name))
75     @league.delete(@p)
76     assert(!@league.find(@p.name))
77   end
78
79   def test_reload
80     @league.reload
81     assert(true)
82   end
83 end