llvm.org GIT mirror llvm / 109cbe5
[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 Mandeep Singh Grang 2 years ago
1 changed file(s) with 4 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
1111 //===---------------------------------------------------------------------===//
1212
1313 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallPtrSet.h"
1514 #include "llvm/Support/ReverseIteration.h"
1615 #include "gtest/gtest.h"
1716
2221 "int * is pointer-like");
2322 static_assert(detail::IsPointerLike::value,
2423 "uintptr_t is pointer-like");
24 static_assert(!detail::IsPointerLike::value,
25 "int is not pointer-like");
26 static_assert(detail::IsPointerLike::value,
27 "void * is pointer-like");
2528 struct IncompleteType;
2629 static_assert(detail::IsPointerLike::value,
2730 "incomplete * is pointer-like");
28
29 // Test reverse iteration for a DenseMap with pointer-like keys.
30 // DenseMap should reverse iterate if its keys are pointer-like.
31 DenseMap Map;
32 int a = 1, b = 2, c = 3, d = 4;
33 int *Keys[] = { &a, &b, &c, &d };
34
35 // Insert keys into the DenseMap.
36 for (auto *Key: Keys)
37 Map[Key] = 0;
38
39 // Note: This is the observed order of keys in the DenseMap.
40 // If there is any change in the behavior of the DenseMap, this order would
41 // need to be adjusted accordingly.
42 int *IterKeys[] = { &a, &b, &c, &d };
43 if (shouldReverseIterate())
44 std::reverse(&IterKeys[0], &IterKeys[4]);
45
46 // Check that the DenseMap is iterated in the expected order.
47 for (const auto &Tuple : zip(Map, IterKeys))
48 ASSERT_EQ(*(std::get<0>(Tuple).first), *(std::get<1>(Tuple)));
49
50 // Check operator++ (post-increment).
51 int i = 0;
52 for (auto iter = Map.begin(), end = Map.end(); iter != end; iter++, ++i)
53 ASSERT_EQ(iter->first, IterKeys[i]);
54 }
55
56 TEST(ReverseIterationTest, DenseMapTest2) {
57 static_assert(!detail::IsPointerLike::value,
58 "int is not pointer-like");
5931
6032 // For a DenseMap with non-pointer-like keys, forward iteration equals
6133 // reverse iteration.
8052 for (auto iter = Map.begin(), end = Map.end(); iter != end; iter++, ++i)
8153 ASSERT_EQ(iter->first, IterKeys[i]);
8254 }
83
84 TEST(ReverseIterationTest, SmallPtrSetTest) {
85 static_assert(detail::IsPointerLike::value,
86 "void * is pointer-like");
87
88 SmallPtrSet Set;
89 int a = 1, b = 2, c = 3, d = 4;
90 int *Ptrs[] = { &a, &b, &c, &d };
91
92 for (auto *Ptr: Ptrs)
93 Set.insert(Ptr);
94
95 // Note: This is the observed order of keys in the SmallPtrSet.
96 // If there is any change in the behavior of the SmallPtrSet, this order
97 // would need to be adjusted accordingly.
98 int *IterPtrs[] = { &a, &b, &c, &d };
99 if (shouldReverseIterate())
100 std::reverse(&IterPtrs[0], &IterPtrs[4]);
101
102 // Check that the SmallPtrSet is iterated in the expected order.
103 for (const auto &Tuple : zip(Set, IterPtrs))
104 ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));
105
106 // Check operator++ (post-increment).
107 int i = 0;
108 for (auto iter = Set.begin(), end = Set.end(); iter != end; iter++, ++i)
109 ASSERT_EQ(*iter, IterPtrs[i]);
110 }