OSDN Git Service

Implemented a new command: %%FORK
[shogi-server/shogi-server.git] / test / TC_buoy.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 $topdir = File.expand_path File.dirname(__FILE__)
3 require 'test/unit'
4 require 'shogi_server/buoy'
5 require 'mock_game'
6 require 'mock_player'
7 require 'mock_log_message'
8
9
10 class TestBuoyGame < Test::Unit::TestCase
11   def test_equal
12     g1 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, nil, nil)
13     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, nil, nil)
14     assert_equal g1, g2
15   end
16
17   def test_equal2
18     g1 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, 20)
19     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, 20)
20     assert_equal g1, g2
21   end
22
23   def test_not_equal
24     g1 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, nil, nil)
25     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 2, nil, nil)
26     assert_not_equal g1, g2
27   end
28
29   def test_not_equal2
30     g1 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, 20)
31     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, 200)
32     assert_not_equal g1, g2
33   end
34
35   def test_not_equal3
36     g1 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, nil)
37     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, 200)
38     assert_not_equal g1, g2
39   end
40 end
41
42
43 class TestBuoy < Test::Unit::TestCase
44   def setup
45     @dir = File.dirname(__FILE__)
46     @filename = File.join(@dir, "buoy.yaml")
47     @conf = {:topdir => @dir}
48     @buoy = ShogiServer::Buoy.new @conf
49   end
50   
51   def teardown
52     if File.exist? @filename
53       File.delete @filename
54     end
55   end
56
57   def test_game_name
58     assert(ShogiServer::Buoy.game_name?("buoy_hoge-1500-0"))
59     assert(ShogiServer::Buoy.game_name?("buoy_hoge-900-0"))
60     assert(ShogiServer::Buoy.game_name?("buoy_hoge-0-30"))
61     assert(!ShogiServer::Buoy.game_name?("buoyhoge-1500-0"))
62     assert(!ShogiServer::Buoy.game_name?("hoge-1500-0"))
63   end 
64
65   def test_is_new_game1
66     assert @buoy.is_new_game?("buoy_123-900-0")
67   end
68
69   def test_add_game
70     game = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, nil, nil)
71     @buoy.add_game(game)
72     assert !@buoy.is_new_game?("buoy_1234-900-0")
73     game2 = @buoy.get_game(game.game_name)
74     assert_equal game, game2
75
76     @buoy.delete_game game
77     assert @buoy.is_new_game?("buoy_1234-900-0")
78   end
79
80   def test_add_game2
81     game = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1, 10, 20)
82     @buoy.add_game(game)
83     assert !@buoy.is_new_game?("buoy_1234-900-0")
84     game2 = @buoy.get_game(game.game_name)
85     assert_equal game, game2
86
87     @buoy.delete_game game
88     assert @buoy.is_new_game?("buoy_1234-900-0")
89   end
90
91   def test_update_game
92     game = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 2, nil, nil)
93     @buoy.add_game(game)
94     g2 = ShogiServer::BuoyGame.new(game.game_name, game.moves, game.owner, game.count-1, nil, nil)
95     @buoy.update_game(g2)
96     
97     get = @buoy.get_game(g2.game_name)
98     assert_equal g2, get
99   end
100 end
101