diff options
author | Aaron <aaron@10gen.com> | 2009-04-07 17:58:25 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-04-07 17:58:25 -0400 |
commit | 5b1411841303f486f1acc117fca294fa3b443e70 (patch) | |
tree | 4c114910f1c76da15de2bd0949b954d9802990bc /dbtests | |
parent | 5f9d2b6aa5ed0ac05bf42e93bcb608ad7aa2c01d (diff) | |
download | mongo-5b1411841303f486f1acc117fca294fa3b443e70.tar.gz |
handle nan and inf double values in comparison
Diffstat (limited to 'dbtests')
-rw-r--r-- | dbtests/jsobjtests.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index f004ec23f71..e157f956152 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -175,6 +175,31 @@ namespace JsobjTests { } }; + class Nan : public Base { + public: + void run() { + double inf = numeric_limits< double >::infinity(); + double nan = numeric_limits< double >::quiet_NaN(); + double nan2 = numeric_limits< double >::signaling_NaN(); + + ASSERT( BSON( "a" << inf ).woCompare( BSON( "a" << inf ) ) == 0 ); + ASSERT( BSON( "a" << inf ).woCompare( BSON( "a" << 1 ) ) < 0 ); + ASSERT( BSON( "a" << 1 ).woCompare( BSON( "a" << inf ) ) > 0 ); + + ASSERT( BSON( "a" << nan ).woCompare( BSON( "a" << nan ) ) == 0 ); + ASSERT( BSON( "a" << nan ).woCompare( BSON( "a" << 1 ) ) < 0 ); + ASSERT( BSON( "a" << 1 ).woCompare( BSON( "a" << nan ) ) > 0 ); + + ASSERT( BSON( "a" << nan2 ).woCompare( BSON( "a" << nan2 ) ) == 0 ); + ASSERT( BSON( "a" << nan2 ).woCompare( BSON( "a" << 1 ) ) < 0 ); + ASSERT( BSON( "a" << 1 ).woCompare( BSON( "a" << nan2 ) ) > 0 ); + + ASSERT( BSON( "a" << inf ).woCompare( BSON( "a" << nan ) ) == 0 ); + ASSERT( BSON( "a" << inf ).woCompare( BSON( "a" << nan2 ) ) == 0 ); + ASSERT( BSON( "a" << nan ).woCompare( BSON( "a" << nan2 ) ) == 0 ); + } + }; + namespace Validation { class Base { @@ -619,6 +644,7 @@ namespace JsobjTests { add< BSONObjTests::WoCompareDifferentLength >(); add< BSONObjTests::WoSortOrder >(); add< BSONObjTests::TimestampTest >(); + add< BSONObjTests::Nan >(); add< BSONObjTests::Validation::BadType >(); add< BSONObjTests::Validation::EooBeforeEnd >(); add< BSONObjTests::Validation::Undefined >(); |