OSDN Git Service

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