From: Mandeep Singh Grang Date: Fri, 25 Aug 2017 01:11:28 +0000 (+0000) Subject: [unittests] Remove reverse iteration tests which use pointer-like keys X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=109cbe502f3aa2e2b0856cc105374288a0be981e;p=llvm [unittests] Remove reverse iteration tests which use pointer-like keys Summary: The expected order of pointer-like keys is hash-function-dependent which in turn depends on the platform/environment. Need to come up with a better way to test reverse iteration of containers with pointer-like keys. Reviewers: dblaikie, mehdi_amini, efriedma, mgrang Reviewed By: mgrang Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37128 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311741 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/Support/ReverseIterationTest.cpp b/unittests/Support/ReverseIterationTest.cpp index 486c928e47f..41205958f41 100644 --- a/unittests/Support/ReverseIterationTest.cpp +++ b/unittests/Support/ReverseIterationTest.cpp @@ -12,7 +12,6 @@ //===---------------------------------------------------------------------===// #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/ReverseIteration.h" #include "gtest/gtest.h" @@ -23,41 +22,14 @@ TEST(ReverseIterationTest, DenseMapTest1) { "int * is pointer-like"); static_assert(detail::IsPointerLike::value, "uintptr_t is pointer-like"); + static_assert(!detail::IsPointerLike::value, + "int is not pointer-like"); + static_assert(detail::IsPointerLike::value, + "void * is pointer-like"); struct IncompleteType; static_assert(detail::IsPointerLike::value, "incomplete * is pointer-like"); - // Test reverse iteration for a DenseMap with pointer-like keys. - // DenseMap should reverse iterate if its keys are pointer-like. - DenseMap Map; - int a = 1, b = 2, c = 3, d = 4; - int *Keys[] = { &a, &b, &c, &d }; - - // Insert keys into the DenseMap. - for (auto *Key: Keys) - Map[Key] = 0; - - // 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[] = { &a, &b, &c, &d }; - if (shouldReverseIterate()) - 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).first), *(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->first, IterKeys[i]); -} - -TEST(ReverseIterationTest, DenseMapTest2) { - static_assert(!detail::IsPointerLike::value, - "int is not pointer-like"); - // For a DenseMap with non-pointer-like keys, forward iteration equals // reverse iteration. DenseMap Map; @@ -81,31 +53,3 @@ TEST(ReverseIterationTest, DenseMapTest2) { for (auto iter = Map.begin(), end = Map.end(); iter != end; iter++, ++i) ASSERT_EQ(iter->first, IterKeys[i]); } - -TEST(ReverseIterationTest, SmallPtrSetTest) { - static_assert(detail::IsPointerLike::value, - "void * is pointer-like"); - - SmallPtrSet Set; - int a = 1, b = 2, c = 3, d = 4; - int *Ptrs[] = { &a, &b, &c, &d }; - - for (auto *Ptr: Ptrs) - Set.insert(Ptr); - - // 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 *IterPtrs[] = { &a, &b, &c, &d }; - if (shouldReverseIterate()) - std::reverse(&IterPtrs[0], &IterPtrs[4]); - - // Check that the SmallPtrSet is iterated in the expected order. - for (const auto &Tuple : zip(Set, IterPtrs)) - 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, IterPtrs[i]); -}