| 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 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(PriorityQueueTest, LastMaxOrderErase) { | 100 TEST_F(PriorityQueueTest, LastMaxOrderErase) { |
| 101 for (size_t i = 0; i < kNumElements; ++i) { | 101 for (size_t i = 0; i < kNumElements; ++i) { |
| 102 EXPECT_EQ(kLastMaxOrderErase[i], queue_.LastMax().value()); | 102 EXPECT_EQ(kLastMaxOrderErase[i], queue_.LastMax().value()); |
| 103 queue_.Erase(queue_.LastMax()); | 103 queue_.Erase(queue_.LastMax()); |
| 104 } | 104 } |
| 105 CheckEmpty(); | 105 CheckEmpty(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST_F(PriorityQueueTest, NextHighestIteration) { |
| 109 PriorityQueue<int>::Pointer current = queue_.FirstMax(); |
| 110 for (size_t i = 0; i < kNumElements; ++i) { |
| 111 EXPECT_FALSE(current.is_null()); |
| 112 EXPECT_EQ(kFirstMaxOrder[i], current.value()); |
| 113 current = queue_.NextHighest(current); |
| 114 } |
| 115 EXPECT_TRUE(current.is_null()); |
| 116 } |
| 117 |
| 118 TEST_F(PriorityQueueTest, NextHighestIterationWithDeletion) { |
| 119 PriorityQueue<int>::Pointer current = queue_.FirstMax(); |
| 120 for (size_t i = 0; i < kNumElements; ++i) { |
| 121 EXPECT_FALSE(current.is_null()); |
| 122 EXPECT_EQ(kFirstMaxOrder[i], current.value()); |
| 123 PriorityQueue<int>::Pointer next = queue_.NextHighest(current); |
| 124 queue_.Erase(current); |
| 125 current = next; |
| 126 } |
| 127 EXPECT_TRUE(current.is_null()); |
| 128 CheckEmpty(); |
| 129 } |
| 130 |
| 108 TEST_F(PriorityQueueTest, EraseFromMiddle) { | 131 TEST_F(PriorityQueueTest, EraseFromMiddle) { |
| 109 queue_.Erase(pointers_[2]); | 132 queue_.Erase(pointers_[2]); |
| 110 queue_.Erase(pointers_[3]); | 133 queue_.Erase(pointers_[3]); |
| 111 | 134 |
| 112 const int expected_order[] = { 8, 1, 6, 0, 5, 4, 7 }; | 135 const int expected_order[] = { 8, 1, 6, 0, 5, 4, 7 }; |
| 113 | 136 |
| 114 for (size_t i = 0; i < arraysize(expected_order); ++i) { | 137 for (size_t i = 0; i < arraysize(expected_order); ++i) { |
| 115 EXPECT_EQ(expected_order[i], queue_.FirstMin().value()); | 138 EXPECT_EQ(expected_order[i], queue_.FirstMin().value()); |
| 116 queue_.Erase(queue_.FirstMin()); | 139 queue_.Erase(queue_.FirstMin()); |
| 117 } | 140 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 for (size_t i = 0; i < arraysize(expected_order); ++i) { | 152 for (size_t i = 0; i < arraysize(expected_order); ++i) { |
| 130 EXPECT_EQ(expected_order[i], queue_.FirstMin().value()); | 153 EXPECT_EQ(expected_order[i], queue_.FirstMin().value()); |
| 131 queue_.Erase(queue_.FirstMin()); | 154 queue_.Erase(queue_.FirstMin()); |
| 132 } | 155 } |
| 133 CheckEmpty(); | 156 CheckEmpty(); |
| 134 } | 157 } |
| 135 | 158 |
| 136 } // namespace | 159 } // namespace |
| 137 | 160 |
| 138 } // namespace net | 161 } // namespace net |
| OLD | NEW |