blob: 0ba06b0199a3f6d13cbff4bfb5cd26dcdf5bb8fb [file] [log] [blame]
<!DOCTYPE HTML>
<html>
<!--
Copyright (c) 2012 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>TimelineCounter tests</title>
<script src="base.js"></script>
<script>
base.require('unittest');
base.require('test_utils');
base.require('timeline_counter');
</script>
</head>
<body>
<script>
'use strict';
var TimelineCounter = tracing.TimelineCounter;
function createCounterWithTwoSeries() {
var ctr = new TimelineCounter(null, 0, '', 'myCounter');
ctr.seriesNames.push('a', 'b');
ctr.seriesColors.push(0, 1);
ctr.timestamps.push(0, 1, 2, 3);
ctr.samples.push(5, 10, 6, 15, 5, 12, 7, 16);
return ctr;
}
function testGetSampleStatisticsWithSingleSelection() {
var ctr = createCounterWithTwoSeries();
var ret = ctr.getSampleStatistics([0]);
assertEquals(5, ret[0].min);
assertEquals(5, ret[0].max);
assertEquals(5, ret[0].avg);
assertEquals(5, ret[0].start);
assertEquals(5, ret[0].end);
assertEquals(10, ret[1].min);
assertEquals(10, ret[1].max);
assertEquals(10, ret[1].avg);
assertEquals(10, ret[1].start);
assertEquals(10, ret[1].end);
}
function testGetSampleStatisticsWithMultipleSelections() {
var ctr = createCounterWithTwoSeries();
var ret = ctr.getSampleStatistics([0, 1]);
assertEquals(5, ret[0].min);
assertEquals(6, ret[0].max);
assertEquals((5 + 6) / 2, ret[0].avg);
assertEquals(5, ret[0].start);
assertEquals(6, ret[0].end);
assertEquals(10, ret[1].min);
assertEquals(15, ret[1].max);
assertEquals((10 + 15) / 2, ret[1].avg);
assertEquals(10, ret[1].start);
assertEquals(15, ret[1].end);
}
function testGetSampleStatisticsWithOutofOrderIndices() {
var ctr = createCounterWithTwoSeries();
var ret = ctr.getSampleStatistics([1, 0]);
assertEquals(5, ret[0].min);
assertEquals(6, ret[0].max);
assertEquals((5 + 6) / 2, ret[0].avg);
assertEquals(5, ret[0].start);
assertEquals(6, ret[0].end);
assertEquals(10, ret[1].min);
assertEquals(15, ret[1].max);
assertEquals((10 + 15) / 2, ret[1].avg);
assertEquals(10, ret[1].start);
assertEquals(15, ret[1].end);
}
function testGetSampleStatisticsWithAllSelections() {
var ctr = createCounterWithTwoSeries();
var ret = ctr.getSampleStatistics([1, 0, 2, 3]);
assertEquals(5, ret[0].min);
assertEquals(7, ret[0].max);
assertEquals((5 + 6 + 5 + 7) / 4, ret[0].avg);
assertEquals(5, ret[0].start);
assertEquals(7, ret[0].end);
assertEquals(10, ret[1].min);
assertEquals(16, ret[1].max);
assertEquals((10 + 15 + 12 + 16) / 4, ret[1].avg);
assertEquals(10, ret[1].start);
assertEquals(16, ret[1].end);
}
</script>
</body>
</html>