summaryrefslogtreecommitdiff
path: root/shell/utils.js
diff options
context:
space:
mode:
authorMike Dirolf <mike@10gen.com>2010-03-22 12:07:44 -0400
committerMike Dirolf <mike@10gen.com>2010-03-22 12:07:44 -0400
commitc0c57984d9f7f38f90257e7ac2780894dadbd9ad (patch)
treeb32ff668066f4615280c531c3ecee2fedcc0b4d7 /shell/utils.js
parentd6e3981dc7286a34c8f1030c0dde7c1e2b087abc (diff)
downloadmongo-c0c57984d9f7f38f90257e7ac2780894dadbd9ad.tar.gz
assert.close just uses difference now (can specify decimal place) - old implementation was brittle for small numbers
Diffstat (limited to 'shell/utils.js')
-rw-r--r--shell/utils.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/shell/utils.js b/shell/utils.js
index 786e0009e6f..027ba0d6386 100644
--- a/shell/utils.js
+++ b/shell/utils.js
@@ -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) {
- return;
+assert.close = function( a , b , msg , places ){
+ if (places === undefined) {
+ places = 4;
}
- var diff = Math.abs( (a-b)/((a+b)/2) );
- if ( diff < .001 )
+ if (Math.round((a - b) * Math.pow(10, places)) === 0) {
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 ){