[llvm-exegesis] Fix wrong index type.
[llvm-complete.git] / unittests / ADT / DepthFirstIteratorTest.cpp
blob4169cd48fcbd13c6dc6a7c221da3d99595549eb0
1 //=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator tests ---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/DepthFirstIterator.h"
11 #include "TestGraph.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 namespace llvm {
18 template <typename T> struct CountedSet {
19 typedef typename SmallPtrSet<T, 4>::iterator iterator;
21 SmallPtrSet<T, 4> S;
22 int InsertVisited = 0;
24 std::pair<iterator, bool> insert(const T &Item) {
25 InsertVisited++;
26 return S.insert(Item);
29 size_t count(const T &Item) const { return S.count(Item); }
31 void completed(T) { }
34 template <typename T> class df_iterator_storage<CountedSet<T>, true> {
35 public:
36 df_iterator_storage(CountedSet<T> &VSet) : Visited(VSet) {}
38 CountedSet<T> &Visited;
41 TEST(DepthFirstIteratorTest, ActuallyUpdateIterator) {
42 typedef CountedSet<Graph<3>::NodeType *> StorageT;
43 typedef df_iterator<Graph<3>, StorageT, true> DFIter;
45 Graph<3> G;
46 G.AddEdge(0, 1);
47 G.AddEdge(0, 2);
48 StorageT S;
49 for (auto N : make_range(DFIter::begin(G, S), DFIter::end(G, S)))
50 (void)N;
52 EXPECT_EQ(3, S.InsertVisited);