Class: Hypothesis::Possible

Inherits:
Object
  • Object
show all
Includes:
Hypothesis
Defined in:
lib/hypothesis/possible.rb

Overview

A Possible describes a range of valid values that can result from a call to #any. This class should not be subclassed directly, but instead should always be constructed using methods from Possibilities.

Constant Summary

Constants included from Hypothesis

DEFAULT_DATABASE_PATH

Instance Method Summary collapse

Methods included from Hypothesis

#any, #assume, #hypothesis, included, setup_called

Instance Method Details

#map { ... } ⇒ Possible Also known as: collect

A Possible value constructed by passing one of these Possible values to the provided block.

e.g. the Possible values of ‘integers.map { |i| i * 2 }` are all even integers.

Yields:

  • A possible value of self.

Returns:



34
35
36
37
38
# File 'lib/hypothesis/possible.rb', line 34

def map
  Implementations::CompositePossible.new do
    yield any(self)
  end
end

#select { ... } ⇒ Possible Also known as: filter

Note:

Similar warnings to Hypothesis#assume apply here: If the condition is difficult to satisfy this may impact the performance and quality of your testing.

One of these Possible values selected such that the block returns a true value for it.

e.g. the Possible values of ‘integers.filter { |i| i % 2 == 0}` are all even integers (but will typically be less efficient than the one suggested in #map.

Yields:

  • A possible value of self.

Returns:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hypothesis/possible.rb', line 57

def select
  Implementations::CompositePossible.new do
    result = nil
    4.times do |i|
      assume(i < 3)
      result = any self
      break if yield(result)
    end
    result
  end
end