Skip to content

Commit 3402775

Browse files
Merge pull request #291 from SparseLinearAlgebra/v1.2
Test: achieve 100% coverage for LAGraph_CFL_reachability
2 parents 314c9e1 + 8315558 commit 3402775

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

experimental/algorithm/LAGraph_CFL_reachability.c

-7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// Querying Using Linear Algebra", URL:
1616
// https://disser.spbu.ru/files/2022/disser_azimov.pdf
1717

18-
// FIXME: some of the code below is not covered by the test suite, "make cov".
19-
// See the FIXMEs below.
2018

2119
#define LG_FREE_WORK \
2220
{ \
@@ -175,7 +173,6 @@ GrB_Info LAGraph_CFL_reachability
175173
ADD_TO_MSG("Adjacency matrices with these indexes are null: ");
176174
ADD_TO_MSG("%d", i);
177175
} else {
178-
// FIXME: this case is not tested.
179176
ADD_TO_MSG(", %d", i);
180177
}
181178

@@ -224,7 +221,6 @@ GrB_Info LAGraph_CFL_reachability
224221

225222
// [Variable -> eps]
226223
if (is_rule_eps) {
227-
// FIXME: this case is not tested.
228224
eps_rules[eps_rules_count++] = i;
229225

230226
continue;
@@ -247,7 +243,6 @@ GrB_Info LAGraph_CFL_reachability
247243

248244
if (rule.prod_A < -1 || rule.prod_A >= nonterms_count || rule.prod_B < -1 ||
249245
rule.prod_B >= nonterms_count) {
250-
// FIXME: this case is not tested.
251246
ADD_INDEX_TO_ERROR_RULE(nonterm_err, i);
252247
}
253248

@@ -286,7 +281,6 @@ GrB_Info LAGraph_CFL_reachability
286281
GRB_TRY(GrB_Matrix_nvals(&adj_matrix_nnz, adj_matrices[term_rule.prod_A]));
287282

288283
if (adj_matrix_nnz == 0) {
289-
// FIXME: this case is not tested.
290284
continue;
291285
}
292286

@@ -311,7 +305,6 @@ GrB_Info LAGraph_CFL_reachability
311305

312306
// Rule [Variable -> eps]
313307
for (size_t i = 0; i < eps_rules_count; i++) {
314-
// FIXME: this case is not tested.
315308
LAGraph_rule_WCNF eps_rule = rules[eps_rules[i]];
316309

317310
GxB_eWiseUnion (

experimental/test/test_CFL_reachability.c

+45-3
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,23 @@ void init_grammar_aSb() {
139139
.nonterms_count = 4, .terms_count = 2, .rules_count = 5, .rules = rules};
140140
}
141141

142-
// S -> aS | a in WCNF
142+
// S -> aS | a | eps in WCNF
143143
//
144144
// Terms: [0 a]
145145
// Nonterms: [0 S]
146146
// S -> SS [0 0 0 0]
147147
// S -> a [0 0 -1 0]
148+
// S -> eps [0 -1 -1 0]
148149
void init_grammar_aS() {
149150
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);
151152

152153
rules[0] = (LAGraph_rule_WCNF){0, 0, 0, 0};
153154
rules[1] = (LAGraph_rule_WCNF){0, 0, -1, 0};
155+
rules[2] = (LAGraph_rule_WCNF){0, -1, -1, 0};
154156

155157
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};
157159
}
158160

159161
// Complex grammar
@@ -404,6 +406,24 @@ void init_graph_3() {
404406
adj_matrices[1] = adj_matrix_b;
405407
}
406408

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+
407427
//====================
408428
// Tests with valid result
409429
//====================
@@ -514,6 +534,21 @@ void test_CFL_reachability_two_nodes_cycle(void) {
514534
teardown();
515535
}
516536

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+
517552
//====================
518553
// Tests with invalid result
519554
//====================
@@ -541,6 +576,11 @@ void test_CFL_reachability_invalid_rules(void) {
541576
(LAGraph_rule_WCNF){.nonterm = 10, .prod_A = 1, .prod_B = 2, .index = 0};
542577
check_error(GrB_INVALID_VALUE);
543578

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+
544584
// Rule [C -> t], where t >= terms_count
545585
grammar.rules[0] =
546586
(LAGraph_rule_WCNF){.nonterm = 0, .prod_A = 10, .prod_B = -1, .index = 0};
@@ -579,6 +619,7 @@ void test_CFL_reachability_null_pointers(void) {
579619
init_outputs() ;
580620

581621
adj_matrices[0] = NULL;
622+
adj_matrices[1] = NULL;
582623
check_error(GrB_NULL_POINTER);
583624

584625
adj_matrices = NULL;
@@ -615,6 +656,7 @@ TEST_LIST = {{"CFL_reachability_complex_grammar", test_CFL_reachability_complex_
615656
{"CFL_reachability_line", test_CFL_reachability_line},
616657
{"CFL_reachability_two_nodes_cycle", test_CFL_reachability_two_nodes_cycle},
617658
{"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},
618660
#if !defined ( GRAPHBLAS_HAS_CUDA )
619661
{"CFG_reachability_null_pointers", test_CFL_reachability_null_pointers},
620662
#endif

0 commit comments

Comments
 (0)