Created
August 9, 2012 10:37
-
-
Save a2ikm/3303116 to your computer and use it in GitHub Desktop.
rspec
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
shared_examples_for "hogehoge" do | |
it "should be_valid" do | |
check_count = 10 | |
check_count.times do | |
sample_count = 1000 | |
counts = {1 => 0, 2 => 0} | |
sample_count.times do | |
counts[xxx[:id]] += 1 | |
end | |
(counts[1] < counts[2]).should be_true | |
(counts[1] + counts[2]).should == sample_count | |
end | |
end | |
end | |
context "normal" do | |
let(:a) { [{id: 1, weight:1}, {id:2, weight: 3}, {id:3, weight:nil}] } | |
let(:xxx) { a.sample_with_weight } | |
it_should_behave_like "hogehoge" | |
end | |
context "weightを取る属性名を指定" do | |
let(:a) { [{id: 1, hoge_weight:1}, {id:2, hoge_weight: 2}] } | |
let(:xxx) { a.sample_with_weight(:hoge_weight) } | |
it_should_behave_like "hogehoge" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment