OSDN Git Service

Merge branch '201312-KinPenalty' into wdoor-stable
[shogi-server/shogi-server.git] / test / TC_floodgate_history.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 require 'test/unit'
3 require 'yaml'
4 require 'shogi_server'
5 require 'shogi_server/player'
6 require 'shogi_server/league/floodgate'
7
8 $league = ShogiServer::League.new(File.dirname(__FILE__))
9 $league.event = "TC_floodgate_history"
10
11 class MockGame
12   attr_accessor :game_id, :game_name
13
14   def regist_observers
15     # do nothing
16   end
17 end
18
19 class MockPlayer < ShogiServer::BasicPlayer
20   attr_accessor :status
21 end
22
23 class TestHistory < Test::Unit::TestCase
24   def setup
25     @orig_logger = $logger
26     $logger ||= Logger.new(STDERR)
27   end
28
29   def teardown
30     $logger = @orig_logger
31   end
32
33   def removed_file
34     file = Pathname.new "test_floodgate_history.yaml"
35     if file.exist?
36       file.delete
37     end
38     assert(!file.exist?)
39     return file
40   end
41
42   def test_load_no_file
43     file = removed_file
44
45     history = ShogiServer::League::Floodgate::History.new(file)
46     history.load
47     assert(true)
48   end
49
50   def test_load_empty_file
51     file = removed_file
52
53     file.open("w") {|f| f.write ""}
54     assert(file.exist?)
55
56     history = ShogiServer::League::Floodgate::History.new(file)
57     history.load
58     assert(true)
59
60     a = MockPlayer.new
61     a.name = "a"
62     a.win  = 1
63     a.loss = 2
64     a.rate = 0
65     a.last_game_win = false
66     a.sente = true
67     a.status = ""
68     b = MockPlayer.new
69     b.name = "b"
70     b.win  = 10
71     b.loss = 20
72     b.rate = 1500
73     b.last_game_win = true
74     b.sente = false
75     b.status = ""
76
77     game = MockGame.new
78     game.game_id = "dummy_game_id"
79     game.game_name = "dummy_game_name"
80     
81     gr = ShogiServer::GameResult.new(game, a, b)
82     history.update(gr)
83     assert true
84   end
85 end