@@ -139,21 +139,23 @@ void init_grammar_aSb() {
139
139
.nonterms_count = 4 , .terms_count = 2 , .rules_count = 5 , .rules = rules };
140
140
}
141
141
142
- // S -> aS | a in WCNF
142
+ // S -> aS | a | eps in WCNF
143
143
//
144
144
// Terms: [0 a]
145
145
// Nonterms: [0 S]
146
146
// S -> SS [0 0 0 0]
147
147
// S -> a [0 0 -1 0]
148
+ // S -> eps [0 -1 -1 0]
148
149
void init_grammar_aS () {
149
150
LAGraph_rule_WCNF * rules = NULL ;
150
- LAGraph_Calloc ((void * * ) & rules , 2 , sizeof (LAGraph_rule_WCNF ), msg );
151
+ LAGraph_Calloc ((void * * ) & rules , 3 , sizeof (LAGraph_rule_WCNF ), msg );
151
152
152
153
rules [0 ] = (LAGraph_rule_WCNF ){0 , 0 , 0 , 0 };
153
154
rules [1 ] = (LAGraph_rule_WCNF ){0 , 0 , -1 , 0 };
155
+ rules [2 ] = (LAGraph_rule_WCNF ){0 , -1 , -1 , 0 };
154
156
155
157
grammar = (grammar_t ){
156
- .nonterms_count = 1 , .terms_count = 1 , .rules_count = 2 , .rules = rules };
158
+ .nonterms_count = 1 , .terms_count = 1 , .rules_count = 3 , .rules = rules };
157
159
}
158
160
159
161
// Complex grammar
@@ -404,6 +406,24 @@ void init_graph_3() {
404
406
adj_matrices [1 ] = adj_matrix_b ;
405
407
}
406
408
409
+ // Graph:
410
+
411
+ // 0 -b-> 1
412
+ // 1 -b-> 0
413
+ void init_graph_4 () {
414
+ LAGraph_Calloc ((void * * ) & adj_matrices , 2 , sizeof (GrB_Matrix ), msg ) ;
415
+
416
+ GrB_Matrix adj_matrix_a , adj_matrix_b ;
417
+ GrB_Matrix_new (& adj_matrix_a , GrB_BOOL , 2 , 2 );
418
+ GrB_Matrix_new (& adj_matrix_b , GrB_BOOL , 2 , 2 );
419
+
420
+ OK (GrB_Matrix_setElement (adj_matrix_b , true, 0 , 1 ));
421
+ OK (GrB_Matrix_setElement (adj_matrix_b , true, 1 , 0 ));
422
+
423
+ adj_matrices [0 ] = adj_matrix_a ;
424
+ adj_matrices [1 ] = adj_matrix_b ;
425
+ }
426
+
407
427
//====================
408
428
// Tests with valid result
409
429
//====================
@@ -514,6 +534,21 @@ void test_CFL_reachability_two_nodes_cycle(void) {
514
534
teardown ();
515
535
}
516
536
537
+ void test_CFL_reachability_with_empty_adj_matrix (void ) {
538
+ setup ();
539
+ GrB_Info retval ;
540
+
541
+ init_grammar_aS ();
542
+ init_graph_4 ();
543
+ init_outputs () ;
544
+
545
+ OK (run_algorithm ());
546
+ check_result ("(0, 0) (1, 1)" );
547
+
548
+ free_workspace ();
549
+ teardown ();
550
+ }
551
+
517
552
//====================
518
553
// Tests with invalid result
519
554
//====================
@@ -541,6 +576,11 @@ void test_CFL_reachability_invalid_rules(void) {
541
576
(LAGraph_rule_WCNF ){.nonterm = 10 , .prod_A = 1 , .prod_B = 2 , .index = 0 };
542
577
check_error (GrB_INVALID_VALUE );
543
578
579
+ // Rule [S -> A B], where A >= nonterms_count
580
+ grammar .rules [0 ] =
581
+ (LAGraph_rule_WCNF ){.nonterm = 0 , .prod_A = 10 , .prod_B = 2 , .index = 0 };
582
+ check_error (GrB_INVALID_VALUE );
583
+
544
584
// Rule [C -> t], where t >= terms_count
545
585
grammar .rules [0 ] =
546
586
(LAGraph_rule_WCNF ){.nonterm = 0 , .prod_A = 10 , .prod_B = -1 , .index = 0 };
@@ -579,6 +619,7 @@ void test_CFL_reachability_null_pointers(void) {
579
619
init_outputs () ;
580
620
581
621
adj_matrices [0 ] = NULL ;
622
+ adj_matrices [1 ] = NULL ;
582
623
check_error (GrB_NULL_POINTER );
583
624
584
625
adj_matrices = NULL ;
@@ -615,6 +656,7 @@ TEST_LIST = {{"CFL_reachability_complex_grammar", test_CFL_reachability_complex_
615
656
{"CFL_reachability_line" , test_CFL_reachability_line },
616
657
{"CFL_reachability_two_nodes_cycle" , test_CFL_reachability_two_nodes_cycle },
617
658
{"CFG_reach_basic_invalid_rules" , test_CFL_reachability_invalid_rules },
659
+ {"test_CFL_reachability_with_empty_adj_matrix" , test_CFL_reachability_with_empty_adj_matrix },
618
660
#if !defined ( GRAPHBLAS_HAS_CUDA )
619
661
{"CFG_reachability_null_pointers" , test_CFL_reachability_null_pointers },
620
662
#endif
0 commit comments