Class: RandomlyGenerated::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/randomly_generated/object.rb

Overview

This is the base class for all classes used to generate random objects.

Direct Known Subclasses

Integer, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Object

Returns a new instance of Object.



6
7
8
9
# File 'lib/randomly_generated/object.rb', line 6

def initialize(options={})
  @seed = options.fetch(:seed) { Random.new_seed }
  @rand = Random.new(seed)
end

Instance Attribute Details

#randObject (readonly)

Returns the value of attribute rand.



4
5
6
# File 'lib/randomly_generated/object.rb', line 4

def rand
  @rand
end

#seedObject (readonly)

Returns the value of attribute seed.



3
4
5
# File 'lib/randomly_generated/object.rb', line 3

def seed
  @seed
end

Instance Method Details

#callObject

Returns the generated object.

Raises:



12
13
14
# File 'lib/randomly_generated/object.rb', line 12

def call
  raise NotImplementedError
end

#shrunken_subsetsObject

Returns an array of “shrunken” proper subsets of the object. These subsets are intended to find simpler cases that will reproduce a test failure. WARNING: This API will likely change. We plan to experiment with it heavily. One idea is to have it take a block instead, and pass the various subsets to the block.



20
21
22
23
# File 'lib/randomly_generated/object.rb', line 20

def shrunken_subsets
  # By default, assume that the object is atomic and cannot be simplified.
  []
end