Permalink
Browse files

fix group5.js test. MINOR

  • Loading branch information...
1 parent c33f5a8 commit d5415567a77e28e5e08a748e5cbb4023be77684f @RedBeard0531 RedBeard0531 committed Oct 20, 2009
Showing with 16 additions and 6 deletions.
  1. +16 −6 jstests/group5.js
View
@@ -2,6 +2,7 @@
t = db.group5;
t.drop();
+// each group has groupnum+1 5 users
for ( var group=0; group<10; group++ ){
for ( var i=0; i<5+group; i++ ){
t.save( { group : "group" + group , user : i } )
@@ -13,16 +14,25 @@ function c( group ){
{
key : { group : 1 } ,
q : { group : "group" + group } ,
- initial : { users : [] },
+ initial : { users : {} },
reduce : function(obj,prev){
- prev.users.push( obj.user );
+ prev.users[obj.user] = true; // add this user to the hash
},
finalize : function(x){
- x.users = x.users.length;
+ var count = 0;
+ for (var key in x.users){
+ count++;
+ }
+
+ //replace user obj with count
+ //count add new field and keep users
+ x.users = count;
return x;
}
- });
+ })[0]; // returns array
}
-assert.eq( 5 , c(0) , "g0" );
-assert.eq( 10 , c(5) , "g5" );
+assert.eq( "group0" , c(0).group , "g0" );
+assert.eq( 5 , c(0).users , "g0 a" );
+assert.eq( "group5" , c(5).group , "g5" );
+assert.eq( 10 , c(5).users , "g5 a" );

0 comments on commit d541556

Please sign in to comment.