Class: NegativeInteger

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

Constant Summary collapse

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

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.



96
97
98
99
100
101
# File 'lib/rushcheck/integer.rb', line 96

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

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

this method is needed to include HsRandom.

Raises:

  • (RuntimeError)


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rushcheck/integer.rb', line 83

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

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