Class: RushCheck::Assertion

Inherits:
Object
  • Object
show all
Includes:
Testable
Defined in:
lib/rushcheck/assertion.rb

Overview

Assertion class is one of main features of RushCheck. You can write a testcase for random testing as follows:

Assertion.new(Integer, String) do |x, y|

RushCheck::guard { precondition }
body

end

The return value of the body of testcase is checked by the method ‘check’.

Note that the number of arguments in the block must be equal to the number of arguments of Assertion.new. However, for a curried block, we can write also

Assertion.new(*cs) {|*xs| ...}

See also class Claim, which is a subclass of Assertion See also the RushCheck tutorial and several examples.

Direct Known Subclasses

Claim

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Testable

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

Constructor Details

#initialize(*xs, &f) ⇒ Assertion

Returns a new instance of Assertion.



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

def initialize(*xs, &f)
  @inputs = xs[0..(f.arity - 1)]
  @proc = f
end

Instance Attribute Details

#procObject (readonly)

Returns the value of attribute proc.



35
36
37
# File 'lib/rushcheck/assertion.rb', line 35

def proc
  @proc
end

Instance Method Details

#propertyObject



81
82
83
84
85
86
87
88
# File 'lib/rushcheck/assertion.rb', line 81

def property
  _property { |args|
    if @proc.call(*args)
    then RushCheck::Result.new(true)
    else RushCheck::Result.new(false)
    end
    }
end