summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/tools/llvm-exegesis/OperandGraphTest.cpp
blob: a29813b03efa6800c660b49392e5eaec4dfae72d (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
40
41
42
43
44
45
46
47
48
//===-- OperandGraphTest.cpp ------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "OperandGraph.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

using testing::ElementsAre;
using testing::IsEmpty;
using testing::Not;

namespace exegesis {
namespace graph {
namespace {

static const auto In = Node::In();
static const auto Out = Node::Out();

TEST(OperandGraphTest, NoPath) {
  Graph TheGraph;
  EXPECT_THAT(TheGraph.getPathFrom(In, Out), IsEmpty());
}

TEST(OperandGraphTest, Connecting) {
  Graph TheGraph;
  TheGraph.connect(In, Out);
  EXPECT_THAT(TheGraph.getPathFrom(In, Out), Not(IsEmpty()));
  EXPECT_THAT(TheGraph.getPathFrom(In, Out), ElementsAre(In, Out));
}

TEST(OperandGraphTest, ConnectingThroughVariable) {
  const Node Var = Node::Var(1);
  Graph TheGraph;
  TheGraph.connect(In, Var);
  TheGraph.connect(Var, Out);
  EXPECT_THAT(TheGraph.getPathFrom(In, Out), Not(IsEmpty()));
  EXPECT_THAT(TheGraph.getPathFrom(In, Out), ElementsAre(In, Var, Out));
}

} // namespace
} // namespace graph
} // namespace exegesis
OpenPOWER on IntegriCloud