1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 'use strict'; 6 7 base.require('tracing.test_utils'); 8 base.require('tracing.trace_model.counter'); 9 base.require('tracing.trace_model.counter_series'); 10 11 base.unittest.testSuite('tracing.trace_model.counter', function() { 12 var createCounterWithTwoSeries = function() { 13 var ctr = new tracing.trace_model.Counter(null, 0, '', 'myCounter'); 14 var aSeries = new tracing.trace_model.CounterSeries('a', 0); 15 var bSeries = new tracing.trace_model.CounterSeries('b', 0); 16 ctr.addSeries(aSeries); 17 ctr.addSeries(bSeries); 18 19 aSeries.addSample(0, 5); 20 aSeries.addSample(1, 6); 21 aSeries.addSample(2, 5); 22 aSeries.addSample(3, 7); 23 24 bSeries.addSample(0, 10); 25 bSeries.addSample(1, 15); 26 bSeries.addSample(2, 12); 27 bSeries.addSample(3, 16); 28 29 return ctr; 30 }; 31 32 test('getSampleStatisticsWithSingleSelection', function() { 33 var ctr = createCounterWithTwoSeries(); 34 var ret = ctr.getSampleStatistics([0]); 35 36 assertEquals(5, ret[0].min); 37 assertEquals(5, ret[0].max); 38 assertEquals(5, ret[0].avg); 39 assertEquals(5, ret[0].start); 40 assertEquals(5, ret[0].end); 41 42 assertEquals(10, ret[1].min); 43 assertEquals(10, ret[1].max); 44 assertEquals(10, ret[1].avg); 45 assertEquals(10, ret[1].start); 46 assertEquals(10, ret[1].end); 47 }); 48 49 test('getSampleStatisticsWithMultipleSelections', function() { 50 var ctr = createCounterWithTwoSeries(); 51 var ret = ctr.getSampleStatistics([0, 1]); 52 53 assertEquals(5, ret[0].min); 54 assertEquals(6, ret[0].max); 55 assertEquals((5 + 6) / 2, ret[0].avg); 56 assertEquals(5, ret[0].start); 57 assertEquals(6, ret[0].end); 58 59 assertEquals(10, ret[1].min); 60 assertEquals(15, ret[1].max); 61 assertEquals((10 + 15) / 2, ret[1].avg); 62 assertEquals(10, ret[1].start); 63 assertEquals(15, ret[1].end); 64 }); 65 66 test('getSampleStatisticsWithOutofOrderIndices', function() { 67 var ctr = createCounterWithTwoSeries(); 68 var ret = ctr.getSampleStatistics([1, 0]); 69 70 assertEquals(5, ret[0].min); 71 assertEquals(6, ret[0].max); 72 assertEquals((5 + 6) / 2, ret[0].avg); 73 assertEquals(5, ret[0].start); 74 assertEquals(6, ret[0].end); 75 76 assertEquals(10, ret[1].min); 77 assertEquals(15, ret[1].max); 78 assertEquals((10 + 15) / 2, ret[1].avg); 79 assertEquals(10, ret[1].start); 80 assertEquals(15, ret[1].end); 81 }); 82 83 test('getSampleStatisticsWithAllSelections', function() { 84 var ctr = createCounterWithTwoSeries(); 85 var ret = ctr.getSampleStatistics([1, 0, 2, 3]); 86 87 assertEquals(5, ret[0].min); 88 assertEquals(7, ret[0].max); 89 assertEquals((5 + 6 + 5 + 7) / 4, ret[0].avg); 90 assertEquals(5, ret[0].start); 91 assertEquals(7, ret[0].end); 92 93 assertEquals(10, ret[1].min); 94 assertEquals(16, ret[1].max); 95 assertEquals((10 + 15 + 12 + 16) / 4, ret[1].avg); 96 assertEquals(10, ret[1].start); 97 assertEquals(16, ret[1].end); 98 }); 99 }); 100