OSDN Git Service

Getting an absolute location of this file was wrong if it was a synbolic link. This...
[shogi-server/shogi-server.git] / test / TC_rating.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 load 'mk_rate'
3 require 'test/unit'
4
5 class RatingTest < Test::Unit::TestCase
6   def test_rating1
7     wl = GSL::Matrix[[0,3,9],
8                 [1,0,3],
9                 [1,1,0]]
10     rating = Rating.new(wl)
11     rating.rating
12     rating.average!
13     rating.integer!
14     assert( rating.rate[0] > rating.rate[1])
15     assert( rating.rate[1] > rating.rate[2])
16   end
17
18   def test_rating2
19     wl = GSL::Matrix[ # \e$B=54)>-4}\e(B2001\e$BG/\e(B9\e$B7n\e(B12\e$BF|9f$N%G!<%?\e(B
20       [  0,  59,  52,  39,  29,  12],    # \e$BL>?M$*$h$S\e(BA\e$B5i\e(B
21       [ 40,   0,  37,  29,  27,  10],    # B\e$B5i\e(B1\e$BAH\e(B
22       [ 33,  35,   0,  50,  92,  41],    # B\e$B5i\e(B2\e$BAH\e(B
23       [ 21,  19,  51,   0, 140,  80],    # C\e$B5i\e(B1\e$BAH\e(B
24       [  5,  21,  82, 103,   0, 124],    # C\e$B5i\e(B2\e$BAH\e(B
25       [  2,   6,   9,  34,  44,   0],    # \e$B%U%j!<%/%i%9\e(B
26     ]
27     rating = Rating.new(wl)
28     assert_nothing_raised {rating.rating}
29     rating.integer!
30     p1, p2, p3, p4, p5, p6 = rating.rate.to_a
31     assert(p1 > p2)
32     assert(p2 > p3)
33     assert(p3 > p4)
34     assert(p4 > p5)
35     assert(p5 > p6)
36   end
37
38   def test_rating3
39     wl = GSL::Matrix[[0, 3, 18], 
40                 [1, 0, 14], 
41                 [10, 39, 0]]
42     rating = Rating.new(wl)
43     assert_nothing_raised {rating.rating}
44     rating.integer!
45     p1, p2, p3 = rating.rate.to_a
46     assert( p1 > p2 )
47     assert( p3 > p2 )
48   end
49
50   def test_rank2
51     wl = GSL::Matrix[[0, 3],
52                 [1, 0]]
53     rating = Rating.new(wl)
54     rating.rating
55     p1 = rating.rate[0]
56     p2 = rating.rate[1]
57     rating.integer!
58     assert( (180..200).include?(p1 - p2), rating.rate.to_a.inspect )
59   end
60
61   def test_rank3
62     wl = GSL::Matrix[[0, 30, 0],
63                 [10, 0, 30],
64                 [0, 10, 0]]
65     rating = Rating.new(wl)
66     rating.rating
67     rating.average!
68     rating.integer!
69     p1 = rating.rate[0]
70     p2 = rating.rate[1]
71     rating.integer!
72     assert( rating.rate[0] > rating.rate[1])
73     assert( rating.rate[1] > rating.rate[2])
74   end
75 end
76
77
78 class TestWinLossMatrix < Test::Unit::TestCase
79   def setup
80     keys = ['a', 'b', 'c']
81     win_loss = GSL::Matrix[[0,2,3],[1,0,1],[1,1,0]]
82     @matrix = WinLossMatrix.new(keys, win_loss)
83   end
84     
85   def test_delete_rows
86     $deleted = []
87     result = @matrix.delete_rows([0])
88     assert_equal(["b", "c"], result.keys)
89     assert_equal(GSL::Matrix[[0,1],[1,0]], result.matrix)
90
91     result = @matrix.delete_rows([0,2])
92     assert_equal(["b"], result.keys)
93     assert_equal(GSL::Matrix[[0]], result.matrix)
94   end
95
96   def test_connected_subsets
97     array = %w!
98       0  0  0  0  0  2  9 74  0  0  0
99       0  0  0  0 21  0  0  0  0  0  0
100       0  0  0  0 19  0  0  0  0  0  0
101       0  0  0  0 13  0  0  0  0  0  0
102       0 19 20 27  0  0  0  0  0  0  0
103       1  0  0  0  0  0  0  0  0  0  5
104       1  0  0  0  0  0  0  0  0  0  9
105       5  0  0  0  0  0  0  0  0  0  0
106       0  0  0  0  0  0  0  0  0  0  6
107       0  0  0  0  0  0  0  0  0  0  1
108       0  0  0  0  0  1  1  0 28  1  0!.map{|v| v.to_i}
109     keys = ["gps+11648e4e66e7ed6a86cb7f1d0cf604fe", 
110             "gps1_wPrBn_hand+cf51828e1e4351eea9a70e754b8e5edc",
111             "gps1_wPrBn_simple+d6c7d5e4acfb4a21072824d3be07c6dc",
112             "gps1_woPrBn+ea563881afd2e56d3dd715538d2da850",
113             "gps2_wPrBn_mem+dbd8165c47a193b7e76fa9adb3b4e445",
114             "gps32+aa0ba6bfbd84caa7ef1cda34562ce90c",
115             "gps500+0706915e56798d393c9aec4749789b2f",
116             "guest+068b4eb12b042a72e1c7791344175d82",
117             "guest+471a3f6aea2804130b5b967e8a42ea3c",
118             "kaneko+4cee2e6a81fea84316b13626e705e431",
119             "yowai_gps+95908f6c18338f5340371f71523fc5e3"]
120     win_loss = GSL::Matrix.alloc(array, 11, 11)
121     obj = WinLossMatrix.new(keys, win_loss)
122     objs = obj.connected_subsets
123     assert_equal(2, objs.size)
124   end
125 end
126
127 # vim: ts=2 sw=2 sts=0
128