Class: PositiveInteger

Inherits:
Integer show all
Defined in:
lib/rushcheck/integer.rb

Constant Summary collapse

@@max_bound =
2**30 - 1
@@min_bound =
1

Class Method Summary collapse

Methods inherited from Integer

bound, #coarbitrary

Methods included from RushCheck::HsRandom

#random, #random_array, #random_std

Methods included from RushCheck::Arbitrary

#arbitrary

Methods included from RushCheck::Coarbitrary

#coarbitrary

Class Method Details

.arbitraryObject

this method is needed to use Arbitrary.



68
69
70
71
72
73
# File 'lib/rushcheck/integer.rb', line 68

def self.arbitrary
  RushCheck::Gen.sized do |n| 
    n = 1 - n if n <= 0
    RushCheck::Gen.choose(1, n) 
  end
end

.random_range(gen, lo = @@min_bound, hi = @@max_bound) ⇒ Object

this method is needed to include HsRandom.

Raises:

  • (RuntimeError)


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rushcheck/integer.rb', line 55

def self.random_range(gen, lo=@@min_bound, hi=@@max_bound)
  hi, lo = lo, hi if hi < lo 
  raise RuntimeError, "PositiveInteger requires positive lower bound." if lo <= 0
  v, g = gen.gen_next
  d = hi - lo + 1

  if d == 1
  then [lo, g]
  else [(v % d) + lo, g]
  end
end