summaryrefslogtreecommitdiff
path: root/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp')
-rw-r--r--Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp122
1 files changed, 109 insertions, 13 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp b/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp
index 7579c4299..d81dcfcfe 100644
--- a/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp
+++ b/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp
@@ -25,11 +25,12 @@
#include "config.h"
+#include "MoveOnly.h"
#include <wtf/ListHashSet.h>
namespace TestWebKitAPI {
-TEST(WTF, ListHashSetRemoveFirst)
+TEST(WTF_ListHashSet, RemoveFirst)
{
ListHashSet<int> list;
list.add(1);
@@ -48,7 +49,26 @@ TEST(WTF, ListHashSetRemoveFirst)
ASSERT_TRUE(list.isEmpty());
}
-TEST(WTF, ListHashSetAppendOrMoveToLastNewItems)
+TEST(WTF_ListHashSet, RemoveLast)
+{
+ ListHashSet<int> list;
+ list.add(1);
+ list.add(2);
+ list.add(3);
+
+ ASSERT_EQ(3, list.last());
+
+ list.removeLast();
+ ASSERT_EQ(2, list.last());
+
+ list.removeLast();
+ ASSERT_EQ(1, list.last());
+
+ list.removeLast();
+ ASSERT_TRUE(list.isEmpty());
+}
+
+TEST(WTF_ListHashSet, AppendOrMoveToLastNewItems)
{
ListHashSet<int> list;
ListHashSet<int>::AddResult result = list.appendOrMoveToLast(1);
@@ -58,7 +78,7 @@ TEST(WTF, ListHashSetAppendOrMoveToLastNewItems)
result = list.appendOrMoveToLast(3);
ASSERT_TRUE(result.isNewEntry);
- ASSERT_EQ(list.size(), 3);
+ ASSERT_EQ(list.size(), 3u);
// The list should be in order 1, 2, 3.
ListHashSet<int>::iterator iterator = list.begin();
@@ -70,7 +90,7 @@ TEST(WTF, ListHashSetAppendOrMoveToLastNewItems)
++iterator;
}
-TEST(WTF, ListHashSetAppendOrMoveToLastWithDuplicates)
+TEST(WTF_ListHashSet, AppendOrMoveToLastWithDuplicates)
{
ListHashSet<int> list;
@@ -79,11 +99,11 @@ TEST(WTF, ListHashSetAppendOrMoveToLastWithDuplicates)
ASSERT_TRUE(result.isNewEntry);
result = list.appendOrMoveToLast(1);
ASSERT_FALSE(result.isNewEntry);
- ASSERT_EQ(1, list.size());
+ ASSERT_EQ(1u, list.size());
list.add(2);
list.add(3);
- ASSERT_EQ(3, list.size());
+ ASSERT_EQ(3u, list.size());
// Appending 2 move it to the end.
ASSERT_EQ(3, list.last());
@@ -98,7 +118,7 @@ TEST(WTF, ListHashSetAppendOrMoveToLastWithDuplicates)
ASSERT_FALSE(result.isNewEntry);
result = list.appendOrMoveToLast(1);
ASSERT_FALSE(result.isNewEntry);
- ASSERT_EQ(3, list.size());
+ ASSERT_EQ(3u, list.size());
ListHashSet<int>::iterator iterator = list.begin();
ASSERT_EQ(3, *iterator);
@@ -109,7 +129,7 @@ TEST(WTF, ListHashSetAppendOrMoveToLastWithDuplicates)
++iterator;
}
-TEST(WTF, ListHashSetPrependOrMoveToLastNewItems)
+TEST(WTF_ListHashSet, PrependOrMoveToLastNewItems)
{
ListHashSet<int> list;
ListHashSet<int>::AddResult result = list.prependOrMoveToFirst(1);
@@ -119,7 +139,7 @@ TEST(WTF, ListHashSetPrependOrMoveToLastNewItems)
result = list.prependOrMoveToFirst(3);
ASSERT_TRUE(result.isNewEntry);
- ASSERT_EQ(list.size(), 3);
+ ASSERT_EQ(list.size(), 3u);
// The list should be in order 3, 1, 2.
ListHashSet<int>::iterator iterator = list.begin();
@@ -131,7 +151,7 @@ TEST(WTF, ListHashSetPrependOrMoveToLastNewItems)
++iterator;
}
-TEST(WTF, ListHashSetPrependOrMoveToLastWithDuplicates)
+TEST(WTF_ListHashSet, PrependOrMoveToLastWithDuplicates)
{
ListHashSet<int> list;
@@ -140,11 +160,11 @@ TEST(WTF, ListHashSetPrependOrMoveToLastWithDuplicates)
ASSERT_TRUE(result.isNewEntry);
result = list.prependOrMoveToFirst(1);
ASSERT_FALSE(result.isNewEntry);
- ASSERT_EQ(1, list.size());
+ ASSERT_EQ(1u, list.size());
list.add(2);
list.add(3);
- ASSERT_EQ(3, list.size());
+ ASSERT_EQ(3u, list.size());
// Prepending 2 move it to the beginning.
ASSERT_EQ(1, list.first());
@@ -159,7 +179,7 @@ TEST(WTF, ListHashSetPrependOrMoveToLastWithDuplicates)
ASSERT_FALSE(result.isNewEntry);
result = list.prependOrMoveToFirst(3);
ASSERT_FALSE(result.isNewEntry);
- ASSERT_EQ(3, list.size());
+ ASSERT_EQ(3u, list.size());
ListHashSet<int>::iterator iterator = list.begin();
ASSERT_EQ(3, *iterator);
@@ -170,4 +190,80 @@ TEST(WTF, ListHashSetPrependOrMoveToLastWithDuplicates)
++iterator;
}
+TEST(WTF_ListHashSet, ReverseIterator)
+{
+ ListHashSet<int> list;
+
+ list.add(1);
+ list.add(2);
+ list.add(3);
+
+ auto it = list.rbegin();
+ ASSERT_EQ(3, *it);
+ ++it;
+ ASSERT_EQ(2, *it);
+ ++it;
+ ASSERT_EQ(1, *it);
+ ++it;
+ ASSERT_TRUE(it == list.rend());
+
+ const auto& listHashSet = list;
+
+ auto constIt = listHashSet.rbegin();
+ ASSERT_EQ(3, *constIt);
+ ++constIt;
+ ASSERT_EQ(2, *constIt);
+ ++constIt;
+ ASSERT_EQ(1, *constIt);
+ ++constIt;
+ ASSERT_TRUE(constIt == listHashSet.rend());
+}
+
+TEST(WTF_ListHashSet, MoveOnly)
+{
+ ListHashSet<MoveOnly> list;
+ list.add(MoveOnly(2));
+ list.add(MoveOnly(4));
+
+ // { 2, 4 }
+ ASSERT_EQ(2U, list.first().value());
+ ASSERT_EQ(4U, list.last().value());
+
+ list.appendOrMoveToLast(MoveOnly(3));
+
+ // { 2, 4, 3 }
+ ASSERT_EQ(3U, list.last().value());
+
+ // { 4, 3, 2 }
+ list.appendOrMoveToLast(MoveOnly(2));
+ ASSERT_EQ(4U, list.first().value());
+ ASSERT_EQ(2U, list.last().value());
+
+ list.prependOrMoveToFirst(MoveOnly(5));
+
+ // { 5, 2, 4, 3 }
+ ASSERT_EQ(5U, list.first().value());
+
+ list.prependOrMoveToFirst(MoveOnly(3));
+
+ // { 3, 5, 4, 2 }
+ ASSERT_EQ(3U, list.first().value());
+ ASSERT_EQ(2U, list.last().value());
+
+ list.insertBefore(MoveOnly(4), MoveOnly(1));
+ list.insertBefore(list.end(), MoveOnly(6));
+
+ // { 3, 5, 1, 4, 2, 6 }
+ ASSERT_EQ(3U, list.takeFirst().value());
+ ASSERT_EQ(5U, list.takeFirst().value());
+ ASSERT_EQ(1U, list.takeFirst().value());
+
+ // { 4, 2, 6 }
+ ASSERT_EQ(6U, list.takeLast().value());
+ ASSERT_EQ(2U, list.takeLast().value());
+ ASSERT_EQ(4U, list.takeLast().value());
+
+ ASSERT_TRUE(list.isEmpty());
+}
+
} // namespace TestWebKitAPI