| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/containers/flat_set.h" | 5 #include "base/containers/flat_set.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/containers/container_test_utils.h" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/test/move_only_int.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 // A flat_set is basically a interface to flat_tree. So several basic | 16 // A flat_set is basically a interface to flat_tree. So several basic |
| 16 // operations are tested to make sure things are set up properly, but the bulk | 17 // operations are tested to make sure things are set up properly, but the bulk |
| 17 // of the tests are in flat_tree_unittests.cc. | 18 // of the tests are in flat_tree_unittests.cc. |
| 18 | 19 |
| 19 using ::testing::ElementsAre; | 20 using ::testing::ElementsAre; |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 copy.erase(copy.begin()); | 85 copy.erase(copy.begin()); |
| 85 copy.insert(10); | 86 copy.insert(10); |
| 86 EXPECT_THAT(copy, ElementsAre(2, 10)); | 87 EXPECT_THAT(copy, ElementsAre(2, 10)); |
| 87 | 88 |
| 88 original.swap(copy); | 89 original.swap(copy); |
| 89 EXPECT_THAT(original, ElementsAre(2, 10)); | 90 EXPECT_THAT(original, ElementsAre(2, 10)); |
| 90 EXPECT_THAT(copy, ElementsAre(1, 2)); | 91 EXPECT_THAT(copy, ElementsAre(1, 2)); |
| 91 } | 92 } |
| 92 | 93 |
| 94 TEST(FlatSet, UsingTransparentCompare) { |
| 95 using ExplicitInt = base::MoveOnlyInt; |
| 96 base::flat_set<ExplicitInt> s; |
| 97 const auto& s1 = s; |
| 98 int x = 0; |
| 99 |
| 100 // Check if we can use lookup functions without converting to key_type. |
| 101 // Correctness is checked in flat_tree tests. |
| 102 s.count(x); |
| 103 s1.count(x); |
| 104 s.find(x); |
| 105 s1.find(x); |
| 106 s.equal_range(x); |
| 107 s1.equal_range(x); |
| 108 s.lower_bound(x); |
| 109 s1.lower_bound(x); |
| 110 s.upper_bound(x); |
| 111 s1.upper_bound(x); |
| 112 s.erase(x); |
| 113 |
| 114 // Check if we broke overload resolution. |
| 115 s.emplace(0); |
| 116 s.emplace(1); |
| 117 s.erase(s.begin()); |
| 118 s.erase(s.cbegin()); |
| 119 } |
| 120 |
| 93 } // namespace base | 121 } // namespace base |
| OLD | NEW |