The goog.testing.MockRandom Class

goog.testing.MockRandom
> goog.Disposable

goog.testing.MockRandom(sequence, opt_install)

Class for unit testing code that uses Math.random.

sequence {Array.<number>}
The sequence of numbers to return.
opt_install {boolean=}
Whether to install the MockRandom at construction time.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.hasMoreValues()

returns {boolean}
Whether there are more numbers left in the sequence.

.inject(values)

Injects new numbers into the beginning of the sequence.

values {Array.<number>|number}
Number or array of numbers to inject.

.install()

Installs this MockRandom as the system number generator.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.random()

returns {number}
The next number in the sequence. If there are no more values left, this will return a random number.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.uninstall()

Uninstalls the MockRandom.