Class: RandomHash
- Inherits:
-
Hash
- Object
- Hash
- RandomHash
- Extended by:
- RushCheck::Arbitrary
- Includes:
- RushCheck::Coarbitrary
- Defined in:
- lib/rushcheck/hash.rb
Overview
RandomHash is a subclass of Hash which provides a random generator of hash. Programmer can make a subclass of RandomHash to make user defined random generator of Hash.
Class Method Summary collapse
- .arbitrary ⇒ Object
-
.set_pattern(pat) ⇒ Object
class method set_pattern takes a hash object of random pattern.
Instance Method Summary collapse
Methods included from RushCheck::Arbitrary
Class Method Details
.arbitrary ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rushcheck/hash.rb', line 26 def self.arbitrary RushCheck::Gen.new do |n, r| h = {} r2 = r @@pat.keys.each do |k| r1, r2 = r2.split h[k] = @@pat[k].arbitrary.value(n, r1) end h end end |
.set_pattern(pat) ⇒ Object
21 22 23 24 |
# File 'lib/rushcheck/hash.rb', line 21 def self.set_pattern(pat) @@pat = pat self end |
Instance Method Details
#coarbitrary(g) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rushcheck/hash.rb', line 38 def coarbitrary(g) r = g.variant(0) values.each do |c| r = c.coarbitrary(r.variant(1)) end r end |