OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/priority_queue.h" | 5 #include "net/base/priority_queue.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 typedef PriorityQueue<int>::Priority Priority; | 15 typedef PriorityQueue<int>::Priority Priority; |
16 const Priority kPriorities[] = { 2, 1, 2, 0, 4, 3, 1, 4, 0 }; | 16 const Priority kPriorities[] = { 2, 1, 2, 0, 4, 3, 1, 4, 0 }; |
17 const Priority kNumPriorities = 5; // max(kPriorities) + 1 | 17 const Priority kNumPriorities = 5; // max(kPriorities) + 1 |
18 const size_t kNumElements = arraysize(kPriorities); | 18 const size_t kNumElements = arraysize(kPriorities); |
19 const int kFirstMinOrder[kNumElements] = { 3, 8, 1, 6, 0, 2, 5, 4, 7 }; | 19 const int kFirstMinOrder[kNumElements] = { 3, 8, 1, 6, 0, 2, 5, 4, 7 }; |
20 const int kLastMaxOrderErase[kNumElements] = { 7, 4, 5, 2, 0, 6, 1, 8, 3 }; | 20 const int kLastMaxOrderErase[kNumElements] = { 7, 4, 5, 2, 0, 6, 1, 8, 3 }; |
21 const int kFirstMaxOrder[kNumElements] = { 4, 7, 5, 0, 2, 1, 6, 3, 8 }; | 21 const int kFirstMaxOrder[kNumElements] = { 4, 7, 5, 0, 2, 1, 6, 3, 8 }; |
22 const int kLastMinOrder[kNumElements] = { 8, 3, 6, 1, 2, 0, 5, 7, 4 }; | 22 const int kLastMinOrder[kNumElements] = { 8, 3, 6, 1, 2, 0, 5, 7, 4 }; |
23 | 23 |
24 class PriorityQueueTest : public testing::Test { | 24 class PriorityQueueTest : public testing::Test { |
25 protected: | 25 protected: |
26 PriorityQueueTest() : queue_(kNumPriorities) {} | 26 PriorityQueueTest() : queue_(kNumPriorities) {} |
27 | 27 |
28 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() override { |
29 CheckEmpty(); | 29 CheckEmpty(); |
30 for (size_t i = 0; i < kNumElements; ++i) { | 30 for (size_t i = 0; i < kNumElements; ++i) { |
31 EXPECT_EQ(i, queue_.size()); | 31 EXPECT_EQ(i, queue_.size()); |
32 pointers_[i] = queue_.Insert(static_cast<int>(i), kPriorities[i]); | 32 pointers_[i] = queue_.Insert(static_cast<int>(i), kPriorities[i]); |
33 EXPECT_FALSE(queue_.empty()); | 33 EXPECT_FALSE(queue_.empty()); |
34 } | 34 } |
35 EXPECT_EQ(kNumElements, queue_.size()); | 35 EXPECT_EQ(kNumElements, queue_.size()); |
36 } | 36 } |
37 | 37 |
38 void CheckEmpty() { | 38 void CheckEmpty() { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 for (size_t i = 0; i < arraysize(expected_order); ++i) { | 142 for (size_t i = 0; i < arraysize(expected_order); ++i) { |
143 EXPECT_EQ(expected_order[i], queue_.FirstMin().value()); | 143 EXPECT_EQ(expected_order[i], queue_.FirstMin().value()); |
144 queue_.Erase(queue_.FirstMin()); | 144 queue_.Erase(queue_.FirstMin()); |
145 } | 145 } |
146 CheckEmpty(); | 146 CheckEmpty(); |
147 } | 147 } |
148 | 148 |
149 } // namespace | 149 } // namespace |
150 | 150 |
151 } // namespace net | 151 } // namespace net |
OLD | NEW |