jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1197376 - in /jmeter/trunk: src/jorphan/org/apache/jorphan/math/StatCalculator.java test/src/org/apache/jorphan/math/TestStatCalculator.java xdocs/changes.xml
Date Fri, 04 Nov 2011 00:56:03 GMT
Author: sebb
Date: Fri Nov  4 00:56:03 2011
New Revision: 1197376

URL: http://svn.apache.org/viewvc?rev=1197376&view=rev
Log:
Bug 52125 - StatCalculator.addAll(StatCalculator calc) joins incorrect if there are more samples
with the same response time in one of the TreeMap

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java
    jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java?rev=1197376&r1=1197375&r2=1197376&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/math/StatCalculator.java Fri Nov  4 00:56:03
2011
@@ -94,8 +94,8 @@ public abstract class StatCalculator<T e
     }
 
     public void addAll(StatCalculator<T> calc) {
-        for (T val : calc.valuesMap.keySet()) {
-            addValue(val);
+        for(Entry<T, MutableLong> ent : calc.valuesMap.entrySet()) {
+            addValue(ent.getKey(), ent.getValue().intValue());
         }
     }
 
@@ -200,25 +200,17 @@ public abstract class StatCalculator<T e
     public void addValue(T val, int sampleCount) {
         count += sampleCount;
         double currentVal = val.doubleValue();
-        sum += currentVal;
-        T actualValue = val;
-        if (sampleCount > 1){
-            // For n values in an aggregate sample the average value = (val/n)
-            // So need to add n * (val/n) * (val/n) = val * val / n
-            sumOfSquares += currentVal * currentVal / sampleCount;
-            actualValue = divide(val, sampleCount);
-        } else {
-            sumOfSquares += currentVal * currentVal;
-            actualValue = val;
-        }
-        updateValueCount(actualValue, sampleCount);
+        sum += currentVal * sampleCount; 
+        // For n same values in sum of square is equal to n*val^2
+        sumOfSquares += currentVal * currentVal * sampleCount;
+        updateValueCount(val, sampleCount);
         mean = sum / count;
         deviation = Math.sqrt((sumOfSquares / count) - (mean * mean));
-        if (actualValue.compareTo(max) > 0){
-            max=actualValue;
+        if (val.compareTo(max) > 0){
+            max=val;
         }
-        if (actualValue.compareTo(min) < 0){
-            min=actualValue;
+        if (val.compareTo(min) < 0){
+            min=val;
         }
     }
 

Modified: jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java?rev=1197376&r1=1197375&r2=1197376&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java (original)
+++ jmeter/trunk/test/src/org/apache/jorphan/math/TestStatCalculator.java Fri Nov  4 00:56:03
2011
@@ -101,4 +101,40 @@ public class TestStatCalculator extends 
         assertTrue(map.containsKey(Integer.valueOf(0)));
         assertTrue(map.containsKey(Integer.valueOf(2)));
     }
+    
+    public void testBug52125_1(){ // No duplicates when adding
+        calc.addValue(1L);
+        calc.addValue(2L);
+        calc.addValue(3L);
+        calc.addValue(2L);
+        calc.addValue(2L);
+        calc.addValue(2L);
+        assertEquals(6, calc.getCount());
+        assertEquals(12.0, calc.getSum());
+        assertEquals(0.5773502691896255, calc.getStandardDeviation());
+    }
+
+    public void testBug52125_2(){ // add duplicates
+        calc.addValue(1L);
+        calc.addValue(2L);
+        calc.addValue(3L);
+        calc.addValue(2L, 3);
+        assertEquals(6, calc.getCount());
+        assertEquals(12.0, calc.getSum());
+        assertEquals(0.5773502691896255, calc.getStandardDeviation());
+    }
+
+    public void testBug52125_3(){ // add duplicates as per bug
+        calc.addValue(1L);
+        calc.addValue(2L);
+        calc.addValue(3L);
+        StatCalculatorLong calc2 = new StatCalculatorLong();
+        calc2.addValue(2L);
+        calc2.addValue(2L);
+        calc2.addValue(2L);
+        calc.addAll(calc2);
+        assertEquals(6, calc.getCount());
+        assertEquals(12.0, calc.getSum());
+        assertEquals(0.5773502691896255, calc.getStandardDeviation());
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1197376&r1=1197375&r2=1197376&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Nov  4 00:56:03 2011
@@ -143,6 +143,7 @@ these occurs, Sampler is marked as faile
 <li>Bug 52093 - Toolbar ToolTips don't switch language</li>
 <li>Bug 51733 - SyncTimer is messed up if you a interrupt a test plan</li>
 <li>Bug 52118 - New toolbar : shutdown and stop buttons not disabled when no test is
running</li>
+<li>Bug 52125 - StatCalculator.addAll(StatCalculator calc) joins incorrect if there
are more samples with the same response time in one of the TreeMap</li>
 </ul>
 
 <!-- =================== Improvements =================== -->



Mime
View raw message