diff options
author | Nobuyoshi Nakada <[email protected]> | 2025-02-02 20:59:59 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2025-02-02 20:59:59 +0900 |
commit | 571f3394f2b8ac312e0e6213c639a44cf7e29fe4 () | |
tree | 2dab89f87cf65ac1a0787caf87a5716c860a9860 | |
parent | 8dd0d63550c4da2ba7939f371f73825caa2e932e (diff) |
[Bug #21106] Fix tests for custom random object
When a positive integer limit is given, `rand` method of a RNG object is expected to return a value between 0 and the limit (exclusive). Fix shuffle_spec.rb like as the similar code in sample_spec.rb, and add tests for greater values. TODO: - Return a value that is equal to or greater than the limit given to the RNG object. - Extract common code about RNG objects to a shared file.
Notes: Merged: https://.com/ruby/ruby/pull/12690
-rw-r--r-- | spec/ruby/core/array/sample_spec.rb | 7 | ||||
-rw-r--r-- | spec/ruby/core/array/shuffle_spec.rb | 13 |
2 files changed, 18 insertions, 2 deletions
@@ -114,6 +114,13 @@ describe "Array#sample" do -> { [1, 2].sample(random: random) }.should raise_error(RangeError) end end end @@ -69,9 +69,18 @@ describe "Array#shuffle" do -> { [1, 2].shuffle(random: random) }.should raise_error(RangeError) end - it "raises a RangeError if the value is equal to one" do value = mock("array_shuffle_random_value") - value.should_receive(:to_int).at_least(1).times.and_return(1) random = mock("array_shuffle_random") random.should_receive(:rand).at_least(1).times.and_return(value) |