forked from ulid/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
63 lines (43 loc) · 1.53 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
57
58
59
60
61
62
63
var assert = require('assert')
var ulid = require('./')
describe('ulid', function() {
describe('prng', function() {
it('should produce a number', function() {
assert.strictEqual(false, isNaN(ulid.prng()))
})
it('should be between 0 and 1', function() {
var num = ulid.prng()
assert(num > 0 && num < 1)
})
})
describe('encodeTime', function() {
it('should return expected encoded result', function() {
assert.strictEqual('01ARYZ6S41', ulid.encodeTime(1469918176385, 10))
})
it('should change length properly', function() {
assert.strictEqual('0001AS99AA60', ulid.encodeTime(1470264322240, 12))
})
it('should truncate time if not enough length', function() {
assert.strictEqual('AS4Y1E11', ulid.encodeTime(1470118279201, 8))
})
it('should throw if time greater than (2 ^ 48) - 1', function() {
assert.throws(() => ulid.encodeTime(Math.pow(2, 48), 8), Error)
})
})
describe('encodeRandom', function() {
it('should return correct length', function() {
assert.strictEqual(12, ulid.encodeRandom(12).length)
})
})
describe('ulid', function() {
it('should return correct length', function() {
assert.strictEqual(26, ulid().length)
})
it('should return expected encoded time component result', function() {
assert.strictEqual('01ARYZ6S41', ulid(1469918176385).substring(0, 10))
})
it('should throw an error if seed is not a number', function() {
assert.throws(() => ulid('test'), Error)
})
})
})