We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e950baa commit 6ca3dcaCopy full SHA for 6ca3dca
spec/array_spec.rb
@@ -13,11 +13,34 @@
13
14
let(:array) { [1, 2, 3, 4] }
15
subject { array.weighted_sample }
16
+
17
it { should eq 3 }
18
19
+ context "different random" do
20
+ before do
21
+ Kernel.stub(:rand) { 0 }
22
+ end
23
24
+ it { should eq 1 }
25
26
27
28
29
+ Kernel.stub(:rand) { 1 }
30
31
32
+ it { should eq 4 }
33
34
35
context "with weights" do
36
subject { array.weighted_sample([1, 0, 0, 0]) }
37
it { should eq 1 }
38
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
44
45
46
0 commit comments