summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/ReverseIterationTest.cpp
blob: 9235ecd74321e2401a2da93aa170eec2d99d9010 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//===- llvm/unittest/ADT/ReverseIterationTest.cpp ------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// ReverseIteration unit tests.
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"
#include "llvm/ADT/SmallPtrSet.h"

#if LLVM_ENABLE_ABI_BREAKING_CHECKS
using namespace llvm;

TEST(ReverseIterationTest, SmallPtrSetTest) {

  SmallPtrSet<void*, 4> Set;
  void *Ptrs[] = { (void*)0x1, (void*)0x2, (void*)0x3, (void*)0x4 };
  void *ReversePtrs[] = { (void*)0x4, (void*)0x3, (void*)0x2, (void*)0x1 };

  for (auto *Ptr: Ptrs)
    Set.insert(Ptr);

  // Check forward iteration.
  ReverseIterate<bool>::value = false;
  for (const auto &Tuple : zip(Set, Ptrs))
    ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));

  // Check reverse iteration.
  ReverseIterate<bool>::value = true;
  for (const auto &Tuple : zip(Set, ReversePtrs))
    ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));
}
#endif
OpenPOWER on IntegriCloud