-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
56 lines (41 loc) · 1.04 KB
/
test.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
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const test = require('tape')
const pmr = require('.')
test('basic without seed', function (t) {
const random = pmr()
t.is(typeof random(), 'number')
t.end()
})
test('with string seed', function (t) {
t.plan(10)
const random1 = pmr('a seed')
const random2 = pmr('a seed')
for (let i = 0; i < 10; i++) {
t.is(random1(), random2())
}
})
test('with buffer seed', function (t) {
t.plan(10)
const random1 = pmr(Buffer.from('a seed'))
const random2 = pmr(Buffer.from('a seed'))
for (let i = 0; i < 10; i++) {
t.is(random1(), random2())
}
})
test('string seed is treated equally to buffer seed', function (t) {
t.plan(10)
const random1 = pmr('a seed')
const random2 = pmr(Buffer.from('a seed'))
for (let i = 0; i < 10; i++) {
t.is(random1(), random2())
}
})
test('with zero-filled seed', function (t) {
const random = pmr(Buffer.alloc(1))
const results = new Set()
for (let i = 0; i < 100; i++) {
results.add(random())
}
t.ok(results.size > 1, String(results.size))
t.end()
})