Skip to content

Commit 6ca3dca

Browse files
author
Peter de Ruijter
committed
More boundary tests for Array.
1 parent e950baa commit 6ca3dca

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

spec/array_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,34 @@
1313

1414
let(:array) { [1, 2, 3, 4] }
1515
subject { array.weighted_sample }
16+
1617
it { should eq 3 }
1718

19+
context "different random" do
20+
before do
21+
Kernel.stub(:rand) { 0 }
22+
end
23+
24+
it { should eq 1 }
25+
end
26+
27+
context "different random" do
28+
before do
29+
Kernel.stub(:rand) { 1 }
30+
end
31+
32+
it { should eq 4 }
33+
end
34+
1835
context "with weights" do
1936
subject { array.weighted_sample([1, 0, 0, 0]) }
2037
it { should eq 1 }
2138
end
39+
40+
context "all the same weights" do
41+
before { Kernel.stub(:rand) { 1 } }
42+
subject { array.weighted_sample([0, 0, 0, 0]) }
43+
it { should eq 4 }
44+
end
2245
end
2346
end

0 commit comments

Comments
 (0)