2017-04-10 17:49:32 +00:00
|
|
|
/*
|
|
|
|
QUnit.test("random.init() with no seed value", function(assert) {
|
|
|
|
random.init();
|
|
|
|
assert.ok(random.seed, "random seed is not null.");
|
2017-04-07 15:06:59 +00:00
|
|
|
});
|
|
|
|
|
2017-04-10 17:49:32 +00:00
|
|
|
QUnit.test("random.init() with provided seed", function(assert) {
|
|
|
|
let seed = new Date().getTime();
|
|
|
|
random.init(seed);
|
|
|
|
assert.equal(random.seed, seed, "seed is correct");
|
2017-04-07 15:06:59 +00:00
|
|
|
});
|
2017-04-10 17:49:32 +00:00
|
|
|
*/
|
2017-04-07 15:06:59 +00:00
|
|
|
|
2017-04-10 17:49:32 +00:00
|
|
|
QUnit.test("random.range() PRNG reproducibility", function(assert) {
|
|
|
|
let seed, result1, result2;
|
2017-04-07 15:06:59 +00:00
|
|
|
seed = new Date().getTime();
|
2017-04-10 17:49:32 +00:00
|
|
|
random.init(seed);
|
|
|
|
result1 = random.range(1, 20);
|
|
|
|
random.init(seed);
|
|
|
|
result2 = random.range(1, 20);
|
2017-04-07 15:06:59 +00:00
|
|
|
assert.equal(result1, result2, "both results are the same")
|
|
|
|
});
|
|
|
|
|
2017-04-10 17:49:32 +00:00
|
|
|
QUnit.test("random.choose() with equal distribution", function(assert) {
|
|
|
|
let foo = 0, bar = 0;
|
|
|
|
random.init(new Date().getTime());
|
|
|
|
for (let i = 0; i < 100; ++i) {
|
|
|
|
let tmp = random.choose([[1, 'foo'], [1, 'bar']]);
|
2017-04-07 15:06:59 +00:00
|
|
|
if (tmp == "foo") { foo += 1; }
|
|
|
|
if (tmp == "bar") { bar += 1; }
|
|
|
|
}
|
|
|
|
assert.ok(bar > 0 && foo > 0, "both objects were chosen")
|
|
|
|
});
|