mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
Introduce custom adjacency-list based graph
This commit is contained in:
@@ -55,13 +55,13 @@ TEST(NFAGraph, RemoveRedundancy1) {
|
||||
|
||||
unique_ptr<NGWrapper> graph(constructGraphWithCC("(a|b)c", cc, 0));
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
NGHolder &g = *graph;
|
||||
|
||||
// Run removeRedundancy
|
||||
removeRedundancy(*graph, SOM_NONE);
|
||||
NFAGraph &g = graph->g;
|
||||
removeRedundancy(g, SOM_NONE);
|
||||
|
||||
// Our graph should only have two non-special nodes
|
||||
ASSERT_EQ((size_t)N_SPECIALS + 2, num_vertices(*graph));
|
||||
ASSERT_EQ((size_t)N_SPECIALS + 2, num_vertices(g));
|
||||
|
||||
// Dot-star start state should be connected to itself and a single other
|
||||
// vertex
|
||||
@@ -98,13 +98,13 @@ TEST(NFAGraph, RemoveRedundancy2) {
|
||||
unique_ptr<NGWrapper> graph(constructGraphWithCC("a.*b?c", cc,
|
||||
HS_FLAG_DOTALL));
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
NGHolder &g = *graph;
|
||||
|
||||
// Run removeRedundancy
|
||||
removeRedundancy(*graph, SOM_NONE);
|
||||
NFAGraph &g = graph->g;
|
||||
removeRedundancy(g, SOM_NONE);
|
||||
|
||||
// Our graph should now have only 3 non-special vertices
|
||||
ASSERT_EQ((size_t)N_SPECIALS + 3, num_vertices(*graph));
|
||||
ASSERT_EQ((size_t)N_SPECIALS + 3, num_vertices(g));
|
||||
|
||||
// Dot-star start state should be connected to itself and a single other
|
||||
// vertex
|
||||
@@ -156,12 +156,12 @@ TEST(NFAGraph, RemoveRedundancy3) {
|
||||
cc, 0));
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
|
||||
unsigned countBefore = num_vertices(graph->g);
|
||||
unsigned countBefore = num_vertices(*graph);
|
||||
removeRedundancy(*graph, SOM_NONE);
|
||||
|
||||
// The '(a|b)?' construction (two states) should have disappeared, leaving
|
||||
// this expr as 'foobar.*teakettle'
|
||||
ASSERT_EQ(countBefore - 2, num_vertices(graph->g));
|
||||
ASSERT_EQ(countBefore - 2, num_vertices(*graph));
|
||||
}
|
||||
|
||||
TEST(NFAGraph, RemoveRedundancy4) {
|
||||
@@ -169,11 +169,11 @@ TEST(NFAGraph, RemoveRedundancy4) {
|
||||
unique_ptr<NGWrapper> graph(constructGraphWithCC("foo([A-Z]|a|b|q)", cc, 0));
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
|
||||
unsigned countBefore = num_vertices(graph->g);
|
||||
unsigned countBefore = num_vertices(*graph);
|
||||
removeRedundancy(*graph, SOM_NONE);
|
||||
|
||||
// We should end up with the alternation collapsing into one state
|
||||
ASSERT_EQ(countBefore - 3, num_vertices(graph->g));
|
||||
ASSERT_EQ(countBefore - 3, num_vertices(*graph));
|
||||
}
|
||||
|
||||
TEST(NFAGraph, RemoveRedundancy5) {
|
||||
@@ -182,12 +182,12 @@ TEST(NFAGraph, RemoveRedundancy5) {
|
||||
cc, 0));
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
|
||||
unsigned countBefore = num_vertices(graph->g);
|
||||
unsigned countBefore = num_vertices(*graph);
|
||||
removeRedundancy(*graph, SOM_NONE);
|
||||
|
||||
// Since we don't return a start offset, the first state ('[0-9]?') is
|
||||
// redundant.
|
||||
ASSERT_EQ(countBefore - 1, num_vertices(graph->g));
|
||||
ASSERT_EQ(countBefore - 1, num_vertices(*graph));
|
||||
}
|
||||
|
||||
TEST(NFAGraph, RemoveEdgeRedundancy1) {
|
||||
@@ -196,12 +196,12 @@ TEST(NFAGraph, RemoveEdgeRedundancy1) {
|
||||
auto graph = constructGraphWithCC("A+hatstand", cc, HS_FLAG_DOTALL);
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
|
||||
unsigned countBefore = num_edges(graph->g);
|
||||
unsigned countBefore = num_edges(*graph);
|
||||
|
||||
removeEdgeRedundancy(*graph, SOM_NONE, cc);
|
||||
|
||||
// One edge (the self-loop on the leading A+) should have been removed.
|
||||
ASSERT_EQ(countBefore - 1, num_edges(graph->g));
|
||||
ASSERT_EQ(countBefore - 1, num_edges(*graph));
|
||||
}
|
||||
|
||||
TEST(NFAGraph, RemoveEdgeRedundancy2) {
|
||||
@@ -210,12 +210,12 @@ TEST(NFAGraph, RemoveEdgeRedundancy2) {
|
||||
auto graph = constructGraphWithCC("foo.*A*bar", cc, HS_FLAG_DOTALL);
|
||||
ASSERT_TRUE(graph.get() != nullptr);
|
||||
|
||||
size_t numEdgesBefore = num_edges(graph->g);
|
||||
size_t numVertsBefore = num_vertices(graph->g);
|
||||
size_t numEdgesBefore = num_edges(*graph);
|
||||
size_t numVertsBefore = num_vertices(*graph);
|
||||
|
||||
removeEdgeRedundancy(*graph, SOM_NONE, cc);
|
||||
|
||||
// The .* should swallow up the A* and its self-loop.
|
||||
ASSERT_EQ(numEdgesBefore - 4, num_edges(graph->g));
|
||||
ASSERT_EQ(numVertsBefore - 1, num_vertices(graph->g));
|
||||
ASSERT_EQ(numEdgesBefore - 4, num_edges(*graph));
|
||||
ASSERT_EQ(numVertsBefore - 1, num_vertices(*graph));
|
||||
}
|
||||
|
Reference in New Issue
Block a user