1 //=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator tests ---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/DepthFirstIterator.h"
10 #include "TestGraph.h"
11 #include "gtest/gtest.h"
17 template <typename T
> struct CountedSet
{
18 typedef typename SmallPtrSet
<T
, 4>::iterator iterator
;
21 int InsertVisited
= 0;
23 std::pair
<iterator
, bool> insert(const T
&Item
) {
25 return S
.insert(Item
);
28 size_t count(const T
&Item
) const { return S
.count(Item
); }
33 template <typename T
> class df_iterator_storage
<CountedSet
<T
>, true> {
35 df_iterator_storage(CountedSet
<T
> &VSet
) : Visited(VSet
) {}
37 CountedSet
<T
> &Visited
;
40 TEST(DepthFirstIteratorTest
, ActuallyUpdateIterator
) {
41 typedef CountedSet
<Graph
<3>::NodeType
*> StorageT
;
42 typedef df_iterator
<Graph
<3>, StorageT
, true> DFIter
;
48 for (auto N
: make_range(DFIter::begin(G
, S
), DFIter::end(G
, S
)))
51 EXPECT_EQ(3, S
.InsertVisited
);