Class: Integer

Inherits:
Object
  • Object
show all
Extended by:
RushCheck::Arbitrary, RushCheck::HsRandom
Includes:
RushCheck::Coarbitrary
Defined in:
lib/rushcheck/integer.rb

Overview

ruby’s Integer class is extended to use RushCheck library. See also HsRandom, Arbitrary and Coarbitrary.

Direct Known Subclasses

NegativeInteger, PositiveInteger

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RushCheck::HsRandom

random, random_array, random_std

Methods included from RushCheck::Arbitrary

arbitrary

Class Method Details

.arbitraryObject

this method is needed to use Arbitrary.



26
27
28
# File 'lib/rushcheck/integer.rb', line 26

def self.arbitrary
  RushCheck::Gen.sized {|n| RushCheck::Gen.choose(-n, n) }
end

.boundObject

this method is needed to include HsRandom.



21
22
23
# File 'lib/rushcheck/integer.rb', line 21

def self.bound
  [@@min_bound, @@max_bound]
end

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

this method is needed to include HsRandom.



31
32
33
34
35
36
37
38
39
40
# File 'lib/rushcheck/integer.rb', line 31

def self.random_range(gen, lo=@@min_bound, hi=@@max_bound)
  hi, lo = lo, hi if hi < lo 
  v, g = gen.gen_next
  d = hi - lo + 1

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

Instance Method Details

#coarbitrary(g) ⇒ Object

this method is needed to use Coarbitrary.



43
44
45
46
# File 'lib/rushcheck/integer.rb', line 43

def coarbitrary(g)
  m = (self >= 0) ? 2 * self  : (-2) * self + 1
  g.variant(m)
end