Home | History | Annotate | Download | only in src
      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
      5 Use of this source code is governed by a BSD-style license that can be
      6 found in the LICENSE file.
      7 -->
      8 <head>
      9 <title>TimelineCounter tests</title>
     10 <script src="base.js"></script>
     11 <script>
     12   base.require('unittest');
     13   base.require('test_utils');
     14   base.require('timeline_counter');
     15 </script>
     16 </head>
     17 <body>
     18 <script>
     19   'use strict';
     20 
     21   var TimelineCounter = tracing.TimelineCounter;
     22 
     23 
     24 
     25 
     26   function createCounterWithTwoSeries() {
     27     var ctr = new TimelineCounter(null, 0, '', 'myCounter');
     28     ctr.seriesNames.push('a', 'b');
     29     ctr.seriesColors.push(0, 1);
     30     ctr.timestamps.push(0, 1, 2, 3);
     31     ctr.samples.push(5, 10, 6, 15, 5, 12, 7, 16);
     32     return ctr;
     33   }
     34 
     35   function testGetSampleStatisticsWithSingleSelection() {
     36     var ctr = createCounterWithTwoSeries();
     37     var ret = ctr.getSampleStatistics([0]);
     38 
     39     assertEquals(5, ret[0].min);
     40     assertEquals(5, ret[0].max);
     41     assertEquals(5, ret[0].avg);
     42     assertEquals(5, ret[0].start);
     43     assertEquals(5, ret[0].end);
     44 
     45     assertEquals(10, ret[1].min);
     46     assertEquals(10, ret[1].max);
     47     assertEquals(10, ret[1].avg);
     48     assertEquals(10, ret[1].start);
     49     assertEquals(10, ret[1].end);
     50   }
     51 
     52   function testGetSampleStatisticsWithMultipleSelections() {
     53     var ctr = createCounterWithTwoSeries();
     54     var ret = ctr.getSampleStatistics([0, 1]);
     55 
     56     assertEquals(5, ret[0].min);
     57     assertEquals(6, ret[0].max);
     58     assertEquals((5 + 6) / 2, ret[0].avg);
     59     assertEquals(5, ret[0].start);
     60     assertEquals(6, ret[0].end);
     61 
     62     assertEquals(10, ret[1].min);
     63     assertEquals(15, ret[1].max);
     64     assertEquals((10 + 15) / 2, ret[1].avg);
     65     assertEquals(10, ret[1].start);
     66     assertEquals(15, ret[1].end);
     67   }
     68 
     69   function testGetSampleStatisticsWithOutofOrderIndices() {
     70     var ctr = createCounterWithTwoSeries();
     71     var ret = ctr.getSampleStatistics([1, 0]);
     72 
     73     assertEquals(5, ret[0].min);
     74     assertEquals(6, ret[0].max);
     75     assertEquals((5 + 6) / 2, ret[0].avg);
     76     assertEquals(5, ret[0].start);
     77     assertEquals(6, ret[0].end);
     78 
     79     assertEquals(10, ret[1].min);
     80     assertEquals(15, ret[1].max);
     81     assertEquals((10 + 15) / 2, ret[1].avg);
     82     assertEquals(10, ret[1].start);
     83     assertEquals(15, ret[1].end);
     84   }
     85 
     86   function testGetSampleStatisticsWithAllSelections() {
     87     var ctr = createCounterWithTwoSeries();
     88     var ret = ctr.getSampleStatistics([1, 0, 2, 3]);
     89 
     90     assertEquals(5, ret[0].min);
     91     assertEquals(7, ret[0].max);
     92     assertEquals((5 + 6 + 5 + 7) / 4, ret[0].avg);
     93     assertEquals(5, ret[0].start);
     94     assertEquals(7, ret[0].end);
     95 
     96     assertEquals(10, ret[1].min);
     97     assertEquals(16, ret[1].max);
     98     assertEquals((10 + 15 + 12 + 16) / 4, ret[1].avg);
     99     assertEquals(10, ret[1].start);
    100     assertEquals(16, ret[1].end);
    101   }
    102 
    103 </script>
    104 </body>
    105 </html>
    106