1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2021-01-28 17:08:57 +01:00
parent 1b377b32c8
commit 2e32b919b4
35 changed files with 832 additions and 10 deletions

View file

@ -117,6 +117,48 @@ describe "Kernel.rand" do
end
end
context "given an inclusive range between 0 and 1" do
it "returns an Integer between the two Integers" do
x = rand(0..1)
x.should be_kind_of(Integer)
(0..1).should include(x)
end
it "returns a Float if at least one side is Float" do
seed = 42
x1 = Random.new(seed).rand(0..1.0)
x2 = Random.new(seed).rand(0.0..1.0)
x3 = Random.new(seed).rand(0.0..1)
x3.should be_kind_of(Float)
x1.should equal(x3)
x2.should equal(x3)
(0.0..1.0).should include(x3)
end
end
context "given an exclusive range between 0 and 1" do
it "returns zero as an Integer" do
x = rand(0...1)
x.should be_kind_of(Integer)
x.should eql(0)
end
it "returns a Float if at least one side is Float" do
seed = 42
x1 = Random.new(seed).rand(0...1.0)
x2 = Random.new(seed).rand(0.0...1.0)
x3 = Random.new(seed).rand(0.0...1)
x3.should be_kind_of(Float)
x1.should equal(x3)
x2.should equal(x3)
(0.0...1.0).should include(x3)
end
end
it "returns a numeric for an range argument where max is < 1" do
rand(0.25..0.75).should be_kind_of(Numeric)
end