1 //=== llvm/unittest/ADT/BreadthFirstIteratorTest.cpp - BFS 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/BreadthFirstIterator.h"
10 #include "TestGraph.h"
11 #include "gtest/gtest.h"
17 TEST(BreadthFristIteratorTest
, Basic
) {
18 typedef bf_iterator
<Graph
<4>> BFIter
;
25 auto It
= BFIter::begin(G
);
26 auto End
= BFIter::end(G
);
27 EXPECT_EQ(It
.getLevel(), 0U);
28 EXPECT_EQ(*It
, G
.AccessNode(0));
30 EXPECT_EQ(It
.getLevel(), 1U);
31 EXPECT_EQ(*It
, G
.AccessNode(1));
33 EXPECT_EQ(It
.getLevel(), 1U);
34 EXPECT_EQ(*It
, G
.AccessNode(2));
36 EXPECT_EQ(It
.getLevel(), 2U);
37 EXPECT_EQ(*It
, G
.AccessNode(3));
42 TEST(BreadthFristIteratorTest
, Cycle
) {
43 typedef bf_iterator
<Graph
<4>> BFIter
;
56 auto It
= BFIter::begin(G
);
57 auto End
= BFIter::end(G
);
58 EXPECT_EQ(It
.getLevel(), 0U);
59 EXPECT_EQ(*It
, G
.AccessNode(0));
61 EXPECT_EQ(It
.getLevel(), 1U);
62 EXPECT_EQ(*It
, G
.AccessNode(1));
64 EXPECT_EQ(It
.getLevel(), 2U);
65 EXPECT_EQ(*It
, G
.AccessNode(2));
67 EXPECT_EQ(It
.getLevel(), 3U);
68 EXPECT_EQ(*It
, G
.AccessNode(3));
73 } // end namespace llvm