Need tests for PerfTestRunner.computeStatistics
authortomz@codeaurora.org <tomz@codeaurora.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 May 2012 23:08:48 +0000 (23:08 +0000)
committertomz@codeaurora.org <tomz@codeaurora.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 May 2012 23:08:48 +0000 (23:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=85410

Reviewed by Ryosuke Niwa.

PerformanceTests:

* resources/runner.js:

LayoutTests:

* fast/harness/perftests/perf-runner-compute-statistics-expected.txt: Added.
* fast/harness/perftests/perf-runner-compute-statistics.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@115905 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/harness/perftests/perf-runner-compute-statistics-expected.txt [new file with mode: 0644]
LayoutTests/fast/harness/perftests/perf-runner-compute-statistics.html [new file with mode: 0644]
PerformanceTests/ChangeLog
PerformanceTests/resources/runner.js

index c0b7796..a7b54e0 100644 (file)
@@ -1,3 +1,13 @@
+2012-05-02  Tom Zakrajsek  <tomz@codeaurora.org>
+
+        Need tests for PerfTestRunner.computeStatistics
+        https://bugs.webkit.org/show_bug.cgi?id=85410
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/harness/perftests/perf-runner-compute-statistics-expected.txt: Added.
+        * fast/harness/perftests/perf-runner-compute-statistics.html: Added.
+
 2012-05-02  Joshua Bell  <jsbell@chromium.org>
 
         IndexedDB: Handle generated keys up to 2^53
diff --git a/LayoutTests/fast/harness/perftests/perf-runner-compute-statistics-expected.txt b/LayoutTests/fast/harness/perftests/perf-runner-compute-statistics-expected.txt
new file mode 100644 (file)
index 0000000..e9fc205
--- /dev/null
@@ -0,0 +1,68 @@
+This test verifies PerfTestRunner.computeStatistics(), including: min, max, median, mean, sum, variance, and stdev.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Ensure no latent divide by 0's for an odd number of elements.
+data = [0,0,0,0,0]
+PASS stats.min is 0
+PASS stats.max is 0
+PASS stats.median is 0
+PASS stats.mean is 0
+PASS stats.sum is 0
+PASS stats.variance is 0
+PASS stats.stdev is 0
+
+This test will catch if any order dependencies in the data, such as
+needing to be numerically sorted, are not resolved by the algorithm.
+This variant covers an odd number of elements.
+data = [1,10,2,20,5]
+PASS stats.min is 1
+PASS stats.max is 20
+PASS stats.median is 5
+PASS stats.mean is 7.6
+PASS stats.sum is 38
+PASS stats.min is 1
+PASS stats.max is 20
+PASS stats.median is 5
+PASS stats.mean is 7.6
+PASS stats.sum is 38
+PASS stats.variance is within 0.0001 of 48.239999999999995
+PASS stats.stdev is within 0.0001 of 6.945502141674135
+
+This test will catch if any order dependencies in the data, such as
+needing to be numerically sorted, are not resolved by the algorithm.
+This variant covers an odd number of elements, and negative values.
+data = [-1,-10,-2,-20,-5]
+PASS stats.min is -20
+PASS stats.max is -1
+PASS stats.median is -5
+PASS stats.mean is -7.6
+PASS stats.sum is -38
+PASS stats.min is -20
+PASS stats.max is -1
+PASS stats.median is -5
+PASS stats.mean is -7.6
+PASS stats.sum is -38
+PASS stats.variance is within 0.0001 of 48.239999999999995
+PASS stats.stdev is within 0.0001 of 6.945502141674135
+
+Ensure no latent divide by 0's for an even number of elements.
+data = [0,0,0,0]
+PASS stats.median is 0
+
+This test verifies that median is handled correctly for
+an even number of elements.
+data = [1,10,2,20,5,6]
+PASS stats.median is 5.5
+PASS stats.median is 5.5
+
+This test verifies that median is handled correctly for
+an even number of elements, including negative numbers.
+data = [-1,-10,-2,-20,-5,-6]
+PASS stats.median is -5.5
+PASS stats.median is -5.5
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/harness/perftests/perf-runner-compute-statistics.html b/LayoutTests/fast/harness/perftests/perf-runner-compute-statistics.html
new file mode 100644 (file)
index 0000000..9f66563
--- /dev/null
@@ -0,0 +1,153 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../../../PerformanceTests/resources/runner.js"></script>
+<script type="text/javascript">
+var alternateComputeStatistics = {
+    min: function(array) {
+        return Math.min.apply(Math, array);
+    },
+    max: function(array) {
+        return Math.max.apply(Math, array);
+    },
+    median: function(originalData) {
+        // don't want side effects on the input array, so...
+        var array = originalData.slice(0);
+        array.sort(function(a,b) { return a - b; });
+        var mid = Math.floor(array.length / 2);
+        if (array.length % 2)
+            return array[mid];
+        else
+            return (array[mid-1] + array[mid]) / 2;
+    },
+    mean: function(array) {
+        return alternateComputeStatistics.sum(array)/array.length;
+    },
+    sum: function(array) {
+        var total = 0;
+        for (var index in array)
+            total += array[index];
+        return total;
+    },
+    variance: function(array) {
+        var mean = alternateComputeStatistics.mean(array);
+        var arrayOfSquaredDiffs = [];
+        for (var index in array) {
+            var squaredDiff = array[index] - mean;
+            squaredDiff *= squaredDiff;
+            arrayOfSquaredDiffs.push(squaredDiff);
+        };
+        return alternateComputeStatistics.mean(arrayOfSquaredDiffs);
+    },
+    stdev: function(array) {
+        return Math.sqrt(alternateComputeStatistics.variance(array));
+    }
+};
+</script>
+</head>
+<body>
+
+<div id="description"></div>
+
+<script type="text/javascript">
+description("This test verifies PerfTestRunner.computeStatistics(), " +
+            "including: min, max, median, mean, sum, variance, and stdev.");
+</script>
+
+<div id="console"></div>
+
+<script type="text/javascript">
+var data = [];
+var stats = [];
+
+data = [0, 0, 0, 0, 0];
+debug("Ensure no latent divide by 0's for an odd number of elements.");
+debug("data = " + JSON.stringify(data));
+stats = PerfTestRunner.computeStatistics(data);
+shouldEvaluateTo("stats.min", 0);
+shouldEvaluateTo("stats.max", 0);
+shouldEvaluateTo("stats.median", 0);
+shouldEvaluateTo("stats.mean", 0);
+shouldEvaluateTo("stats.sum", 0);
+shouldEvaluateTo("stats.variance", 0);
+shouldEvaluateTo("stats.stdev", 0);
+debug("");
+
+data = [1, 10, 2, 20, 5];
+debug("This test will catch if any order dependencies in the data, such as");
+debug("needing to be numerically sorted, are not resolved by the algorithm.");
+debug("This variant covers an odd number of elements.");
+debug("data = " + JSON.stringify(data));
+stats = PerfTestRunner.computeStatistics(data);
+// hand calculated
+shouldEvaluateTo("stats.min", 1);
+shouldEvaluateTo("stats.max", 20);
+shouldEvaluateTo("stats.median", 5);
+shouldEvaluateTo("stats.mean", (38/5));
+shouldEvaluateTo("stats.sum", (1+2+5+10+20));
+// using alternate implementation
+shouldEvaluateTo("stats.min", alternateComputeStatistics.min(data));
+shouldEvaluateTo("stats.max", alternateComputeStatistics.max(data));
+shouldEvaluateTo("stats.median", alternateComputeStatistics.median(data));
+shouldEvaluateTo("stats.mean", alternateComputeStatistics.mean(data));
+shouldEvaluateTo("stats.sum", alternateComputeStatistics.sum(data));
+shouldBeCloseTo("stats.variance", alternateComputeStatistics.variance(data), 0.0001);
+shouldBeCloseTo("stats.stdev", alternateComputeStatistics.stdev(data), 0.0001);
+debug("");
+
+data = [-1, -10, -2, -20, -5];
+debug("This test will catch if any order dependencies in the data, such as");
+debug("needing to be numerically sorted, are not resolved by the algorithm.");
+debug("This variant covers an odd number of elements, and negative values.");
+debug("data = " + JSON.stringify(data));
+stats = PerfTestRunner.computeStatistics(data);
+// hand calculated
+shouldEvaluateTo("stats.min", -20);
+shouldEvaluateTo("stats.max", -1);
+shouldEvaluateTo("stats.median", -5);
+shouldEvaluateTo("stats.mean", (-38/5));
+shouldEvaluateTo("stats.sum", (-1-2-5-10-20));
+// using alternate implementation
+shouldEvaluateTo("stats.min", alternateComputeStatistics.min(data));
+shouldEvaluateTo("stats.max", alternateComputeStatistics.max(data));
+shouldEvaluateTo("stats.median", alternateComputeStatistics.median(data));
+shouldEvaluateTo("stats.mean", alternateComputeStatistics.mean(data));
+shouldEvaluateTo("stats.sum", alternateComputeStatistics.sum(data));
+shouldBeCloseTo("stats.variance", alternateComputeStatistics.variance(data), 0.0001);
+shouldBeCloseTo("stats.stdev", alternateComputeStatistics.stdev(data), 0.0001);
+debug("");
+
+data = [0, 0, 0, 0];
+debug("Ensure no latent divide by 0's for an even number of elements.");
+debug("data = " + JSON.stringify(data));
+stats = PerfTestRunner.computeStatistics(data);
+shouldEvaluateTo("stats.median", 0);
+debug("");
+
+data = [1, 10, 2, 20, 5, 6];
+debug("This test verifies that median is handled correctly for");
+debug("an even number of elements.");
+debug("data = " + JSON.stringify(data));
+stats = PerfTestRunner.computeStatistics(data);
+shouldEvaluateTo("stats.median", 5.5);
+shouldEvaluateTo("stats.median", alternateComputeStatistics.median(data));
+debug("");
+
+data = [-1, -10, -2, -20, -5, -6];
+debug("This test verifies that median is handled correctly for");
+debug("an even number of elements, including negative numbers.");
+debug("data = " + JSON.stringify(data));
+stats = PerfTestRunner.computeStatistics(data);
+shouldEvaluateTo("stats.median", -5.5);
+shouldEvaluateTo("stats.median", alternateComputeStatistics.median(data));
+debug("");
+
+// runner.js marks this as an async test so we need to call notifyDone.
+if (window.layoutTestController)
+    layoutTestController.notifyDone();
+</script>
+
+<script src="../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 1b73450..a0947b0 100644 (file)
@@ -1,3 +1,12 @@
+2012-05-02  Tom Zakrajsek  <tomz@codeaurora.org>
+
+        Need tests for PerfTestRunner.computeStatistics
+        https://bugs.webkit.org/show_bug.cgi?id=85410
+
+        Reviewed by Ryosuke Niwa.
+
+        * resources/runner.js:
+
 2012-04-29  Tom Zakrajsek  <tomz@codeaurora.org>
 
         PerfTestRunner.computeStatistics incorrectly calculates min, max and median
index 710d93b..e14f966 100644 (file)
@@ -1,3 +1,4 @@
+// There are tests for computeStatistics() located in LayoutTests/fast/harness/perftests
 
 var PerfTestRunner = {};