diff options
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/couch_tests.js | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 287ba6fb..fd6eaed2 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -388,12 +388,12 @@ var tests = { result = db.query(map, reduce, {startkey: i, endkey: numDocs - i}); T(result.rows[0].value == 2*(summate(numDocs-i) - summate(i-1))); } - + db.deleteDb(); db.createDb(); for(var i=1; i <= 5; i++) { - + for(var j=0; j < 10; j++) { // these docs are in the order of the keys collation, for clarity var docs = []; @@ -411,12 +411,12 @@ var tests = { T(db.bulkSave(docs).ok); T(db.info().doc_count == ((i - 1) * 10 * 11) + ((j + 1) * 11)); } - + map = function (doc) {emit(doc.keys, 1)}; reduce = function (keys, values) { return sum(values); }; - + var results = db.query(map, reduce, {group:true}); - + //group by exact key match T(equals(results.rows[0], {key:["a"],value:20*i})); T(equals(results.rows[1], {key:["a","b"],value:20*i})); @@ -432,7 +432,7 @@ var tests = { var results = db.query(map, reduce, {group_level:1}); T(equals(results.rows[0], {key:["a"],value:70*i})); T(equals(results.rows[1], {key:["d"],value:40*i})); - + //group by the first 2 elements in the key array var results = db.query(map, reduce, {group_level:2}); T(equals(results.rows[0], {key:["a"],value:20*i})); @@ -443,13 +443,13 @@ var tests = { T(equals(results.rows[5], {key:["d","b"],value:10*i})); T(equals(results.rows[6], {key:["d","c"],value:10*i})); } - + // now test out more complex reductions that need to use the combine option. - + db.deleteDb(); db.createDb(); - + var map = function (doc) {emit(doc.val, doc.val)}; var reduceCombine = function (keys, values, rereduce) { // This computes the standard deviation of the mapped results @@ -457,7 +457,7 @@ var tests = { var count=0; var total=0.0; var sqrTotal=0.0; - + if (!rereduce) { // This is the reduce phase, we are reducing over emitted values from // the map functions. @@ -467,7 +467,7 @@ var tests = { } count = values.length; } - else { + else { // This is the rereduce phase, we are re-reducing previosuly // reduced values. for(var i in values) { @@ -476,17 +476,18 @@ var tests = { sqrTotal = sqrTotal + values[i].sqrTotal; } } - + var variance = (sqrTotal - ((total * total)/count)) / count; stdDeviation = Math.sqrt(variance); - + // the reduce result. It contains enough information to be rereduced // with other reduce results. return {"stdDeviation":stdDeviation,"count":count, "total":total,"sqrTotal":sqrTotal}; }; - + // Save a bunch a docs. + for(var i=0; i < 10; i++) { var docs = []; docs.push({val:10}); @@ -786,7 +787,7 @@ var tests = { if (debug) debugger; var numDocs = 500; - + function makebigstring(power) { var str = "a"; while(power-- > 0) { |