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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 0
3
- major: 0
4
- minor: 2
2
+ :minor: 2
3
+ :patch: 1
4
+ :major: 0
@@ -1,8 +1,8 @@
1
1
  class Range
2
2
  def random
3
- return nil unless self.max
4
- Integer(min) && Integer(max)
5
- Kernel.rand(self.max - self.min + 1) + self.min
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) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevenwire-forgery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sutton