OSDN Git Service

Fix Dockerfile
[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   end
14 end
15
16 class TestGameResult < Test::Unit::TestCase
17   class DummyGame
18     attr_accessor :game_name
19   end
20
21   def setup
22     @p1 = ShogiServer::BasicPlayer.new
23     @p1.sente = true
24     @p2 = ShogiServer::BasicPlayer.new
25     @p2.sente = false
26     @game = DummyGame.new
27   end
28
29   def test_game_result_win
30     gr = ShogiServer::GameResultWin.new(@game, @p1, @p2)
31     assert_equal(@p1.last_game_win, true)
32     assert_equal(@p2.last_game_win, false)
33     assert_equal(nil, gr.log_summary_type)
34   end
35
36   def test_game_result_abnormal_win
37     gr = ShogiServer::GameResultAbnormalWin.new(@game, @p1, @p2)
38     assert_equal(@p1.last_game_win, true)
39     assert_equal(@p2.last_game_win, false)
40     assert_equal("abnormal", gr.log_summary_type)
41   end
42
43   def test_game_result_kachi_win
44     gr = ShogiServer::GameResultKachiWin.new(@game, @p1, @p2)
45     assert_equal(@p1.last_game_win, true)
46     assert_equal(@p2.last_game_win, false)
47     assert_equal("kachi", gr.log_summary_type)
48   end
49
50   def test_game_result_illegal_kachi_win
51     gr = ShogiServer::GameResultIllegalKachiWin.new(@game, @p1, @p2)
52     assert_equal(@p1.last_game_win, true)
53     assert_equal(@p2.last_game_win, false)
54     assert_equal("illegal kachi", gr.log_summary_type)
55   end
56
57   def test_game_result_illegal_move_win
58     gr = ShogiServer::GameResultIllegalMoveWin.new(@game, @p1, @p2)
59     assert_equal(@p1.last_game_win, true)
60     assert_equal(@p2.last_game_win, false)
61     assert_equal("illegal move", gr.log_summary_type)
62   end
63
64   def test_game_result_uchifuzume_win
65     gr = ShogiServer::GameResultUchifuzumeWin.new(@game, @p1, @p2)
66     assert_equal(@p1.last_game_win, true)
67     assert_equal(@p2.last_game_win, false)
68     assert_equal("uchifuzume", gr.log_summary_type)
69   end
70
71   def test_game_result_oute_kaihi_more_win
72     gr = ShogiServer::GameResultOuteKaihiMoreWin.new(@game, @p1, @p2)
73     assert_equal(@p1.last_game_win, true)
74     assert_equal(@p2.last_game_win, false)
75     assert_equal("oute_kaihimore", gr.log_summary_type)
76   end
77
78   def test_game_result_outori_win
79     gr = ShogiServer::GameResultOutoriWin.new(@game, @p1, @p2)
80     assert_equal(@p1.last_game_win, true)
81     assert_equal(@p2.last_game_win, false)
82     assert_equal("outori", gr.log_summary_type)
83   end
84
85   def test_game_result_toryo_win
86     gr = ShogiServer::GameResultToryoWin.new(@game, @p1, @p2)
87     assert_equal(@p1.last_game_win, true)
88     assert_equal(@p2.last_game_win, false)
89     assert_equal("toryo", gr.log_summary_type)
90   end
91
92   def test_game_result_oute_sennichite_win
93     gr = ShogiServer::GameResultOuteSennichiteWin.new(@game, @p1, @p2)
94     assert_equal(@p1.last_game_win, true)
95     assert_equal(@p2.last_game_win, false)
96     assert_equal("oute_sennichite", gr.log_summary_type)
97   end
98
99   def test_game_result_draw
100     gr = ShogiServer::GameResultDraw.new(@game, @p1, @p2)
101     assert_equal(@p1.last_game_win, false)
102     assert_equal(@p2.last_game_win, false)
103     assert_equal(nil, gr.log_summary_type)
104   end
105
106   def test_game_result_sennichite_draw
107     gr = ShogiServer::GameResultSennichiteDraw.new(@game, @p1, @p2)
108     assert_equal(@p1.last_game_win, false)
109     assert_equal(@p2.last_game_win, false)
110     assert_equal("sennichite", gr.log_summary_type)
111   end
112
113 end
114