Esempio n. 1
0
/**
 * Returns next node for an input of @a c at node @a node or node_p() if none.
 */
node_p find_next(const node_p& node, uint8_t c)
{
    Node::target_info_list_t targets = node->targets_for(c);
    if (targets.empty()) {
        return node_p();
    }
    else {
        if (targets.size() != 1) {
            throw logic_error("Unexpected non-determinism.");
        }
        return targets.front().first;
    }
}
Esempio n. 2
0
TEST(TestIntermediate, NodeEdges)
{
    Node node;
    node_p target_a = boost::make_shared<Node>();
    node_p target_a2 = boost::make_shared<Node>();
    node_p target_b = boost::make_shared<Node>();
    byte_vector_t values;
    values.push_back('a');
    node.edges().push_back(Edge::make_from_vector(target_a, false, values));
    node.edges().push_back(Edge::make_from_vector(target_a2, false, values));
    values[0] = 'b';
    node.edges().push_back(Edge::make_from_vector(target_b, false, values));

    Node::edge_list_t edges = node.edges_for('a');
    EXPECT_EQ(2UL, edges.size());
    EXPECT_TRUE(edges.front().matches('a'));
    EXPECT_EQ(1UL, edges.front().size());
    edges = node.edges_for('b');
    EXPECT_EQ(1UL, edges.size());
    EXPECT_EQ(target_b, edges.front().target());
    EXPECT_TRUE(edges.front().matches('b'));
    EXPECT_EQ(1UL, edges.front().size());

    node_p target_default = boost::make_shared<Node>();

    node.default_target() = target_default;

    Node::target_info_list_t targets;

    targets = node.targets_for('a');
    EXPECT_EQ(2UL, targets.size());
    targets = node.targets_for('b');
    EXPECT_EQ(1UL, targets.size());
    targets = node.targets_for('c');
    EXPECT_EQ(1UL, targets.size());
    EXPECT_EQ(target_default, targets.front().first);

    node_p target_epsilon = boost::make_shared<Node>();
    node.edges().push_back(Edge(target_epsilon));
    targets = node.targets_for('a');
    EXPECT_EQ(3UL, targets.size());
    targets = node.targets_for('b');
    EXPECT_EQ(2UL, targets.size());
    targets = node.targets_for('c');
    EXPECT_EQ(1UL, targets.size());
}