OSDN Git Service

Improved stability of test results.
[shogi-server/shogi-server.git] / test / TC_usi.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2
3 require 'test/unit'
4 require 'shogi_server'
5 require 'shogi_server/board'
6 require 'shogi_server/piece'
7
8 class TestUsi < Test::Unit::TestCase
9   def setup
10     @usi = ShogiServer::Usi.new
11   end
12
13   def test_hirate
14     hirate_sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL";
15     board = ShogiServer::Board.new
16     assert_equal @usi.parseBoard(hirate_sfen, board), 0
17
18     hirate = ShogiServer::Board.new
19     hirate.initial
20     hirate.teban = nil
21
22     assert_equal hirate.to_s, board.to_s
23   end
24
25   def test_hirate_board
26     board = ShogiServer::Board.new
27     board.initial
28     hirate_sfen         = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b -";
29     hirate_sfen_escaped = "lnsgkgsnl_1r5b1_ppppppppp_9_9_9_PPPPPPPPP_1B5R1_LNSGKGSNL.b.-";
30     assert_equal hirate_sfen, @usi.board2usi(board, board.teban)
31     assert_equal hirate_sfen_escaped, ShogiServer::Usi.escape(@usi.board2usi(board, board.teban))
32   end
33
34   def test_board_with_hands1
35     b = ShogiServer::Board.new
36     b.initial
37     b.set_from_str(<<EOB)
38 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
39 P2 * -HI *  *  *  *  * -KA * 
40 P3-FU-FU-FU-FU-FU-FU-FU-FU *
41 P4 *  *  *  *  *  *  *  *  * 
42 P5 *  *  *  *  *  *  *  *  * 
43 P6 *  *  *  *  *  *  *  *  * 
44 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
45 P8 * +KA *  *  *  *  * +HI * 
46 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
47 P+00FU
48 EOB
49     assert_equal "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b P", @usi.board2usi(b, b.teban)
50   end
51
52   def test_board_with_hands2
53     b = ShogiServer::Board.new
54     b.initial
55     b.set_from_str(<<EOB)
56 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
57 P2 * -HI *  *  *  *  * -KA * 
58 P3-FU-FU-FU-FU-FU-FU-FU-FU *
59 P4 *  *  *  *  *  *  *  *  * 
60 P5 *  *  *  *  *  *  *  *  * 
61 P6 *  *  *  *  *  *  *  *  * 
62 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
63 P8 * +KA *  *  *  *  * +HI * 
64 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
65 P-00FU
66 EOB
67     assert_equal "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b p", @usi.board2usi(b, b.teban)
68   end
69
70   def test_board_with_hands3
71     b = ShogiServer::Board.new
72     b.initial
73     b.set_from_str(<<EOB)
74 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
75 P2 * -HI *  *  *  *  * -KA * 
76 P3-FU-FU-FU-FU-FU-FU-FU *  *
77 P4 *  *  *  *  *  *  *  *  * 
78 P5 *  *  *  *  *  *  *  *  * 
79 P6 *  *  *  *  *  *  *  *  * 
80 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
81 P8 * +KA *  *  *  *  * +HI * 
82 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
83 P-00FU00FU
84 EOB
85     assert_equal "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b 2p", @usi.board2usi(b, b.teban)
86   end
87 end