sevenwire-forgery 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +3 -3
- data/lib/extensions/range.rb +3 -3
- data/spec/extensions/range_spec.rb +9 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
:minor: 2
|
3
|
+
:patch: 1
|
4
|
+
:major: 0
|
data/lib/extensions/range.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Range
|
2
2
|
def random
|
3
|
-
|
4
|
-
|
5
|
-
Kernel.rand(
|
3
|
+
Integer(first) && Integer(last)
|
4
|
+
raise ArgumentError if first > last
|
5
|
+
Kernel.rand(last - first + 1) + first
|
6
6
|
rescue ArgumentError
|
7
7
|
self.to_a.random
|
8
8
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
describe Range do
|
4
5
|
it "should get a random number out of the range" do
|
@@ -6,6 +7,14 @@ describe Range do
|
|
6
7
|
10.times { range.should include(range.random) }
|
7
8
|
end
|
8
9
|
|
10
|
+
it "should not take a long time when the range is huge" do
|
11
|
+
Timeout.timeout(1){(1234567890..12345678901234567890).random}.should_not raise_error(Timeout::Error)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return nil for a random number from a reverse range" do
|
15
|
+
10.times { (9..0).random.should be_nil }
|
16
|
+
end
|
17
|
+
|
9
18
|
it "should get a random string our of the range" do
|
10
19
|
range = ("a".."z")
|
11
20
|
10.times { range.should include(range.random) }
|