OSDN Git Service

Merge remote-tracking branch 'origin/master'
[shogi-server/shogi-server.git] / test / TC_game_result.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2
3 require 'test/unit'
4 require 'shogi_server'
5 require 'shogi_server/game'
6
7 $league = ShogiServer::League.new(File.dirname(__FILE__))
8 $league.event = "TC_game_result"
9
10 module ShogiServer
11   class BasicPlayer
12     attr_accessor :sente, :status
13
14     def write_safe(dummy)
15     end
16   end
17 end
18
19 class TestGameResult < Test::Unit::TestCase
20   class DummyGame
21     attr_accessor :game_name
22     attr_reader :board
23
24     def initialize
25       @board = ""
26     end
27   end
28
29   def setup
30     @p1 = ShogiServer::BasicPlayer.new
31     @p1.sente = true
32     @p2 = ShogiServer::BasicPlayer.new
33     @p2.sente = false
34     @game = DummyGame.new
35   end
36
37   def test_game_result_win
38     gr = ShogiServer::GameResultWin.new(@game, @p1, @p2)
39     assert_equal(@p1.last_game_win, true)
40     assert_equal(@p2.last_game_win, false)
41     assert_equal(nil, gr.log_summary_type)
42   end
43
44   def test_game_result_abnormal_win
45     gr = ShogiServer::GameResultAbnormalWin.new(@game, @p1, @p2)
46     assert_equal(@p1.last_game_win, true)
47     assert_equal(@p2.last_game_win, false)
48     assert_equal("abnormal", gr.log_summary_type)
49   end
50
51   def test_game_result_kachi_win
52     gr = ShogiServer::GameResultKachiWin.new(@game, @p1, @p2)
53     assert_equal(@p1.last_game_win, true)
54     assert_equal(@p2.last_game_win, false)
55     assert_equal("kachi", gr.log_summary_type)
56   end
57
58   def test_game_result_illegal_kachi_win
59     gr = ShogiServer::GameResultIllegalKachiWin.new(@game, @p1, @p2)
60     assert_equal(@p1.last_game_win, true)
61     assert_equal(@p2.last_game_win, false)
62     assert_equal("illegal kachi", gr.log_summary_type)
63   end
64
65   def test_game_result_illegal_move_win
66     gr = ShogiServer::GameResultIllegalMoveWin.new(@game, @p1, @p2)
67     assert_equal(@p1.last_game_win, true)
68     assert_equal(@p2.last_game_win, false)
69     assert_equal("illegal move", gr.log_summary_type)
70   end
71
72   def test_game_result_uchifuzume_win
73     gr = ShogiServer::GameResultUchifuzumeWin.new(@game, @p1, @p2)
74     assert_equal(@p1.last_game_win, true)
75     assert_equal(@p2.last_game_win, false)
76     assert_equal("uchifuzume", gr.log_summary_type)
77   end
78
79   def test_game_result_oute_kaihi_more_win
80     gr = ShogiServer::GameResultOuteKaihiMoreWin.new(@game, @p1, @p2)
81     assert_equal(@p1.last_game_win, true)
82     assert_equal(@p2.last_game_win, false)
83     assert_equal("oute_kaihimore", gr.log_summary_type)
84   end
85
86   def test_game_result_outori_win
87     gr = ShogiServer::GameResultOutoriWin.new(@game, @p1, @p2)
88     assert_equal(@p1.last_game_win, true)
89     assert_equal(@p2.last_game_win, false)
90     assert_equal("outori", gr.log_summary_type)
91   end
92
93   def test_game_result_toryo_win
94     gr = ShogiServer::GameResultToryoWin.new(@game, @p1, @p2)
95     assert_equal(@p1.last_game_win, true)
96     assert_equal(@p2.last_game_win, false)
97     assert_equal("toryo", gr.log_summary_type)
98   end
99
100   def test_game_result_oute_sennichite_win
101     gr = ShogiServer::GameResultOuteSennichiteWin.new(@game, @p1, @p2)
102     assert_equal(@p1.last_game_win, true)
103     assert_equal(@p2.last_game_win, false)
104     assert_equal("oute_sennichite", gr.log_summary_type)
105   end
106
107   def test_game_result_draw
108     gr = ShogiServer::GameResultDraw.new(@game, @p1, @p2)
109     assert_equal(@p1.last_game_win, false)
110     assert_equal(@p2.last_game_win, false)
111     assert_equal(nil, gr.log_summary_type)
112   end
113
114   def test_game_result_sennichite_draw
115     gr = ShogiServer::GameResultSennichiteDraw.new(@game, @p1, @p2)
116     $cache_state = []
117     def gr.log(s)
118       $cache_state << s
119     end
120     assert_equal(@p1.last_game_win, false)
121     assert_equal(@p2.last_game_win, false)
122     assert_equal("sennichite", gr.log_summary_type)
123
124     gr.delete_observers
125     gr.process
126     assert_equal("%SENNICHITE", $cache_state[0])
127   end
128
129   def test_game_result_timeout
130     gr = ShogiServer::GameResultTimeoutWin.new(@game, @p2, @p1)
131     $cache_state = []
132     def gr.log(s)
133       $cache_state << s
134     end
135     gr.delete_observers
136     gr.process
137     assert_equal("%TIME_UP", $cache_state[0])
138   end
139 end
140