OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/piecewise_linear_function.html"> | 8 <link rel="import" href="/tracing/base/math/piecewise_linear_function.html"> |
9 | 9 |
10 <script> | 10 <script> |
11 'use strict'; | 11 'use strict'; |
12 | 12 |
13 tr.b.unittest.testSuite(function() { | 13 tr.b.unittest.testSuite(function() { |
14 test('PiecewiseLinearFunctionEmpty', function() { | 14 test('PiecewiseLinearFunctionEmpty', function() { |
15 var f = new tr.b.PiecewiseLinearFunction(); | 15 var f = new tr.b.math.PiecewiseLinearFunction(); |
16 assert.strictEqual(f.max, -Infinity); | 16 assert.strictEqual(f.max, -Infinity); |
17 assert.strictEqual(f.min, Infinity); | 17 assert.strictEqual(f.min, Infinity); |
18 assert.strictEqual(f.average, 0); | 18 assert.strictEqual(f.average, 0); |
19 assert.strictEqual(f.percentile(0.5), 0); | 19 assert.strictEqual(f.percentile(0.5), 0); |
20 }); | 20 }); |
21 | 21 |
22 test('PiecewiseLinearFunction', function() { | 22 test('PiecewiseLinearFunction', function() { |
23 var f = new tr.b.PiecewiseLinearFunction(); | 23 var f = new tr.b.math.PiecewiseLinearFunction(); |
24 f.push(0, 0.0, 10, 1.0); | 24 f.push(0, 0.0, 10, 1.0); |
25 f.push(10, 1.0, 20, 0.0); | 25 f.push(10, 1.0, 20, 0.0); |
26 f.push(20, 0.0, 30, 0.0); | 26 f.push(20, 0.0, 30, 0.0); |
27 assert.strictEqual(f.max, 1.0); | 27 assert.strictEqual(f.max, 1.0); |
28 assert.strictEqual(f.min, 0.0); | 28 assert.strictEqual(f.min, 0.0); |
29 assert.closeTo(f.average, 20 * 1 / 2.0 / 30, 1e-6); | 29 assert.closeTo(f.average, 20 * 1 / 2.0 / 30, 1e-6); |
30 assert.closeTo(f.percentile(1.0 / 3.0), 0.0, 1e-6); | 30 assert.closeTo(f.percentile(1.0 / 3.0), 0.0, 1e-6); |
31 assert.closeTo(f.percentile(2.0 / 3.0), 0.5, 1e-6); | 31 assert.closeTo(f.percentile(2.0 / 3.0), 0.5, 1e-6); |
32 }); | 32 }); |
33 }); | 33 }); |
34 </script> | 34 </script> |
OLD | NEW |