• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2022 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {RunningStatistics} from './perf';
16
17test('buffer size is accurate before reaching max capacity', () => {
18  const buf = new RunningStatistics(10);
19
20  for (let i = 0; i < 10; i++) {
21    buf.addValue(i);
22    expect(buf.bufferSize).toEqual(i + 1);
23  }
24});
25
26test('buffer size is accurate after reaching max capacity', () => {
27  const buf = new RunningStatistics(10);
28
29  for (let i = 0; i < 10; i++) {
30    buf.addValue(i);
31  }
32
33  for (let i = 0; i < 10; i++) {
34    buf.addValue(i);
35    expect(buf.bufferSize).toEqual(10);
36  }
37});
38
39test('buffer mean is accurate before reaching max capacity', () => {
40  const buf = new RunningStatistics(10);
41
42  buf.addValue(1);
43  buf.addValue(2);
44  buf.addValue(3);
45
46  expect(buf.bufferMean).toBeCloseTo(2);
47});
48
49test('buffer mean is accurate after reaching max capacity', () => {
50  const buf = new RunningStatistics(10);
51
52  for (let i = 0; i < 20; i++) {
53    buf.addValue(2);
54  }
55
56  expect(buf.bufferMean).toBeCloseTo(2);
57});
58