1 //=== llvm/unittest/ADT/BreadthFirstIteratorTest.cpp - BFS iterator tests -===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/BreadthFirstIterator.h"
11 #include "TestGraph.h"
12 #include "gtest/gtest.h"
18 TEST(BreadthFristIteratorTest, Basic) {
19 typedef bf_iterator<Graph<4>> BFIter;
26 auto It = BFIter::begin(G);
27 auto End = BFIter::end(G);
28 EXPECT_EQ(It.getLevel(), 0U);
29 EXPECT_EQ(*It, G.AccessNode(0));
31 EXPECT_EQ(It.getLevel(), 1U);
32 EXPECT_EQ(*It, G.AccessNode(1));
34 EXPECT_EQ(It.getLevel(), 1U);
35 EXPECT_EQ(*It, G.AccessNode(2));
37 EXPECT_EQ(It.getLevel(), 2U);
38 EXPECT_EQ(*It, G.AccessNode(3));
43 TEST(BreadthFristIteratorTest, Cycle) {
44 typedef bf_iterator<Graph<4>> BFIter;
57 auto It = BFIter::begin(G);
58 auto End = BFIter::end(G);
59 EXPECT_EQ(It.getLevel(), 0U);
60 EXPECT_EQ(*It, G.AccessNode(0));
62 EXPECT_EQ(It.getLevel(), 1U);
63 EXPECT_EQ(*It, G.AccessNode(1));
65 EXPECT_EQ(It.getLevel(), 2U);
66 EXPECT_EQ(*It, G.AccessNode(2));
68 EXPECT_EQ(It.getLevel(), 3U);
69 EXPECT_EQ(*It, G.AccessNode(3));
74 } // end namespace llvm