[PATCH] D37241: [unittests] Add reverse iteration unit tests for pointer-like keys
Mandeep Singh Grang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 28 18:12:28 PDT 2017
mgrang created this revision.
Repository:
rL LLVM
https://reviews.llvm.org/D37241
Files:
unittests/Support/ReverseIterationTest.cpp
Index: unittests/Support/ReverseIterationTest.cpp
===================================================================
--- unittests/Support/ReverseIterationTest.cpp
+++ unittests/Support/ReverseIterationTest.cpp
@@ -12,6 +12,7 @@
//===---------------------------------------------------------------------===//
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/ReverseIteration.h"
#include "gtest/gtest.h"
@@ -53,3 +54,57 @@
for (auto iter = Map.begin(), end = Map.end(); iter != end; iter++, ++i)
ASSERT_EQ(iter->first, IterKeys[i]);
}
+
+TEST(ReverseIterationTest, DenseMapTest2) {
+ struct PtrLike { int a, b, c, d; } P = { 4, 8, 12, 16 };
+ static_assert(detail::IsPointerLike<PtrLike *>::value,
+ "ptrlike * is pointer-like");
+ int *Keys[] = { &P.a, &P.b, &P.c, &P.d };
+
+ // Insert keys into the DenseMap.
+ DenseMap<int *, int> Map;
+ for (auto *Key : Keys)
+ Map[Key] = *Key;
+
+ // Note: This is the observed order of keys in the DenseMap.
+ // If there is any change in the behavior of the DenseMap, this order
+ // would need to be adjusted accordingly.
+ int IterKeys[] = { P.a, P.b, P.c, P.d };
+ if (shouldReverseIterate<int *>())
+ std::reverse(&IterKeys[0], &IterKeys[4]);
+
+ // Check that the DenseMap is iterated in the expected order.
+ for (const auto &Tuple : zip(Map, IterKeys))
+ ASSERT_EQ(std::get<0>(Tuple).second, std::get<1>(Tuple));
+
+ // Check operator++ (post-increment).
+ int i = 0;
+ for (auto iter = Map.begin(), end = Map.end(); iter != end; iter++, ++i)
+ ASSERT_EQ(iter->second, IterKeys[i]);
+}
+
+TEST(ReverseIterationTest, SmallPtrSetTest) {
+ struct PtrLike { int a, b, c, d; } P = { 4, 8, 12, 16 };
+ int *Keys[] = { &P.a, &P.b, &P.c, &P.d };
+
+ // Insert keys into the SmallPtrSet.
+ SmallPtrSet<int *, 4> Set;
+ for (auto *Key: Keys)
+ Set.insert(Key);
+
+ // Note: This is the observed order of keys in the SmallPtrSet.
+ // If there is any change in the behavior of the SmallPtrSet, this
+ // order would need to be adjusted accordingly.
+ int IterKeys[] = { P.a, P.b, P.c, P.d };
+ if (shouldReverseIterate<int *>())
+ std::reverse(&IterKeys[0], &IterKeys[4]);
+
+ // Check that the SmallPtrSet is iterated in the expected order.
+ for (const auto &Tuple : zip(Set, IterKeys))
+ ASSERT_EQ(*std::get<0>(Tuple), std::get<1>(Tuple));
+
+ // Check operator++ (post-increment).
+ int i = 0;
+ for (auto iter = Set.begin(), end = Set.end(); iter != end; iter++, ++i)
+ ASSERT_EQ(**iter, IterKeys[i]);
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37241.113002.patch
Type: text/x-patch
Size: 2575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170829/82e88666/attachment.bin>
More information about the llvm-commits
mailing list