1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
|
/*
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Unit tests for checking the removeGraphEquivalences code in
* nfagraph/ng_equivalence.cpp.
*/
#include "config.h"
#include "gtest/gtest.h"
#include "nfagraph_common.h"
#include "grey.h"
#include "hs.h"
#include "parser/Component.h"
#include "parser/Parser.h"
#include "compiler/compiler.h"
#include "nfagraph/ng.h"
#include "nfagraph/ng_builder.h"
#include "nfagraph/ng_equivalence.h"
#include "nfagraph/ng_misc_opt.h"
#include "util/target_info.h"
using namespace std;
using namespace ue2;
// left equivalence
TEST(NFAGraph, RemoveEquivalence1) {
// Build a small graph with a redundant vertex: (ab|ac)
// The graph should be merged into: a(b|c)
CompileContext cc(false, false, get_current_target(), Grey());
auto graph(constructGraphWithCC("(ab|ac)", cc, 0));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
g.kind = NFA_SUFFIX;
// Run reduceGraphEquivalences
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
// Our graph should only have three non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 3, num_vertices(g));
// Start dot start state should have edges to itself and one vertex
ASSERT_EQ(2U, out_degree(g.startDs, g));
// Accept state should have two incoming edges
ASSERT_EQ(2U, in_degree(g.accept, g));
// Find a vertex that goes right after startDs
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex v : adjacent_vertices_range(g.startDs, g)) {
a = v;
if (a == g.startDs) {
continue;
}
// check if it has the right char reach
const CharReach &tmpcr = g[a].char_reach;
ASSERT_EQ(1U, tmpcr.count());
ASSERT_TRUE(tmpcr.test('a'));
}
// check if we found our vertex
ASSERT_TRUE(a != NGHolder::null_vertex());
// There should be two edges from v to nodes with reachability 'b' and 'c'
NFAVertex b = NGHolder::null_vertex();
NFAVertex c = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(a, g)) {
const CharReach &tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
if (tmpcr.test('b')) {
b = tmp;
} else if (tmpcr.test('c')) {
c = tmp;
} else {
FAIL();
}
}
// check if we found our vertices
ASSERT_TRUE(b != NGHolder::null_vertex());
ASSERT_TRUE(c != NGHolder::null_vertex());
// both vertices should have an edge to accept
ASSERT_TRUE(edge(b, g.accept, g).second);
ASSERT_TRUE(edge(c, g.accept, g).second);
}
// right equivalence
TEST(NFAGraph, RemoveEquivalence2) {
// Build a small graph with a redundant vertex: (ba|ca)
// The graph should be merged into: (b|c)a
CompileContext cc(false, false, get_current_target(), Grey());
auto graph(constructGraphWithCC("(ba|ca)", cc, 0));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
g.kind = NFA_SUFFIX;
// Run reduceGraphEquivalences
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
// Our graph should only have two non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 3, num_vertices(g));
// Start dot start state should have edges to itself and two more vertices
ASSERT_EQ(3U, out_degree(g.startDs, g));
// Accept start state should have edges from one vertex only
ASSERT_EQ(1U, in_degree(g.accept, g));
// Find a vertex leading to accept
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex v : inv_adjacent_vertices_range(g.accept, g)) {
a = v;
if (a == g.accept) {
continue;
}
// check if it has the right char reach
const CharReach &tmpcr = g[a].char_reach;
ASSERT_EQ(1U, tmpcr.count());
ASSERT_TRUE(tmpcr.test('a'));
}
// check if we found our vertex
ASSERT_TRUE(a != NGHolder::null_vertex());
// There should be two edges from v to nodes with reachability 'b' and 'c'
NFAVertex b = NGHolder::null_vertex();
NFAVertex c = NGHolder::null_vertex();
for (NFAVertex tmp : inv_adjacent_vertices_range(a, g)) {
const CharReach &tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
if (tmpcr.test('b')) {
b = tmp;
} else if (tmpcr.test('c')) {
c = tmp;
} else {
FAIL();
}
}
// check if we found our vertices
ASSERT_TRUE(b != NGHolder::null_vertex());
ASSERT_TRUE(c != NGHolder::null_vertex());
// both new vertices should have edges from startDs
ASSERT_TRUE(edge(g.startDs, b, g).second);
ASSERT_TRUE(edge(g.startDs, c, g).second);
}
// more complex left equivalence
TEST(NFAGraph, RemoveEquivalence3) {
// Build a small graph with a redundant vertex: a(..)+X|a(..)+Y
// The graph should be merged into: a(..)+(X|Y)
CompileContext cc(false, false, get_current_target(), Grey());
auto graph(constructGraphWithCC("a(..)+X|a(..)+Y", cc, HS_FLAG_DOTALL));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
g.kind = NFA_SUFFIX;
// Run reduceGraphEquivalences
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
// Our graph should only have five non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 5, num_vertices(g));
// Start dot start state should have edges to itself and one vertex
ASSERT_EQ(2U, out_degree(g.startDs, g));
// Accept state should have two incoming edges
ASSERT_EQ(2U, in_degree(g.accept, g));
// Find a vertex 'a' that goes right after startDs
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex v : adjacent_vertices_range(g.startDs, g)) {
a = v;
if (a == g.startDs) {
continue;
}
// check if it has the right char reach
const CharReach &tmpcr = g[a].char_reach;
ASSERT_EQ(1U, tmpcr.count());
ASSERT_TRUE(tmpcr.test('a'));
}
// check if we found our 'a'
ASSERT_TRUE(a != NGHolder::null_vertex());
// There should be an edge from 'a' to '.'
ASSERT_EQ(1U, out_degree(a, g));
NFAVertex dot1 = *(adjacent_vertices(a, g).first);
// check if this is a dot
const CharReach dot1cr = g[dot1].char_reach;
ASSERT_TRUE(dot1cr.all());
// After dot1, there should be another '.'
ASSERT_EQ(1U, out_degree(dot1, g));
NFAVertex dot2 = *(adjacent_vertices(dot1, g).first);
// check its char reach as well
const CharReach dot2cr = g[dot2].char_reach;
ASSERT_TRUE(dot2cr.all());
// the second dot should have three edges - to dot1, and to X and Y
// first, check an edge to dot1
ASSERT_EQ(3U, out_degree(dot2, g));
ASSERT_TRUE(edge(dot2, dot1, g).second);
// now, let's find X and Y nodes
NFAVertex X = NGHolder::null_vertex();
NFAVertex Y = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(dot2, g)) {
// we already know about dot1, so skip it
if (tmp == dot1) {
continue;
}
const CharReach tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
if (tmpcr.test('X')) {
X = tmp;
} else if (tmpcr.test('Y')) {
Y = tmp;
} else {
FAIL();
}
}
// check if we found both vertices
ASSERT_TRUE(X != NGHolder::null_vertex());
ASSERT_TRUE(Y != NGHolder::null_vertex());
// finally, check if these two vertices only have edges to accept
ASSERT_EQ(1U, out_degree(X, g));
ASSERT_EQ(1U, out_degree(Y, g));
ASSERT_TRUE(edge(X, g.accept, g).second);
ASSERT_TRUE(edge(Y, g.accept, g).second);
}
// more complex right equivalence
TEST(NFAGraph, RemoveEquivalence4) {
// Build a small graph with a redundant vertex: X(..)+a|Y(..)+a
// The graph should be merged into: (X|Y)(..)+a
CompileContext cc(false, false, get_current_target(), Grey());
auto graph(constructGraphWithCC("X(..)+a|Y(..)+a", cc, HS_FLAG_DOTALL));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
g.kind = NFA_SUFFIX;
// Run reduceGraphEquivalences
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
// Our graph should only have five non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 5, num_vertices(g));
// Start dot start state should have edges to itself and two vertices
ASSERT_EQ(3U, out_degree(g.startDs, g));
// Accept state should have one incoming edge
ASSERT_EQ(1U, in_degree(g.accept, g));
// Find X and Y nodes that are connected to startDs
NFAVertex X = NGHolder::null_vertex();
NFAVertex Y = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(g.startDs, g)) {
// skip startDs
if (tmp == g.startDs) {
continue;
}
// get char reach
const CharReach tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
if (tmpcr.test('X')) {
X = tmp;
} else if (tmpcr.test('Y')) {
Y = tmp;
} else {
FAIL();
}
}
// check if we found both vertices
ASSERT_TRUE(X != NGHolder::null_vertex());
ASSERT_TRUE(Y != NGHolder::null_vertex());
// now, find first dot from X
ASSERT_EQ(1U, out_degree(X, g));
NFAVertex dot1 = *(adjacent_vertices(X, g).first);
// make sure Y also has an edge to that dot
ASSERT_EQ(1U, out_degree(Y, g));
ASSERT_TRUE(edge(Y, dot1, g).second);
// now, verify that it's actually a dot
const CharReach dot1cr = g[dot1].char_reach;
ASSERT_TRUE(dot1cr.all());
// the first dot has one edge to another dot
ASSERT_EQ(1U, out_degree(dot1, g));
NFAVertex dot2 = *(adjacent_vertices(dot1, g).first);
// verify it's a dot
const CharReach dot2cr = g[dot2].char_reach;
ASSERT_TRUE(dot2cr.all());
// second dot should have two edges - to dot1 and to 'a'
ASSERT_EQ(2U, out_degree(dot2, g));
ASSERT_TRUE(edge(dot2, dot1, g).second);
// now find 'a'
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(dot2, g)) {
// skip dot1
if (tmp == dot1) {
continue;
}
// get char reach
const CharReach tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
if (tmpcr.test('a')) {
a = tmp;
} else {
FAIL();
}
}
// make sure we found our 'a'
ASSERT_TRUE(a != NGHolder::null_vertex());
// now, check if 'a' has an edge to accept
ASSERT_EQ(1U, out_degree(a, g));
ASSERT_TRUE(edge(a, g.accept, g).second);
}
// catching UE-2693
TEST(NFAGraph, RemoveEquivalence5) {
// Build a small graph with a redundant vertex: [^\x00][^x00]*[\\x00]
// The graph should be merged into: [^\x00]*[\x00]
CompileContext cc(false, false, get_current_target(), Grey());
auto graph(constructGraphWithCC("[^\\x00][^\\x00]*[\\x00]", cc, 0));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
g.kind = NFA_PREFIX;
// Run reduceGraphEquivalences
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
// Our graph should only have two non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 2, num_vertices(g));
// Start dot start state should have edges to itself and one vertex
ASSERT_EQ(2U, out_degree(g.startDs, g));
// Accept state should have one incoming edge
ASSERT_EQ(1U, in_degree(g.accept, g));
// find first vertex and ensure it has a self loop
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(g.startDs, g)) {
v = t;
if (v == g.startDs) {
continue;
}
// check if it has the right char reach
const CharReach &tmpcr = g[v].char_reach;
ASSERT_EQ(255U, tmpcr.count());
ASSERT_TRUE(!tmpcr.test(0));
ASSERT_TRUE(edge(v, v, g).second);
}
// check if we found our vertex
ASSERT_TRUE(v != NGHolder::null_vertex());
// now, find the vertex leading to accept
NFAVertex v2 = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(v, g)) {
// skip self-loop
if (tmp == v) {
continue;
}
v2 = tmp;
// get char reach
const CharReach tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
ASSERT_TRUE(tmpcr.test(0));
ASSERT_TRUE(edge(tmp, g.accept, g).second);
}
// check if we found our vertex
ASSERT_TRUE(v2 != NGHolder::null_vertex());
}
// catching UE-2692
TEST(NFAGraph, RemoveEquivalence6) {
// Build a small graph with two redundant vertices: ^(.*|.*)a
// The graph should be merged into: a
auto graph(constructGraph("^(.*|.*)a", HS_FLAG_DOTALL));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
// Run mergeCyclicDotStars
ASSERT_TRUE(mergeCyclicDotStars(g));
// Our graph should only have one non-special node
ASSERT_EQ((size_t)N_SPECIALS + 1, num_vertices(g));
// Start dot start state should have edges to itself and one vertex
ASSERT_EQ(2U, out_degree(g.startDs, g));
// Accept state should have one incoming edge
ASSERT_EQ(1U, in_degree(g.accept, g));
// find that vertex and ensure it has no self loops and an edge to accept
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(g.startDs, g)) {
v = t;
if (v == g.startDs) {
continue;
}
// check if it has the right char reach
const CharReach &tmpcr = g[v].char_reach;
ASSERT_EQ(1U, tmpcr.count());
ASSERT_TRUE(tmpcr.test('a'));
ASSERT_TRUE(!edge(v, v, g).second);
ASSERT_TRUE(edge(v, g.accept, g).second);
}
// check if we found our vertex
ASSERT_TRUE(v != NGHolder::null_vertex());
}
// catching UE-2692
TEST(NFAGraph, RemoveEquivalence7) {
// Build a small graph with no redundant vertices: ^.+a
// Make sure we don't merge anything
auto graph(constructGraph("^.+a", HS_FLAG_DOTALL));
ASSERT_TRUE(graph != nullptr);
NGHolder &g = *graph;
// Run mergeCyclicDotStars
ASSERT_FALSE(mergeCyclicDotStars(g));
// Our graph should have two non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 2, num_vertices(g));
// Start dot start state should have an edge to itself only
ASSERT_EQ(1U, out_degree(g.startDs, g));
// Start should have edges to startDs and one other vertex
ASSERT_EQ(2U, out_degree(g.start, g));
// Accept state should have one incoming edge
ASSERT_EQ(1U, in_degree(g.accept, g));
// find that vertex and ensure it's a dot self loop and has one outgoing edge
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(g.start, g)) {
if (t == g.startDs) {
continue;
}
v = t;
// check if it has the right char reach
const CharReach &tmpcr = g[v].char_reach;
ASSERT_TRUE(tmpcr.all());
ASSERT_TRUE(edge(v, v, g).second);
ASSERT_EQ(1U, proper_out_degree(v, g));
}
// check if we found our vertex
ASSERT_TRUE(v != NGHolder::null_vertex());
// find the next vertex and ensure it has an edge to accept
NFAVertex v2 = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(v, g)) {
// skip self loop
if (t == v) {
continue;
}
v2 = t;
// check if it has the right char reach
const CharReach &tmpcr = g[v2].char_reach;
ASSERT_EQ(1U, tmpcr.count());
ASSERT_TRUE(tmpcr.test('a'));
ASSERT_TRUE(!edge(v2, v2, g).second);
ASSERT_EQ(1U, proper_out_degree(v2, g));
ASSERT_TRUE(edge(v2, g.accept, g).second);
}
// check if we found our vertex
ASSERT_TRUE(v2 != NGHolder::null_vertex());
}
TEST(NFAGraph, RemoveEquivalence_Reports1) {
CompileContext cc(false, false, get_current_target(), Grey());
NGHolder g(NFA_SUFFIX);
NFAVertex a = add_vertex(g);
NFAVertex b = add_vertex(g);
NFAVertex c = add_vertex(g);
add_edge(g.start, a, g);
add_edge(a, b, g);
add_edge(a, c, g);
add_edge(b, g.accept, g);
add_edge(c, g.accept, g);
g[b].reports.insert(0);
g[c].reports.insert(1);
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
ASSERT_EQ(num_vertices(g), N_SPECIALS + 2); /* b, c should be merged */
ASSERT_EQ(in_degree(g.accept, g), 1);
}
TEST(NFAGraph, RemoveEquivalence_Reports2) {
CompileContext cc(false, false, get_current_target(), Grey());
NGHolder g(NFA_SUFFIX);
NFAVertex a = add_vertex(g);
NFAVertex b = add_vertex(g);
NFAVertex c = add_vertex(g);
add_edge(g.start, a, g);
add_edge(a, b, g);
add_edge(a, c, g);
add_edge(b, g.accept, g);
add_edge(c, g.acceptEod, g);
g[b].reports.insert(0);
g[c].reports.insert(1);
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
ASSERT_EQ(num_vertices(g), N_SPECIALS + 3); /* b, c should not be merged */
ASSERT_EQ(in_degree(g.accept, g), 1);
ASSERT_EQ(in_degree(g.acceptEod, g), 2);
}
TEST(NFAGraph, RemoveEquivalence_Reports3) {
CompileContext cc(false, false, get_current_target(), Grey());
NGHolder g(NFA_SUFFIX);
NFAVertex a = add_vertex(g);
NFAVertex b = add_vertex(g);
NFAVertex c = add_vertex(g);
add_edge(g.start, a, g);
add_edge(a, b, g);
add_edge(a, c, g);
add_edge(b, g.accept, g);
add_edge(c, g.acceptEod, g);
g[b].reports.insert(0);
g[c].reports.insert(0);
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
ASSERT_EQ(num_vertices(g), N_SPECIALS + 2); /* b, c should be merged */
ASSERT_EQ(in_degree(g.accept, g), 1);
ASSERT_EQ(in_degree(g.acceptEod, g), 2);
}
TEST(NFAGraph, RemoveEquivalence_Reports4) {
CompileContext cc(false, false, get_current_target(), Grey());
NGHolder g(NFA_SUFFIX);
NFAVertex a = add_vertex(g);
NFAVertex b = add_vertex(g);
NFAVertex c = add_vertex(g);
NFAVertex d = add_vertex(g);
add_edge(g.start, a, g);
add_edge(a, b, g);
add_edge(a, c, g);
add_edge(c, d, g);
add_edge(d, d, g);
add_edge(b, g.accept, g);
g[b].reports.insert(0);
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
ASSERT_EQ(num_vertices(g), N_SPECIALS + 3); /* b, c should be merged */
ASSERT_EQ(in_degree(g.accept, g), 1);
ASSERT_EQ(in_degree(g.acceptEod, g), 1);
}
TEST(NFAGraph, RemoveEquivalence_Reports5) {
CompileContext cc(false, false, get_current_target(), Grey());
NGHolder g(NFA_SUFFIX);
NFAVertex a = add_vertex(g);
NFAVertex b = add_vertex(g);
NFAVertex c = add_vertex(g);
NFAVertex d = add_vertex(g);
add_edge(g.start, a, g);
add_edge(a, b, g);
add_edge(a, c, g);
add_edge(c, d, g);
add_edge(d, d, g);
add_edge(b, g.acceptEod, g);
g[b].reports.insert(0);
ASSERT_TRUE(reduceGraphEquivalences(g, cc));
ASSERT_EQ(num_vertices(g), N_SPECIALS + 3); /* b, c should be merged */
ASSERT_EQ(in_degree(g.accept, g), 0);
ASSERT_EQ(in_degree(g.acceptEod, g), 2);
}
|