caffe2/core/nomnigraph/tests/subgraph_matcher_test.cc
// Test subtree matching with a simple tree graph.
Test subtree matching with a simple tree graph.
Test subtree matching with a simple tree graph .
TEST(SubgraphMatcher, IsSubtreeMatch) {
  TestGraph graph;
  auto n1 = graph.createNode("1");
  auto n2 = graph.createNode("2");
  auto n3 = graph.createNode("3");
  auto n4 = graph.createNode("4");
  auto n5 = graph.createNode("5");
  auto n6 = graph.createNode("6");
  auto n7 = graph.createNode("7");
  graph.createEdge(n1, n2);
  graph.createEdge(n2, n3);
  graph.createEdge(n2, n4);
  graph.createEdge(n1, n5);
  graph.createEdge(n5, n6);
  graph.createEdge(n5, n7);
  auto subtree = tree(any(), {tree(any()), tree(any())});
  EXPECT_FALSE(TestMatcher::isSubtreeMatch(n1, subtree, false));
  EXPECT_FALSE(TestMatcher::isSubtreeMatch(n4, subtree, false));
  EXPECT_TRUE(TestMatcher::isSubtreeMatch(n2, subtree, false));
  EXPECT_TRUE(TestMatcher::isSubtreeMatch(n5, subtree, false));
  subtree = tree(Criteria("5"), {tree(any()), tree(any())});
  EXPECT_FALSE(TestMatcher::isSubtreeMatch(n2, subtree, false));
  EXPECT_TRUE(TestMatcher::isSubtreeMatch(n5, subtree, false));
  subtree = tree(any(), {tree(any()), tree(Criteria("4"))});
  EXPECT_TRUE(TestMatcher::isSubtreeMatch(n2, subtree, false));
  EXPECT_FALSE(TestMatcher::isSubtreeMatch(n5, subtree, false));
}
TEST ( SubgraphMatcher , IsSubtreeMatch ) { TestGraph graph ; auto n1 = graph . createNode ( " " ) ; auto n2 = graph . createNode ( " " ) ; auto n3 = graph . createNode ( " " ) ; auto n4 = graph . createNode ( " " ) ; auto n5 = graph . createNode ( " " ) ; auto n6 = graph . createNode ( " " ) ; auto n7 = graph . createNode ( " " ) ; graph . createEdge ( n1 , n2 ) ; graph . createEdge ( n2 , n3 ) ; graph . createEdge ( n2 , n4 ) ; graph . createEdge ( n1 , n5 ) ; graph . createEdge ( n5 , n6 ) ; graph . createEdge ( n5 , n7 ) ; auto subtree = tree ( any ( ) , { tree ( any ( ) ) , tree ( any ( ) ) } ) ; EXPECT_FALSE ( TestMatcher :: isSubtreeMatch ( n1 , subtree , false ) ) ; EXPECT_FALSE ( TestMatcher :: isSubtreeMatch ( n4 , subtree , false ) ) ; EXPECT_TRUE ( TestMatcher :: isSubtreeMatch ( n2 , subtree , false ) ) ; EXPECT_TRUE ( TestMatcher :: isSubtreeMatch ( n5 , subtree , false ) ) ; subtree = tree ( Criteria ( " " ) , { tree ( any ( ) ) , tree ( any ( ) ) } ) ; EXPECT_FALSE ( TestMatcher :: isSubtreeMatch ( n2 , subtree , false ) ) ; EXPECT_TRUE ( TestMatcher :: isSubtreeMatch ( n5 , subtree , false ) ) ; subtree = tree ( any ( ) , { tree ( any ( ) ) , tree ( Criteria ( " " ) ) } ) ; EXPECT_TRUE ( TestMatcher :: isSubtreeMatch ( n2 , subtree , false ) ) ; EXPECT_FALSE ( TestMatcher :: isSubtreeMatch ( n5 , subtree , false ) ) ; }
Test subtree matching with a simple tree graph.
Test subtree matching with a simple tree graph .
/*       N1
         /     \
      N2         N5
    /    \     /    \
  N3     N4   N6   N7
  */