forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_stream_tests.js
44 lines (34 loc) · 1.32 KB
/
random_stream_tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Tinytest.add("livedata - DDP.randomStream", function (test) {
var randomSeed = Random.id();
var context = { randomSeed: randomSeed };
var sequence = DDP._CurrentInvocation.withValue(context, function () {
return DDP.randomStream('1');
});
var seeds = sequence.alea.args;
test.equal(seeds.length, 2);
test.equal(seeds[0], randomSeed);
test.equal(seeds[1], '1');
var id1 = sequence.id();
// Clone the sequence by building it the same way RandomStream.get does
var sequenceClone = Random.createWithSeeds.apply(null, seeds);
var id1Cloned = sequenceClone.id();
var id2Cloned = sequenceClone.id();
test.equal(id1, id1Cloned);
// We should get the same sequence when we use the same key
sequence = DDP._CurrentInvocation.withValue(context, function () {
return DDP.randomStream('1');
});
seeds = sequence.alea.args;
test.equal(seeds.length, 2);
test.equal(seeds[0], randomSeed);
test.equal(seeds[1], '1');
// But we should be at the 'next' position in the stream
var id2 = sequence.id();
// Technically these could be equal, but likely to be a bug if hit
// http://search.dilbert.com/comic/Random%20Number%20Generator
test.notEqual(id1, id2);
test.equal(id2, id2Cloned);
});
Tinytest.add("livedata - DDP.randomStream with no-args", function (test) {
DDP.randomStream().id();
});