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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/FlatSetTest.cpp
diff --git a/third_party/WebKit/Source/wtf/FlatSetTest.cpp b/third_party/WebKit/Source/wtf/FlatSetTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..29ebe83dbced9bfa72fc07b4e4d847c116977ffe
--- /dev/null
+++ b/third_party/WebKit/Source/wtf/FlatSetTest.cpp
@@ -0,0 +1,143 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "wtf/FlatSet.h"
+
+#include "testing/gmock/include/gmock/gmock.h"
+
+using testing::ElementsAre;
+
+namespace WTF {
+
+TEST(FlatSetTest, Basic) {
+ FlatSet<int> set;
+ EXPECT_TRUE(set.empty());
+ EXPECT_EQ(0ul, set.size());
+}
+
+TEST(FlatSetTest, InsertBasic) {
+ FlatSet<int> set;
+
+ EXPECT_TRUE(set.insert(1).second);
+ EXPECT_FALSE(set.empty());
+ EXPECT_EQ(1ul, set.size());
+ EXPECT_EQ(1, *set.find(1));
+
+ EXPECT_FALSE(set.insert(1).second);
+}
+
+TEST(FlatSetTest, InsertAndFind) {
+ FlatSet<int> set;
+
+ for (int i = 0; i < 50; i++)
+ set.insert(i * 2);
+
+ EXPECT_EQ(50ul, set.size());
+
+ for (int i = 0; i < 50; i++) {
+ EXPECT_TRUE(set.find(i * 2) != set.end()) << "i = " << i;
+ EXPECT_FALSE(set.find(i * 2 + 1) != set.end()) << "i = " << i;
+ }
+}
+
+TEST(FlatSetTest, InsertUniqueAndFind) {
+ FlatSet<int> set;
+
+ for (int i = 0; i < 50; i++)
+ set.insertUnique(i * 2);
+
+ EXPECT_EQ(50ul, set.size());
+
+ for (int i = 0; i < 50; i++) {
+ EXPECT_TRUE(set.find(i * 2) != set.end()) << "i = " << i;
+ EXPECT_FALSE(set.find(i * 2 + 1) != set.end()) << "i = " << i;
+ }
+}
+
+TEST(FlatSetTest, EraseIterator) {
+ FlatSet<int> set;
+
+ for (int i = 0; i < 50; i++)
+ set.insertUnique(i * 2);
+
+ for (size_t i = 0; !set.empty(); i++) {
+ EXPECT_EQ(50ul - i, set.size());
+ EXPECT_EQ(static_cast<int>(i * 2), *set.begin());
+ EXPECT_EQ(98, *set.rbegin());
+ set.erase(set.begin());
+ }
+}
+
+TEST(FlatSetTest, EraseReverseIterator) {
+ FlatSet<int> set;
+
+ for (int i = 0; i < 50; i++)
+ set.insertUnique(i * 2);
+
+ for (size_t i = 0; !set.empty(); i++) {
+ EXPECT_EQ(50ul - i, set.size());
+ EXPECT_EQ(0, *set.begin());
+ EXPECT_EQ(static_cast<int>((49 - i) * 2), *set.rbegin());
+ set.erase(set.rbegin());
+ }
+
+ EXPECT_TRUE(set.empty());
+}
+
+TEST(FlatSetTest, EraseAllButOneThenInsertOne) {
+ FlatSet<int> set;
+
+ set.insert(1);
+ set.insert(2);
+ set.insert(3);
+ set.insert(4);
+ set.insert(5);
+
+ set.erase(1);
+ set.erase(2);
+ set.erase(3);
+ set.erase(4);
+
+ EXPECT_TRUE(set.find(5) != set.end());
+
+ set.insert(6);
+ EXPECT_TRUE(set.find(6) != set.end());
+}
+
+TEST(FlatSetTest, Iterators) {
+ FlatSet<int> set;
+
+ set.insert(5);
+ set.insert(4);
+ set.insert(1);
+ set.insert(6);
+ set.insert(2);
+ set.insert(7);
+ set.insert(3);
+
+ EXPECT_NE(set.begin(), set.end());
+ EXPECT_NE(set.rbegin(), set.rend());
+
+ auto it = set.begin();
+ EXPECT_EQ(1, *it++);
+ EXPECT_EQ(2, *it++);
+ EXPECT_EQ(3, *it++);
+ EXPECT_EQ(4, *it++);
+ EXPECT_EQ(5, *it++);
+ EXPECT_EQ(6, *it++);
+ EXPECT_EQ(7, *it++);
+ EXPECT_EQ(set.end(), it);
+
+ auto rit = set.rbegin();
+ EXPECT_EQ(7, *rit++);
+ EXPECT_EQ(6, *rit++);
+ EXPECT_EQ(5, *rit++);
+ EXPECT_EQ(4, *rit++);
+ EXPECT_EQ(3, *rit++);
+ EXPECT_EQ(2, *rit++);
+ EXPECT_EQ(1, *rit++);
+ EXPECT_EQ(set.rend(), rit);
+}
+
+} // namespace WTF
« 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