X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=blobdiff_plain;f=test%2FTC_board.rb;h=6008af5c05b31dadf25b6dfb4ad62cc554c08005;hp=f55a83c8e60d4a08a74b0ab5fa8da00ddb4a0789;hb=d42dec0ac3d93f262e441e7fc9fc9bacc71c5c52;hpb=e4189dd168a34df5460f782b824104d82276db96 diff --git a/test/TC_board.rb b/test/TC_board.rb index f55a83c..6008af5 100644 --- a/test/TC_board.rb +++ b/test/TC_board.rb @@ -5,99 +5,6 @@ require 'shogi_server' require 'shogi_server/board' require 'shogi_server/piece' -module ShogiServer -class Board - def set_from_str(strs) - strs.split(/\n/).each do |str| - if (str =~ /^P\d/) - str.sub!(/^P(.)/, '') - y = $1.to_i - x = 9 - while (str.length > 2) - str.sub!(/^(...?)/, '') - one = $1 - if (one =~ /^([\+\-])(..)/) - sg = $1 - name = $2 - if (sg == "+") - sente = true - else - sente = false - end - if ((x < 1) || (9 < x) || (y < 1) || (9 < y)) - raise "bad position #{x} #{y}" - end - case (name) - when "FU" - PieceFU::new(self, x, y, sente) - when "KY" - PieceKY::new(self, x, y, sente) - when "KE" - PieceKE::new(self, x, y, sente) - when "GI" - PieceGI::new(self, x, y, sente) - when "KI" - PieceKI::new(self, x, y, sente) - when "OU" - PieceOU::new(self, x, y, sente) - when "KA" - PieceKA::new(self, x, y, sente) - when "HI" - PieceHI::new(self, x, y, sente) - when "TO" - PieceFU::new(self, x, y, sente, true) - when "NY" - PieceKY::new(self, x, y, sente, true) - when "NK" - PieceKE::new(self, x, y, sente, true) - when "NG" - PieceGI::new(self, x, y, sente, true) - when "UM" - PieceKA::new(self, x, y, sente, true) - when "RY" - PieceHI::new(self, x, y, sente, true) - else - raise "unkown piece #{name}" - end - end - x = x - 1 - end - elsif (str =~ /^P([\+\-])/) - sg = $1 - if (sg == "+") - sente = true - else - sente = false - end - str.sub!(/^../, '') - while (str.length > 3) - str.sub!(/^..(..)/, '') - name = $1 - case (name) - when "FU" - PieceFU::new(self, 0, 0, sente) - when "KY" - PieceKY::new(self, 0, 0, sente) - when "KE" - PieceKE::new(self, 0, 0, sente) - when "GI" - PieceGI::new(self, 0, 0, sente) - when "KI" - PieceKI::new(self, 0, 0, sente) - when "KA" - PieceKA::new(self, 0, 0, sente) - when "HI" - PieceHI::new(self, 0, 0, sente) - else - raise "unkown piece #{name}" - end - end - end - end - end -end -end - class Test_kachi < Test::Unit::TestCase def test_kachi_good b = ShogiServer::Board.new @@ -778,3 +685,75 @@ EOM assert_equal(false, b.uchifuzume?(true)) end end + +class TestBoardForBuoy < Test::Unit::TestCase + def setup + @board = ShogiServer::Board.new + end + + def test_set_from_moves_empty + moves = [] + rt = @board.set_from_moves moves + assert_equal(:normal, rt) + end + + def test_set_from_moves + moves = ["+7776FU", "-3334FU"] + assert_nothing_raised do + @board.set_from_moves moves + end + + correct = ShogiServer::Board.new + correct.set_from_str <