OSDN Git Service

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