Class: RandomProc

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RushCheck::Arbitrary

arbitrary

Methods included from RushCheck::Testable

#check, #classify, #imply, #label, #run, #run_tests, #silent_check, #test, #testcase, #trivial

Class Method Details

.arbitraryObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rushcheck/proc.rb', line 19

def self.arbitrary
  RushCheck::Gen.new do |n, r|
    Proc.new do |*args|
      gens = if args.empty?
             then @@outputs.map {|c| c.arbitrary }
             else args.map do |v|
                    @@outputs.map do |c|
                      v.coarbitrary(c.arbitrary)
                    end
                  end.flatten
             end
      RushCheck::Gen.oneof(gens).value(n, r)
    end
  end
end

.set_pattern(inputs, outputs) ⇒ Object



15
16
17
# File 'lib/rushcheck/proc.rb', line 15

def self.set_pattern(inputs, outputs)
  @@inputs, @@outputs = inputs, outputs
end

Instance Method Details

#coarbitrary(g) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rushcheck/proc.rb', line 35

def coarbitrary(g)
  RushCheck::Gen.new do |n, r|
    r2 = r
    args = @@inputs.map do |c| 
      r1, r2 = r2.split
      c.arbitrary.value(n, r1)
    end

    call(*args).coarbitrary(g)
  end
end

#propertyObject



47
48
49
50
51
# File 'lib/rushcheck/proc.rb', line 47

def property
  RushCheck::Gen.lift_array(@@inputs) {|c| c.arbitrary }.forall do |*args|
    call(*args)
  end
end