forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.uuids.js
68 lines (61 loc) · 2.04 KB
/
test.uuids.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
64
65
66
67
68
'use strict';
/* jshint maxlen: false */
var rfcRegexp = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
function makeUuids(count, length, radix) {
count = count || 1;
var i = -1;
var out = [];
while (++i < count) {
out.push(PouchDB.utils.uuid(length, radix));
}
return out;
}
describe('test.uuid.js', function () {
it('UUID RFC4122 test', function () {
rfcRegexp.test(makeUuids()[0]).should
.equal(true, 'Single UUID complies with RFC4122.');
rfcRegexp.test(PouchDB.utils.uuid()).should
.equal(true,
'Single UUID through Pouch.utils.uuid complies with RFC4122.');
});
it('UUID generation uniqueness', function () {
var count = 1000;
var uuids = makeUuids(count);
testUtils.eliminateDuplicates(uuids).should.have
.length(count, 'Generated UUIDS are unique.');
});
it('Test small uuid uniqness', function () {
var length = 8;
var count = 2000;
var uuids = makeUuids(count, length);
testUtils.eliminateDuplicates(uuids).should.have
.length(count, 'Generated small UUIDS are unique.');
});
it('Test custom length', function () {
var length = 32;
var count = 10;
var uuids = makeUuids(count, length);
// Test single UUID wrapper
uuids.push(PouchDB.utils.uuid(length));
uuids.map(function (uuid) {
uuid.should.have.length(length, 'UUID length is correct.');
});
});
it('Test custom length, redix', function () {
var length = 32;
var count = 10;
var radix = 5;
var uuids = makeUuids(count, length, radix);
// Test single UUID wrapper
uuids.push(PouchDB.utils.uuid(length, radix));
uuids.map(function (uuid) {
var nums = uuid.split('').map(function (character) {
return parseInt(character, radix);
});
var max = Math.max.apply(Math, nums);
var min = Math.min.apply(Math, nums);
max.should.be.below(radix, 'Maximum character is less than radix');
min.should.be.at.least(0, 'Min character is greater than or equal to 0');
});
});
});