1 /******************************************************************************
2 *
3 * Copyright 2021 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <gtest/gtest.h>
20
21 #include "common/multi_priority_queue.h"
22
23 namespace bluetooth {
24 namespace common {
25
TEST(MultiPriorityQueueTest,without_high_priority_item)26 TEST(MultiPriorityQueueTest, without_high_priority_item) {
27 common::MultiPriorityQueue<int, 2> q;
28 ASSERT_TRUE(q.empty());
29 q.push(0);
30 q.push(1, 0);
31 q.push(2);
32 ASSERT_EQ(q.size(), 3);
33 for (int i = 0; i < 3; i++) {
34 ASSERT_EQ(q.front(), i);
35 q.pop();
36 }
37 ASSERT_TRUE(q.empty());
38 }
39
TEST(MultiPriorityQueueTest,with_high_priority_item)40 TEST(MultiPriorityQueueTest, with_high_priority_item) {
41 common::MultiPriorityQueue<int, 2> q;
42 q.push(1);
43 q.push(2);
44 q.push(0, 1);
45 for (int i = 0; i < 3; i++) {
46 ASSERT_EQ(q.front(), i);
47 q.pop();
48 }
49 }
50
TEST(MultiPriorityQueueTest,with_multiple_priority_item)51 TEST(MultiPriorityQueueTest, with_multiple_priority_item) {
52 common::MultiPriorityQueue<int, 3> q;
53 q.push(1, 1);
54 q.push(0, 2);
55 q.push(2, 0);
56 for (int i = 0; i < 3; i++) {
57 ASSERT_EQ(q.front(), i);
58 q.pop();
59 }
60 }
61
62 } // namespace common
63 } // namespace bluetooth
64