Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: third_party/WebKit/Source/wtf/FlatSetTest.cpp

Issue 2396533004: Introduce a FlatMap and FlatSet into WTF (Closed)
Patch Set: Add missing ostream override Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/FlatSet.h ('k') | third_party/WebKit/Source/wtf/FlatTable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "wtf/FlatSet.h"
6
7 #include "testing/gmock/include/gmock/gmock.h"
8
9 using testing::ElementsAre;
10
11 namespace WTF {
12
13 TEST(FlatSetTest, Basic) {
14 FlatSet<int> set;
15 EXPECT_TRUE(set.empty());
16 EXPECT_EQ(0ul, set.size());
17 }
18
19 TEST(FlatSetTest, InsertBasic) {
20 FlatSet<int> set;
21
22 EXPECT_TRUE(set.insert(1).second);
23 EXPECT_FALSE(set.empty());
24 EXPECT_EQ(1ul, set.size());
25 EXPECT_EQ(1, *set.find(1));
26
27 EXPECT_FALSE(set.insert(1).second);
28 }
29
30 TEST(FlatSetTest, InsertAndFind) {
31 FlatSet<int> set;
32
33 for (int i = 0; i < 50; i++)
34 set.insert(i * 2);
35
36 EXPECT_EQ(50ul, set.size());
37
38 for (int i = 0; i < 50; i++) {
39 EXPECT_TRUE(set.find(i * 2) != set.end()) << "i = " << i;
40 EXPECT_FALSE(set.find(i * 2 + 1) != set.end()) << "i = " << i;
41 }
42 }
43
44 TEST(FlatSetTest, InsertUniqueAndFind) {
45 FlatSet<int> set;
46
47 for (int i = 0; i < 50; i++)
48 set.insertUnique(i * 2);
49
50 EXPECT_EQ(50ul, set.size());
51
52 for (int i = 0; i < 50; i++) {
53 EXPECT_TRUE(set.find(i * 2) != set.end()) << "i = " << i;
54 EXPECT_FALSE(set.find(i * 2 + 1) != set.end()) << "i = " << i;
55 }
56 }
57
58 TEST(FlatSetTest, EraseIterator) {
59 FlatSet<int> set;
60
61 for (int i = 0; i < 50; i++)
62 set.insertUnique(i * 2);
63
64 for (size_t i = 0; !set.empty(); i++) {
65 EXPECT_EQ(50ul - i, set.size());
66 EXPECT_EQ(static_cast<int>(i * 2), *set.begin());
67 EXPECT_EQ(98, *set.rbegin());
68 set.erase(set.begin());
69 }
70 }
71
72 TEST(FlatSetTest, EraseReverseIterator) {
73 FlatSet<int> set;
74
75 for (int i = 0; i < 50; i++)
76 set.insertUnique(i * 2);
77
78 for (size_t i = 0; !set.empty(); i++) {
79 EXPECT_EQ(50ul - i, set.size());
80 EXPECT_EQ(0, *set.begin());
81 EXPECT_EQ(static_cast<int>((49 - i) * 2), *set.rbegin());
82 set.erase(set.rbegin());
83 }
84
85 EXPECT_TRUE(set.empty());
86 }
87
88 TEST(FlatSetTest, EraseAllButOneThenInsertOne) {
89 FlatSet<int> set;
90
91 set.insert(1);
92 set.insert(2);
93 set.insert(3);
94 set.insert(4);
95 set.insert(5);
96
97 set.erase(1);
98 set.erase(2);
99 set.erase(3);
100 set.erase(4);
101
102 EXPECT_TRUE(set.find(5) != set.end());
103
104 set.insert(6);
105 EXPECT_TRUE(set.find(6) != set.end());
106 }
107
108 TEST(FlatSetTest, Iterators) {
109 FlatSet<int> set;
110
111 set.insert(5);
112 set.insert(4);
113 set.insert(1);
114 set.insert(6);
115 set.insert(2);
116 set.insert(7);
117 set.insert(3);
118
119 EXPECT_NE(set.begin(), set.end());
120 EXPECT_NE(set.rbegin(), set.rend());
121
122 auto it = set.begin();
123 EXPECT_EQ(1, *it++);
124 EXPECT_EQ(2, *it++);
125 EXPECT_EQ(3, *it++);
126 EXPECT_EQ(4, *it++);
127 EXPECT_EQ(5, *it++);
128 EXPECT_EQ(6, *it++);
129 EXPECT_EQ(7, *it++);
130 EXPECT_EQ(set.end(), it);
131
132 auto rit = set.rbegin();
133 EXPECT_EQ(7, *rit++);
134 EXPECT_EQ(6, *rit++);
135 EXPECT_EQ(5, *rit++);
136 EXPECT_EQ(4, *rit++);
137 EXPECT_EQ(3, *rit++);
138 EXPECT_EQ(2, *rit++);
139 EXPECT_EQ(1, *rit++);
140 EXPECT_EQ(set.rend(), rit);
141 }
142
143 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/FlatSet.h ('k') | third_party/WebKit/Source/wtf/FlatTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698