Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- OperandGraphTest.cpp ------------------------------------*- C++ -*-===// |
| 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 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "OperandGraph.h" |
| 11 | #include "gmock/gmock.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | using testing::ElementsAre; |
| 15 | using testing::IsEmpty; |
| 16 | using testing::Not; |
| 17 | |
| 18 | namespace exegesis { |
| 19 | namespace graph { |
| 20 | namespace { |
| 21 | |
| 22 | static const auto In = Node::In(); |
| 23 | static const auto Out = Node::Out(); |
| 24 | |
| 25 | TEST(OperandGraphTest, NoPath) { |
| 26 | Graph TheGraph; |
| 27 | EXPECT_THAT(TheGraph.getPathFrom(In, Out), IsEmpty()); |
| 28 | } |
| 29 | |
| 30 | TEST(OperandGraphTest, Connecting) { |
| 31 | Graph TheGraph; |
| 32 | TheGraph.connect(In, Out); |
| 33 | EXPECT_THAT(TheGraph.getPathFrom(In, Out), Not(IsEmpty())); |
| 34 | EXPECT_THAT(TheGraph.getPathFrom(In, Out), ElementsAre(In, Out)); |
| 35 | } |
| 36 | |
| 37 | TEST(OperandGraphTest, ConnectingThroughVariable) { |
| 38 | const Node Var = Node::Var(1); |
| 39 | Graph TheGraph; |
| 40 | TheGraph.connect(In, Var); |
| 41 | TheGraph.connect(Var, Out); |
| 42 | EXPECT_THAT(TheGraph.getPathFrom(In, Out), Not(IsEmpty())); |
| 43 | EXPECT_THAT(TheGraph.getPathFrom(In, Out), ElementsAre(In, Var, Out)); |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | } // namespace graph |
| 48 | } // namespace exegesis |