0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

assert.close just uses difference now (can specify decimal place) - old implementation was brittle for small numbers

This commit is contained in:
Mike Dirolf 2010-03-22 12:07:44 -04:00
parent d6e3981dc7
commit c0c57984d9

View File

@ -132,15 +132,16 @@ assert.gt = function( a , b , msg ){
doassert( a + " is not greater than " + b + " : " + msg );
}
assert.close = function( a , b , msg ){
if (a === 0 && b === 0) {
assert.close = function( a , b , msg , places ){
if (places === undefined) {
places = 4;
}
if (Math.round((a - b) * Math.pow(10, places)) === 0) {
return;
}
var diff = Math.abs( (a-b)/((a+b)/2) );
if ( diff < .001 )
return;
doassert( a + " is not close to " + b + " diff: " + diff + " : " + msg );
}
doassert( a + " is not equal to " + b + " within " + places +
" places, diff: " + (a-b) + " : " + msg );
};
Object.extend = function( dst , src , deep ){
for ( var k in src ){