-
Notifications
You must be signed in to change notification settings - Fork 0
/
thompson-test.rb
58 lines (57 loc) · 3.07 KB
/
thompson-test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
require 'test/unit'
require 'thompson.rb'
class ThompsonTest < Test::Unit::TestCase
def test_a()
scenario_list = [
[[[10000,100,20.0], [10000,100,20.0]], [0,0], '同じ比率'],
[[[10000,100,20.0], [10000,50,40.0]], [-1,1], '同じeCPM、異なるCPC'],
[[[10000,100,20.0], [10000,100,10.0]], [1,-1], '異なるeCPM'],
[[[100,1,0.1], [100,1,0.1]], [0,0], '同じ比率'],
[[[100,1,0.1], [100,2,0.05]], [1,-1], '同じeCPM, CPCは半分'],
[[[100,1,0.1], [100,1,0.05]], [1,-1], '異なるeCPM'],
[[[100,1,0.1], [100,0,0.0]], [1,-1], '0-click, CPCは0'],
[[[100,1,0.1], [100,0,0.1]], [1,-1], '0-click, CPCは非0(最小)'],
[[[100,1,0.1], [10,0,0.1]], [-1,1], '0-click, CPCは非0(最小)でインプが少ない'],
# 3つ以上の複数
[[[10000,100,20.0], [10000,100,20.0], [10000,100,20.0]], [0,0,0], '複数同じ'],
[[[10000,100,20.0], [10000,100,20.0], [10000,50,40.0]], [-1,-1,1], '複数eCPMが同じ'],
[[[10000,100,20.0], [10000,100,20.0], [10000,100,10.0]], [1,1,-1], '異なるeCPM'],
# よくありそうな
[[[1000,100,1.0], [10,1,1.0]], [-1,1], '探索か利益追求か(eCPMが同じ)'],
[[[1000,10,1.0], [100,1,1.0]], [-1,1], '探索か利益追求か(eCPMが同じ)'],
[[[10000,100,2.0], [50,1,1.0]], [-1,1], '探索か利益追求か(eCPMが同じ, クリックが1)'],
[[[10000,100,2.0], [50,0,1.0]], [1,-1], '探索か利益追求か(eCPMが半分, クリックが0)'],
[[[10000,100,2.0], [100,1,1.0]], [1,-1], '探索か利益追求か(eCPMが半分)'],
[[[10000,100,2.0], [200,2,1.0]], [1,-1], '探索か利益追求か(eCPMが半分)'],
[[[10000,100,2.0], [500,5,1.0]], [1,-1], '探索か利益追求か(eCPMが半分)'],
[[[10000,100,2.0], [1000,10,1.0]], [1,-1], '探索か利益追求か(eCPMが半分)'],
[[[10000,100,2.0], [2000,20,1.0]], [1,-1], '探索か利益追求か(eCPMが半分)'],
];
scenario_list.each do |scenario|
arms, assertions, comment = scenario
ratios = thompson(arms,10000);
print arms.map{|e|e.join('/')}.join(':')
print " ";
print ratios.join(':')
print " ";
print assertions.join(':')
print " # #{comment}.\n";
average = arms.size;
ratios.each.with_index do |ratio,id|
case assertions[id]
when 0
assert(0.95/average < ratio, '大きすぎ');
assert(1.05/average > ratio, '小さすぎ');
when 1
assert(1.0/average < ratio, '大きすぎ');
when -1
assert(1.0/average > ratio, '小さすぎ');
else
raise 'ないよ'
end # case
end # each
end # each
end # def
end # class