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 2019-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -1,4 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Random.rand" do
it "returns a Float if no max argument is passed" do
@ -83,13 +84,13 @@ describe "Random#rand with Fixnum" do
end
it "raises an ArgumentError when the argument is 0" do
lambda do
-> do
Random.new.rand(0)
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the argument is negative" do
lambda do
-> do
Random.new.rand(-12)
end.should raise_error(ArgumentError)
end
@ -122,7 +123,7 @@ describe "Random#rand with Bignum" do
end
it "raises an ArgumentError when the argument is negative" do
lambda do
-> do
Random.new.rand(-bignum_value)
end.should raise_error(ArgumentError)
end
@ -154,7 +155,7 @@ describe "Random#rand with Float" do
end
it "raises an ArgumentError when the argument is negative" do
lambda do
-> do
Random.new.rand(-1.234567)
end.should raise_error(ArgumentError)
end
@ -165,6 +166,12 @@ describe "Random#rand with Range" do
Random.new.rand(20..43).should be_an_instance_of(Fixnum)
end
it "supports custom object types" do
rand(RandomSpecs::CustomRangeInteger.new(1)..RandomSpecs::CustomRangeInteger.new(42)).should be_an_instance_of(RandomSpecs::CustomRangeInteger)
rand(RandomSpecs::CustomRangeFloat.new(1.0)..RandomSpecs::CustomRangeFloat.new(42.0)).should be_an_instance_of(RandomSpecs::CustomRangeFloat)
rand(Time.now..Time.now).should be_an_instance_of(Time)
end
it "returns an object that is a member of the Range" do
prng = Random.new
r = 20..30
@ -203,13 +210,13 @@ describe "Random#rand with Range" do
end
it "raises an ArgumentError when the startpoint lacks #+ and #- methods" do
lambda do
-> do
Random.new.rand(Object.new..67)
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError when the endpoint lacks #+ and #- methods" do
lambda do
-> do
Random.new.rand(68..Object.new)
end.should raise_error(ArgumentError)
end