Skip to content

Commit

Permalink
SERVER-205 cleaner test
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Apr 13, 2010
1 parent b2830ef commit 41d65a8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions jstests/or1.js
@@ -1,7 +1,16 @@
t = db.jstests_or1;
t.drop();

// assuming saved in order, hopefully ok just for this test
checkArrs = function( a, b, m ) {
assert.eq( a.length, b.length, m );
aStr = [];
bStr = [];
a.forEach( function( x ) { aStr.push( tojson( x ) ); } );
b.forEach( function( x ) { bStr.push( tojson( x ) ); } );
for ( i in aStr ) {
assert( -1 != bStr.indexOf( aStr[ i ] ), m );
}
}

doTest = function() {

Expand All @@ -19,10 +28,10 @@ assert.throws( function() { t.find( { $or:[] } ).toArray(); } );
assert.throws( function() { t.find( { $or:[ "a" ] } ).toArray(); } );

a1 = t.find( { $or: [ { a : 1 } ] } ).toArray();
assert.eq( [ { _id:0, a:1 }, { _id:4, a:1, b:1 }, { _id:5, a:1, b:2 } ], a1 );
checkArrs( [ { _id:0, a:1 }, { _id:4, a:1, b:1 }, { _id:5, a:1, b:2 } ], a1 );

a1b2 = t.find( { $or: [ { a : 1 }, { b : 2 } ] } ).toArray();
assert.eq( [ { _id:0, a:1 }, { _id:3, b:2 }, { _id:4, a:1, b:1 }, { _id:5, a:1, b:2 }, { _id:7, a:2, b:2 } ], a1b2 );
checkArrs( [ { _id:0, a:1 }, { _id:3, b:2 }, { _id:4, a:1, b:1 }, { _id:5, a:1, b:2 }, { _id:7, a:2, b:2 } ], a1b2 );

t.drop();
t.save( {a:[0,1],b:[0,1]} );
Expand Down

0 comments on commit 41d65a8

Please sign in to comment.