Created
August 9, 2012 10:28
-
-
Save u1tnk/3303071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "normal" do | |
a = [{id: 1, weight:1}, {id:2, weight: 3}, {id:3, weight:nil}] | |
check_count = 10 | |
check_count.times do | |
sample_count = 1000 | |
counts = {1 => 0, 2 => 0} | |
sample_count.times do | |
counts[a.sample_with_weight[:id]] += 1 | |
end | |
(counts[1] < counts[2]).should be_true | |
(counts[1] + counts[2]).should == sample_count | |
end | |
end | |
it "weightを取る属性名を指定" do | |
a = [{id: 1, hoge_weight:1}, {id:2, hoge_weight: 2}] | |
check_count = 10 | |
check_count.times do | |
sample_count = 1000 | |
counts = {1 => 0, 2 => 0} | |
sample_count.times do | |
counts[a.sample_with_weight(:hoge_weight)[:id]] += 1 | |
end | |
(counts[1] < counts[2]).should be_true | |
(counts[1] + counts[2]).should == sample_count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment