Files
meteor/packages/random/random_tests.js
Andrew Wilcox 1ad813951b Allow new Random instances to be constructed with specified seed.
For repeatable unit test failures with "random" data it's useful to be
able to create deterministic random number sequences.

Introduce `Random.create(seed...)` which returns a object with the
`Random` API (`id()`, `choice()`, etc.) initialized with the passed
seed(s).
2013-05-22 21:34:39 -07:00

16 lines
675 B
JavaScript

Tinytest.add('random', function (test) {
// Deterministic with a specified seed, which should generate the
// same sequence in all environments.
//
// For repeatable unit test failures using deterministic random
// number sequences it's fine if a new Meteor release changes the
// algorithm being used and it starts generating a different
// sequence for a seed, as long as the sequence is consistent for
// a particular release.
var random = Random.create(0);
test.equal(random.id(), "cp9hWvhg8GSvuZ9os");
test.equal(random.id(), "3f3k6Xo7rrHCifQhR");
test.equal(random.id(), "shxDnjWWmnKPEoLhM");
test.equal(random.id(), "6QTjB8C5SEqhmz4ni");
});