Skip to content

Instantly share code, notes, and snippets.

@renctan
Created October 4, 2013 17:58
Show Gist options
  • Save renctan/6829949 to your computer and use it in GitHub Desktop.
Save renctan/6829949 to your computer and use it in GitHub Desktop.
Test for bsonWoCompare
// Both must be objects
assert.throws(function() {
bsonWoCompare({ x: 1 }, 1);
});
assert.throws(function() {
bsonWoCompare(1, { x: 1 });
});
assert.throws(function() {
bsonWoCompare(1, 1);
});
assert.throws(function() {
bsonWoCompare(null, { x: 1 });
});
assert.throws(function() {
bsonWoCompare({ x: 1 }, null);
});
// Must have 2 args
assert.throws(function() {
bsonWoCompare();
});
assert.throws(function() {
bsonWoCompare({ x: 1 });
});
assert.throws(function() {
bsonWoCompare({ x: 1 });
});
assert.throws(function() {
bsonWoCompare({ x: 1 }, { x: 1 }, { x: 1 });
});
assert.eq(0, bsonWoCompare({}, {}));
assert.eq(0, bsonWoCompare({ x: 1 }, { x: 1 }));
assert.eq(0, bsonWoCompare({ x: 1, y: 1 }, { x: 1, y: 1 }));
assert.eq(0, bsonWoCompare({ x: new Date(1000 * 1000 * 1000 * 1000) },
{ x: ISODate("2001-09-09T01:46:40Z") }));
assert.eq(0, bsonWoCompare({ x: 1, y: { a: 1, b: 1 }}, { x: 1, y: { a: 1, b: 1 }}));
assert.gt(bsonWoCompare({ x: 1 }, {}), 0);
assert.gt(bsonWoCompare({ x: 1, y: 10 }, { x: 1 }), 0);
assert.gt(bsonWoCompare({ x: 1, y: 10 }, { x: 1, y: 1 }), 0);
assert.gt(bsonWoCompare({ y: 1, x: 1 }, { x: 1, y: 1 }), 0);
assert.lt(bsonWoCompare({}, { x: 1 }), 0);
assert.lt(bsonWoCompare({ x: 1 }, { y: 10 }), 0);
assert.lt(bsonWoCompare({ x: 1, y: 1 }, { x: 1, y: 10 }), 0);
assert.lt(bsonWoCompare({ x: 1, y: 1 }, { y: 1, x: 1 }), 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment