Class: Float

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

Constant Summary collapse

@@min_bound =
0.0
@@max_bound =
1.0

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RushCheck::Arbitrary

arbitrary

Methods included from RushCheck::HsRandom

random, random_array, random_std

Class Method Details

.arbitraryObject



18
19
20
21
22
23
# File 'lib/rushcheck/float.rb', line 18

def self.arbitrary
  RushCheck::Gen.new do |n, r|
    a, b, c = (1..3).map { Integer.arbitrary.value(n, r) }
    a + (b / (c.abs + 1))
  end
end

.boundObject



25
26
27
# File 'lib/rushcheck/float.rb', line 25

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

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



29
30
31
32
33
34
35
# File 'lib/rushcheck/float.rb', line 29

def self.random_range(gen, lo=@@min_bound, hi=@@max_bound)
  x, g = Integer.random(gen)
  a, b = Integer.bound
  r = (lo+hi/2).to_f + ((hi - lo).to_f / (b - a) * x)

  [r, g]
end

Instance Method Details

#coarbitrary(g) ⇒ Object



37
38
39
40
41
# File 'lib/rushcheck/float.rb', line 37

def coarbitrary(g)
  h = truncate
  t = (self * (10 ** ((self - h).to_s.length - 2))).truncate
  h.coarbitrary(t.coarbitrary(g))
end