OSDN Git Service

[shogi-server] Enhance capability of Floodgate configuration file
[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 'test/mock_game'
6 require 'test/mock_player'
7 require 'test/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)
13     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1)
14     assert_equal g1, g2
15   end
16
17   def test_not_equal
18     g1 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1)
19     g2 = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 2)
20     assert_not_equal g1, g2
21   end
22 end
23
24
25 class TestBuoy < Test::Unit::TestCase
26   def setup
27     @dir = File.dirname(__FILE__)
28     @filename = File.join(@dir, "buoy.yaml")
29     @conf = {:topdir => @dir}
30     @buoy = ShogiServer::Buoy.new @conf
31   end
32   
33   def teardown
34     if File.exist? @filename
35       File.delete @filename
36     end
37   end
38
39   def test_game_name
40     assert(ShogiServer::Buoy.game_name?("buoy_hoge-1500-0"))
41     assert(ShogiServer::Buoy.game_name?("buoy_hoge-900-0"))
42     assert(ShogiServer::Buoy.game_name?("buoy_hoge-0-30"))
43     assert(!ShogiServer::Buoy.game_name?("buoyhoge-1500-0"))
44     assert(!ShogiServer::Buoy.game_name?("hoge-1500-0"))
45   end 
46
47   def test_is_new_game1
48     assert @buoy.is_new_game?("buoy_123-900-0")
49   end
50
51   def test_add_game
52     game = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 1)
53     @buoy.add_game(game)
54     assert !@buoy.is_new_game?("buoy_1234-900-0")
55     game2 = @buoy.get_game(game.game_name)
56     assert_equal game, game2
57
58     @buoy.delete_game game
59     assert @buoy.is_new_game?("buoy_1234-900-0")
60   end
61
62   def test_update_game
63     game = ShogiServer::BuoyGame.new("buoy_1234-900-0", [], "p1", 2)
64     @buoy.add_game(game)
65     g2 = ShogiServer::BuoyGame.new(game.game_name, game.moves, game.owner, game.count-1)
66     @buoy.update_game(g2)
67     
68     get = @buoy.get_game(g2.game_name)
69     assert_equal g2, get
70   end
71 end
72