OSDN Git Service

Fix #36821: Allow to customize maximum lenght of a login indentifier
[shogi-server/shogi-server.git] / test / TC_util.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 $topdir = File.expand_path File.dirname(__FILE__)
3 require 'test/unit'
4 require 'shogi_server/util'
5
6 class TestShogiServer < Test::Unit::TestCase
7
8   def test_datetime2time
9     now = DateTime.new(2010, 6, 10, 21, 20, 15) # Thu
10
11     assert_instance_of Time, ShogiServer::datetime2time(now) 
12     assert_equal Time.mktime(2010, 6, 10, 21, 20, 15), ShogiServer::datetime2time(now) 
13   end
14
15   def test_time2datetime
16     now = Time.mktime(2010, 6, 10, 21, 20, 15)
17     assert_instance_of DateTime, ShogiServer::time2datetime(now)
18     assert_equal DateTime.new(2010, 6, 10, 21, 20, 15), ShogiServer::time2datetime(now)
19   end
20
21   def test_parse_dow
22     assert_equal 7, ShogiServer.parse_dow("Sun")
23     assert_equal 1, ShogiServer.parse_dow("Mon")
24     assert_equal 2, ShogiServer.parse_dow("Tue")
25     assert_equal 3, ShogiServer.parse_dow("Wed")
26     assert_equal 4, ShogiServer.parse_dow("Thu")
27     assert_equal 5, ShogiServer.parse_dow("Fri")
28     assert_equal 6, ShogiServer.parse_dow("Sat")
29     assert_equal 7, ShogiServer.parse_dow("Sunday")
30     assert_equal 1, ShogiServer.parse_dow("Monday")
31     assert_equal 2, ShogiServer.parse_dow("Tuesday")
32     assert_equal 3, ShogiServer.parse_dow("Wednesday")
33     assert_equal 4, ShogiServer.parse_dow("Thursday")
34     assert_equal 5, ShogiServer.parse_dow("Friday")
35     assert_equal 6, ShogiServer.parse_dow("Saturday")
36   end
37
38 end
39
40
41 class TestMkdir < Test::Unit::TestCase
42   def setup
43     @test_dir = File.join($topdir, "hoge", "hoo", "foo.txt")
44   end
45
46   def teardown
47     if FileTest.directory?(File.dirname(@test_dir))
48       Dir.rmdir(File.dirname(@test_dir))
49       Dir.rmdir(File.join($topdir, "hoge"))
50     end
51   end
52
53   def test_mkdir_for
54     assert !FileTest.directory?(File.dirname(@test_dir))
55     ShogiServer::Mkdir.mkdir_for(@test_dir)
56     assert FileTest.directory?(File.dirname(@test_dir))
57   end
58
59   def test_dirname
60     assert_equal "/hoge", File.dirname("/hoge/foo")
61   end
62
63 end
64
65 class TestFactorial < Test::Unit::TestCase
66   def test_factorial
67     assert_equal 1, ShogiServer::factorial(0)
68     assert_equal 1, ShogiServer::factorial(1)
69     assert_equal 2, ShogiServer::factorial(2)
70     assert_equal 6, ShogiServer::factorial(3)
71   end
72 end
73
74 class TestnCk < Test::Unit::TestCase
75   def test_nCk
76     assert_equal 0, ShogiServer::nCk(2,5)
77     assert_equal 1, ShogiServer::nCk(2,2)
78     assert_equal 6, ShogiServer::nCk(4,2)
79     assert_equal 11*5*9, ShogiServer::nCk(12,4)
80   end
81 end
82