• 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 {GRAY_COLOR} from '../common/colorizer';
16
17import {
18  filterVisibleSlicesForTesting as filterVisibleSlices,
19} from './base_slice_track';
20import {Slice} from './slice';
21
22function slice(start: number, duration: number): Slice {
23  return {
24    id: 42,
25    start: BigInt(start),
26    duration: BigInt(duration),
27    depth: 0,
28    flags: 0,
29    title: '',
30    subTitle: '',
31    baseColor: GRAY_COLOR,
32    color: GRAY_COLOR,
33  };
34}
35
36const s = slice;
37
38test('filterVisibleSlices', () => {
39  expect(filterVisibleSlices([], 0n, 100n)).toEqual([]);
40  expect(filterVisibleSlices([s(10, 80)], 0n, 100n)).toEqual([s(10, 80)]);
41  expect(filterVisibleSlices([s(0, 20)], 10n, 100n)).toEqual([s(0, 20)]);
42  expect(filterVisibleSlices([s(0, 10)], 10n, 100n)).toEqual([s(0, 10)]);
43  expect(filterVisibleSlices([s(100, 10)], 10n, 100n)).toEqual([s(100, 10)]);
44  expect(filterVisibleSlices([s(10, 0)], 10n, 100n)).toEqual([s(10, 0)]);
45  expect(filterVisibleSlices([s(100, 0)], 10n, 100n)).toEqual([s(100, 0)]);
46  expect(filterVisibleSlices([s(0, 5)], 10n, 90n)).toEqual([]);
47  expect(filterVisibleSlices([s(95, 5)], 10n, 90n)).toEqual([]);
48  expect(filterVisibleSlices([s(0, 5), s(95, 5)], 10n, 90n)).toEqual([]);
49  expect(filterVisibleSlices(
50             [
51               s(0, 5),
52               s(50, 0),
53               s(95, 5),
54             ],
55             10n,
56             90n))
57      .toEqual([
58        s(50, 0),
59      ]);
60  expect(filterVisibleSlices(
61             [
62               s(0, 5),
63               s(1, 9),
64               s(6, 3),
65             ],
66             10n,
67             90n))
68      .toContainEqual(s(1, 9));
69  expect(filterVisibleSlices(
70             [
71               s(0, 5),
72               s(1, 9),
73               s(6, 3),
74               s(50, 0),
75             ],
76             10n,
77             90n))
78      .toContainEqual(s(1, 9));
79  expect(filterVisibleSlices(
80             [
81               s(85, 10),
82               s(100, 10),
83             ],
84             10n,
85             90n))
86      .toEqual([
87        s(85, 10),
88      ]);
89  expect(filterVisibleSlices(
90             [
91               s(0, 100),
92
93             ],
94             10n,
95             90n))
96      .toEqual([
97        s(0, 100),
98      ]);
99  expect(filterVisibleSlices(
100             [
101               s(0, 1),
102               s(1, 1),
103               s(2, 1),
104               s(3, 1),
105               s(4, 1),
106               s(5, 10),
107               s(6, 1),
108               s(7, 1),
109               s(8, 1),
110               s(9, 1),
111             ],
112             10n,
113             90n))
114      .toContainEqual(s(5, 10));
115});
116