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

Unified Diff: Source/wtf/ListHashSetTest.cpp

Issue 474943002: Fix for LinkedHashSet::swap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: templated test Created 6 years, 4 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 | « Source/wtf/LinkedHashSet.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/ListHashSetTest.cpp
diff --git a/Source/wtf/ListHashSetTest.cpp b/Source/wtf/ListHashSetTest.cpp
index cd258ea4c2687c2aa6d2ef545ad175e85eab2b7a..a1f6a66f83604a86620a05f48b1d886315b6f1ba 100644
--- a/Source/wtf/ListHashSetTest.cpp
+++ b/Source/wtf/ListHashSetTest.cpp
@@ -656,4 +656,66 @@ TEST(ListHashSetTest, WithOwnPtr)
EXPECT_EQ(ptr2, ownPtr2);
}
+template<typename Set>
+void swapTestHelper()
+{
+ int num = 10;
+ Set set0;
+ Set set1;
+ Set set2;
+ for (int i = 0; i < num; ++i) {
+ set1.add(i + 1);
+ set2.add(num - i);
+ }
+
+ typename Set::iterator it1 = set1.begin();
+ typename Set::iterator it2 = set2.begin();
+ for (int i = 0; i < num; ++i, ++it1, ++it2) {
+ EXPECT_EQ(*it1, i + 1);
+ EXPECT_EQ(*it2, num - i);
+ }
+ EXPECT_EQ(set0.begin(), set0.end());
+ EXPECT_EQ(it1, set1.end());
+ EXPECT_EQ(it2, set2.end());
+
+ // Shift sets: 2->1, 1->0, 0->2
+ set1.swap(set2); // Swap with non-empty sets.
+ set0.swap(set2); // Swap with an empty set.
+
+ it1 = set0.begin();
+ it2 = set1.begin();
+ for (int i = 0; i < num; ++i, ++it1, ++it2) {
+ EXPECT_EQ(*it1, i + 1);
+ EXPECT_EQ(*it2, num - i);
+ }
+ EXPECT_EQ(it1, set0.end());
+ EXPECT_EQ(it2, set1.end());
+ EXPECT_EQ(set2.begin(), set2.end());
+
+ int removedIndex = num >> 1;
+ set0.remove(removedIndex + 1);
+ set1.remove(num - removedIndex);
+
+ it1 = set0.begin();
+ it2 = set1.begin();
+ for (int i = 0; i < num; ++i, ++it1, ++it2) {
+ if (i == removedIndex)
+ ++i;
+ EXPECT_EQ(*it1, i + 1);
+ EXPECT_EQ(*it2, num - i);
+ }
+ EXPECT_EQ(it1, set0.end());
+ EXPECT_EQ(it2, set1.end());
+}
+
+TEST(ListHashSetTest, Swap)
+{
+ swapTestHelper<ListHashSet<int> >();
+}
+
+TEST(LinkedHashSetTest, Swap)
+{
+ swapTestHelper<LinkedHashSet<int> >();
+}
+
} // namespace
« no previous file with comments | « Source/wtf/LinkedHashSet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698