couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r664091 - /incubator/couchdb/trunk/share/www/script/couch_tests.js
Date Fri, 06 Jun 2008 19:24:53 GMT
Author: damien
Date: Fri Jun  6 12:24:53 2008
New Revision: 664091

URL: http://svn.apache.org/viewvc?rev=664091&view=rev
Log:
Added comments and clarity to the reduce/combine test

Modified:
    incubator/couchdb/trunk/share/www/script/couch_tests.js

Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=664091&r1=664090&r2=664091&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Fri Jun  6 12:24:53 2008
@@ -352,14 +352,16 @@
       
     var map = function (doc) {emit(null, doc.val)};
     var reduceCombine = function (keys, values, combine) {
-        // this computes the standard deviation
-        
+        // This computes the standard deviation of the mapped results
         var stdDeviation=0;
         var count=0;
         var total=0;
         var sqrTotal=0;
           
         if (combine) {
+          // This is the combine phase, we are re-reducing previosuly returned
+          // reduce values.
+          
           for(var i in values) {
             count = count + values[i].count;
             total = total + values[i].total;
@@ -367,11 +369,10 @@
           }
           var variance =  (sqrTotal - ((total * total)/count)) / count;
           stdDeviation = Math.sqrt(variance);
-          
-          return {"stdDeviation":stdDeviation,"count":count,
-              "total":total,"sqrTotal":sqrTotal};
         }
         else {
+          // This is the reduce phase, we are reducing over emitted values from
+          // the map functions.
           for(var i in values) {
             total = total + values[i]
             sqrTotal = sqrTotal + (values[i] * values[i])
@@ -380,13 +381,15 @@
           var variance =  (sqrTotal - ((total * total)/count)) / count;
           stdDeviation = Math.sqrt(variance);
         }
-          
+        
+        // the reduce results. It contains enough information to compute
+        // further reduce results, and the final output values.
         return {"stdDeviation":stdDeviation,"count":count,
             "total":total,"sqrTotal":sqrTotal};
       };
       
+      // Save a bunch a docs.
       for(var j=0; j < 10; j++) {
-        // these docs are in the order of the keys collation, for clarity
         var docs = [];
         docs.push({val:10});
         docs.push({val:20});
@@ -402,8 +405,10 @@
       }
       
       var results = db.query(map, reduceCombine);
-      //account for floating point error
-      T(results.rows[0].value.stdDeviation == 28.722813232690143);
+      
+      var difference = results.rows[0].value.stdDeviation - 28.722813232690143;
+      // account for floating point rounding error
+      T(Math.abs(difference) < 0.0000000001);
       
   },
 



Mime
View raw message