コード例 #1
0
TEST(PreorderIterator, ComplexGraph) {
    Graph graph;

    for (size_t i = 0; i < 10; ++i)
        graph.CreateNode();

    graph.GetNode(0).AddChild(1);
    graph.GetNode(0).AddChild(6);
    graph.GetNode(0).AddChild(7);

    graph.GetNode(1).AddChild(2);
    graph.GetNode(1).AddChild(3);
    graph.GetNode(1).AddChild(4);
    graph.GetNode(1).AddChild(5);

    graph.GetNode(7).AddChild(8);

    graph.GetNode(8).AddChild(9);

    std::vector<NodeId> expected_nodes = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    std::vector<size_t> expected_depths = {
        0, 1, 2, 2, 2, 2, 1, 1, 2, 3};
    std::vector<size_t> expected_child_index = {
        0, 0, 0, 1, 2, 3, 1, 2, 0, 0};
    
    ExpectTraversal(expected_nodes, expected_depths, expected_child_index, graph);
}
コード例 #2
0
TEST(PreorderIterator, SimpleGraph) {
    Graph graph;

    Node& root = graph.CreateNode();
    for (size_t i = 0; i < 10; ++i)
        root.AddChild(graph.CreateNode().id());

    std::vector<NodeId> expected_nodes = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    std::vector<size_t> expected_depths = {
        0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    std::vector<size_t> expected_child_index = {
        0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    
    ExpectTraversal(expected_nodes, expected_depths, expected_child_index, graph);
}
コード例 #3
0
TEST(PreorderIterator, VerticalGraph) {
    Graph graph;

    Node* lastNode = &graph.CreateNode();
    for (size_t i = 0; i < 10; ++i) {
        Node* newNode = &graph.CreateNode();
        lastNode->AddChild(newNode->id());
        lastNode = newNode;
    }

    std::vector<NodeId> expected_nodes = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    std::vector<size_t> expected_depths = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    std::vector<size_t> expected_child_index = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    
    ExpectTraversal(expected_nodes, expected_depths, expected_child_index, graph);
}