OSDN Git Service

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