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" | 10 #include "base/containers/container_test_utils.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 // We do not declare operator< because clang complains that it's unused. | 31 // We do not declare operator< because clang complains that it's unused. |
32 }; | 32 }; |
33 | 33 |
34 A a; | 34 A a; |
35 } | 35 } |
36 | 36 |
37 TEST(FlatSet, RangeConstructor) { | 37 TEST(FlatSet, RangeConstructor) { |
38 flat_set<int>::value_type input_vals[] = {1, 1, 1, 2, 2, 2, 3, 3, 3}; | 38 flat_set<int>::value_type input_vals[] = {1, 1, 1, 2, 2, 2, 3, 3, 3}; |
39 | 39 |
40 flat_set<int> cont(std::begin(input_vals), std::end(input_vals)); | 40 flat_set<int> cont(std::begin(input_vals), std::end(input_vals), |
41 base::KEEP_FIRST_OF_DUPES); | |
danakj
2017/04/05 21:33:43
how come only keep first is tested?
brettw
2017/04/07 21:59:04
Since set is just a typedef for tree, most of the
| |
41 EXPECT_THAT(cont, ElementsAre(1, 2, 3)); | 42 EXPECT_THAT(cont, ElementsAre(1, 2, 3)); |
42 } | 43 } |
43 | 44 |
44 TEST(FlatSet, MoveConstructor) { | 45 TEST(FlatSet, MoveConstructor) { |
45 int input_range[] = {1, 2, 3, 4}; | 46 int input_range[] = {1, 2, 3, 4}; |
46 | 47 |
47 flat_set<MoveOnlyInt> original(std::begin(input_range), | 48 flat_set<MoveOnlyInt> original(std::begin(input_range), std::end(input_range), |
48 std::end(input_range)); | 49 base::KEEP_FIRST_OF_DUPES); |
49 flat_set<MoveOnlyInt> moved(std::move(original)); | 50 flat_set<MoveOnlyInt> moved(std::move(original)); |
50 | 51 |
51 EXPECT_EQ(1U, moved.count(MoveOnlyInt(1))); | 52 EXPECT_EQ(1U, moved.count(MoveOnlyInt(1))); |
52 EXPECT_EQ(1U, moved.count(MoveOnlyInt(2))); | 53 EXPECT_EQ(1U, moved.count(MoveOnlyInt(2))); |
53 EXPECT_EQ(1U, moved.count(MoveOnlyInt(3))); | 54 EXPECT_EQ(1U, moved.count(MoveOnlyInt(3))); |
54 EXPECT_EQ(1U, moved.count(MoveOnlyInt(4))); | 55 EXPECT_EQ(1U, moved.count(MoveOnlyInt(4))); |
55 } | 56 } |
56 | 57 |
57 TEST(FlatSet, InitializerListConstructor) { | 58 TEST(FlatSet, InitializerListConstructor) { |
58 flat_set<int> cont{1, 2, 3, 4, 5, 6, 10, 8}; | 59 flat_set<int> cont({1, 2, 3, 4, 5, 6, 10, 8}, KEEP_FIRST_OF_DUPES); |
59 EXPECT_THAT(cont, ElementsAre(1, 2, 3, 4, 5, 6, 8, 10)); | 60 EXPECT_THAT(cont, ElementsAre(1, 2, 3, 4, 5, 6, 8, 10)); |
60 } | 61 } |
61 | 62 |
62 TEST(FlatSet, InsertFindSize) { | 63 TEST(FlatSet, InsertFindSize) { |
63 base::flat_set<int> s; | 64 base::flat_set<int> s; |
64 s.insert(1); | 65 s.insert(1); |
65 s.insert(1); | 66 s.insert(1); |
66 s.insert(2); | 67 s.insert(2); |
67 | 68 |
68 EXPECT_EQ(2u, s.size()); | 69 EXPECT_EQ(2u, s.size()); |
(...skipping 14 matching lines...) Expand all Loading... | |
83 copy.erase(copy.begin()); | 84 copy.erase(copy.begin()); |
84 copy.insert(10); | 85 copy.insert(10); |
85 EXPECT_THAT(copy, ElementsAre(2, 10)); | 86 EXPECT_THAT(copy, ElementsAre(2, 10)); |
86 | 87 |
87 original.swap(copy); | 88 original.swap(copy); |
88 EXPECT_THAT(original, ElementsAre(2, 10)); | 89 EXPECT_THAT(original, ElementsAre(2, 10)); |
89 EXPECT_THAT(copy, ElementsAre(1, 2)); | 90 EXPECT_THAT(copy, ElementsAre(1, 2)); |
90 } | 91 } |
91 | 92 |
92 } // namespace base | 93 } // namespace base |
OLD | NEW |