Class: String

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

Direct Known Subclasses

SpecialString

Constant Summary collapse

@@min_range =
0
@@max_range =
1024

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



20
21
22
23
24
25
26
27
28
# File 'lib/rushcheck/string.rb', line 20

def self.arbitrary
  RushCheck::Gen.sized do |n|
    # Note the Benford's law;
    # http://mathworld.wolfram.com/BenfordsLaw.html
    # This says that (a random integer % 128).chr seems not
    # have /really randomness/.
    RushCheck::Gen.unit((0..n).map{rand(128).chr}.join)
  end
end

.boundObject



30
31
32
# File 'lib/rushcheck/string.rb', line 30

def self.bound
  [@@min_range, @@max_range]
end

.random_range(gen, lo = @@min_range, hi = @@max_range) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/rushcheck/string.rb', line 34

def self.random_range(gen, lo=@@min_range, hi=@@max_range)
  len, g = Integer.random(gen, lo, hi)
  result = ''
  len.times do
    v, g = Integer.random(g, 0, 127)
    result += v.chr
  end
  
  [result. g]
end

Instance Method Details

#coarbitrary(g) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/rushcheck/string.rb', line 45

def coarbitrary(g)
  r = g.variant(0)
  each_byte do |c|
    r = c.coarbitrary(r.variant(1))
  end
  r
end