Skip to content

Commit

Permalink
Add another test that compares different v1 uuid generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ctavan committed Nov 17, 2011
1 parent 9b4184e commit b9ede7a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/compare_v1.js
@@ -0,0 +1,50 @@
var assert = require('assert'),
nodeuuid = require('../uuid'),
uuidjs = require('uuid-js'),
libuuid = require('uuid').generate,
util = require('util'),
exec = require('child_process').exec;

function compare(ids) {
var sorted = ([].concat(ids)).sort();
console.log(ids);
if (sorted.toString() !== ids.toString()) {
console.log('Warning: sorted !== ids');
}
}

// Test time order of v1 uuids
var ids = [];
while (ids.length < 10e3) ids.push(nodeuuid.v1());

var max = 10;
console.log('node-uuid:');
ids = [];
for (var i = 0; i < max; i++) ids.push(nodeuuid.v1());
compare(ids);

console.log('');
console.log('uuidjs:');
ids = [];
for (var i = 0; i < max; i++) ids.push(uuidjs.create(1).toString());
compare(ids);

console.log('');
console.log('libuuid:');
ids = [];
var count = 0;
var last = function() {
compare(ids);
}
var cb = function(err, stdout, stderr) {
ids.push(stdout.substring(0, stdout.length-1));
count++;
if (count < max) {
return next();
}
last();
};
var next = function() {
exec('uuid -1', cb);
};
next();

0 comments on commit b9ede7a

Please sign in to comment.