Permalink
Browse files

another test for m/r merge

  • Loading branch information...
1 parent aeb26c9 commit 8e000febf2de98a3b5ffe95159bdf0e67ae89d5b @erh erh committed Mar 26, 2011
Showing with 37 additions and 0 deletions.
  1. +37 −0 jstests/mr_merge2.js
View
37 jstests/mr_merge2.js
@@ -0,0 +1,37 @@
+
+t = db.mr_merge2;
+t.drop();
+
+t.insert( { a : [ 1 , 2 ] } )
+t.insert( { a : [ 2 , 3 ] } )
+t.insert( { a : [ 3 , 4 ] } )
+
+outName = "mr_merge2_out";
+out = db[outName];
+out.drop();
+
+m = function(){ for (i=0; i<this.a.length; i++ ) emit( this.a[i] , 1 ); }
+r = function(k,vs){ return Array.sum( vs ); }
+
+function tos( o ){
+ var s = "";
+ for ( var i=0; i<100; i++ ){
+ if ( o[i] )
+ s += i + "_" + o[i] + "|";
+ }
+ return s;
+}
+
+
+outOptions = { out : { merge : outName } }
+
+res = t.mapReduce( m , r , outOptions )
+expected = { "1" : 1 , "2" : 2 , "3" : 2 , "4" : 1 }
+assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "A" );
+
+t.insert( { a : [ 4 , 5 ] } )
+res = t.mapReduce( m , r , outOptions )
+expected["4"]++;
+expected["5"] = 1
+assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "B" );
+

0 comments on commit 8e000fe

Please sign in to comment.