LCOV - code coverage report
Current view: top level - experimental/test - test_scc.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: cc56ed4. Current time (UTC): 2024-08-30T17:14:30Z Lines: 50 50 100.0 %
Date: 2024-08-30 17:16:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/experimental/test/test_scc.c: tests for Strongly Connected Components
       3             : //------------------------------------------------------------------------------
       4             : 
       5             : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
       6             : // SPDX-License-Identifier: BSD-2-Clause
       7             : //
       8             : // For additional details (including references to third party source code and
       9             : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See
      10             : // Contributors.txt for a full list of contributors. Created, in part, with
      11             : // funding and support from the U.S. Government (see Acknowledgments.txt file).
      12             : // DM22-0790
      13             : 
      14             : // Contributed by Timothy A. Davis, Texas A&M University
      15             : 
      16             : //------------------------------------------------------------------------------
      17             : 
      18             : // todo: write a simple scc method, as LG_check_scc, and compare its results
      19             : // with LAGraph_scc
      20             : 
      21             : #include <stdio.h>
      22             : #include <acutest.h>
      23             : 
      24             : #include <LAGraphX.h>
      25             : #include <LAGraph_test.h>
      26             : 
      27             : char msg [LAGRAPH_MSG_LEN] ;
      28             : LAGraph_Graph G = NULL ;
      29             : GrB_Matrix A = NULL ;
      30             : #define LEN 512
      31             : char filename [LEN+1] ;
      32             : 
      33             : typedef struct
      34             : {
      35             :     const char *name ;
      36             : }
      37             : matrix_info ;
      38             : 
      39             : int scc_cover [7] = { 0, 0, 2, 0, 4, 2, 0 } ;
      40             : 
      41             : const matrix_info files [ ] =
      42             : {
      43             :     { "A2.mtx" },
      44             :     { "A.mtx" },
      45             :     { "bcsstk13.mtx" },
      46             :     { "cover.mtx" },
      47             :     { "cover_structure.mtx" },
      48             :     { "cryg2500.mtx" },
      49             :     { "full.mtx" },
      50             :     { "full_noheader.mtx" },
      51             :     { "full_symmetric.mtx" },
      52             :     { "jagmesh7.mtx" },
      53             :     { "karate.mtx" },
      54             :     { "ldbc-cdlp-directed-example.mtx" },
      55             :     { "ldbc-cdlp-undirected-example.mtx" },
      56             :     { "ldbc-directed-example-bool.mtx" },
      57             :     { "ldbc-directed-example.mtx" },
      58             :     { "ldbc-directed-example-unweighted.mtx" },
      59             :     { "ldbc-undirected-example-bool.mtx" },
      60             :     { "ldbc-undirected-example.mtx" },
      61             :     { "ldbc-undirected-example-unweighted.mtx" },
      62             :     { "ldbc-wcc-example.mtx" },
      63             :     { "LFAT5.mtx" },
      64             :     { "LFAT5_two.mtx" },
      65             :     { "matrix_bool.mtx" },
      66             :     { "matrix_fp32.mtx" },
      67             :     { "matrix_fp32_structure.mtx" },
      68             :     { "matrix_fp64.mtx" },
      69             :     { "matrix_int16.mtx" },
      70             :     { "matrix_int32.mtx" },
      71             :     { "matrix_int64.mtx" },
      72             :     { "matrix_int8.mtx" },
      73             :     { "matrix_uint16.mtx" },
      74             :     { "matrix_uint32.mtx" },
      75             :     { "matrix_uint64.mtx" },
      76             :     { "matrix_uint8.mtx" },
      77             :     { "msf1.mtx" },
      78             :     { "msf2.mtx" },
      79             :     { "msf3.mtx" },
      80             :     { "olm1000.mtx" },
      81             :     { "pushpull.mtx" },
      82             :     { "sample2.mtx" },
      83             :     { "sample.mtx" },
      84             :     { "structure.mtx" },
      85             :     { "test_BF.mtx" },
      86             :     { "test_FW_1000.mtx" },
      87             :     { "test_FW_2003.mtx" },
      88             :     { "test_FW_2500.mtx" },
      89             :     { "tree-example.mtx" },
      90             :     { "west0067_jumbled.mtx" },
      91             :     { "west0067.mtx" },
      92             :     { "west0067_noheader.mtx" },
      93             :     { "zenios.mtx" },
      94             :     { "" },
      95             : } ;
      96             : 
      97             : //****************************************************************************
      98           1 : void test_scc (void)
      99             : {
     100           1 :     LAGraph_Init (msg) ;
     101             :     #if LAGRAPH_SUITESPARSE
     102             : 
     103           1 :     for (int k = 0 ; ; k++)
     104          51 :     {
     105             : 
     106             :         // load the matrix as A
     107          52 :         const char *aname = files [k].name ;
     108          52 :         if (strlen (aname) == 0) break;
     109          51 :         printf ("\n================================== %s:\n", aname) ;
     110          51 :         TEST_CASE (aname) ;
     111          51 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
     112          51 :         FILE *f = fopen (filename, "r") ;
     113          51 :         TEST_CHECK (f != NULL) ;
     114          51 :         OK (LAGraph_MMRead (&A, f, msg)) ;
     115             : 
     116             :         // construct a directed graph G with adjacency matrix A
     117          51 :         OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ;
     118          51 :         TEST_CHECK (A == NULL) ;
     119             : 
     120          51 :         GrB_Vector c = NULL ;
     121             : 
     122             :         // find the strongly connected components with LAGraph_scc
     123          51 :         OK (LAGraph_scc (&c, G->A, msg)) ;
     124             : 
     125             :         GrB_Index n ;
     126          51 :         OK (GrB_Vector_size (&n, c)) ;
     127          51 :         LAGraph_PrintLevel pr = (n <= 100) ? LAGraph_COMPLETE : LAGraph_SHORT ;
     128             : 
     129             :         // check result c for cover
     130          51 :         if (strcmp (aname, "cover.mtx") == 0)
     131             :         {
     132           1 :             GrB_Vector cgood = NULL ;
     133           1 :             OK (GrB_Vector_new (&cgood, GrB_UINT64, n)) ;
     134           8 :             for (int k = 0 ; k < n ; k++)
     135             :             {
     136           7 :                 OK (GrB_Vector_setElement (cgood, scc_cover [k], k)) ;
     137             :             }
     138           1 :             OK (GrB_wait (cgood, GrB_MATERIALIZE)) ;
     139           1 :             printf ("\nscc (known result):\n") ;
     140           1 :             OK (LAGraph_Vector_Print (cgood, pr, stdout, msg)) ;
     141           1 :             bool ok = false ;
     142           1 :             OK (LAGraph_Vector_IsEqual (&ok, c, cgood, msg)) ;
     143           1 :             TEST_CHECK (ok) ;
     144           1 :             OK (GrB_free (&cgood)) ;
     145             :         }
     146             : 
     147          51 :         printf ("\nscc:\n") ;
     148          51 :         OK (LAGraph_Vector_Print (c, pr, stdout, msg)) ;
     149          51 :         OK (GrB_free (&c)) ;
     150          51 :         OK (LAGraph_Delete (&G, msg)) ;
     151             :     }
     152             : 
     153             :     #else
     154             :     printf ("test skipped\n") ;
     155             :     #endif
     156           1 :     LAGraph_Finalize (msg) ;
     157           1 : }
     158             : 
     159             : //------------------------------------------------------------------------------
     160             : // test_errors
     161             : //------------------------------------------------------------------------------
     162             : 
     163           1 : void test_errors (void)
     164             : {
     165           1 :     LAGraph_Init (msg) ;
     166             :     #if LAGRAPH_SUITESPARSE
     167             : 
     168           1 :     GrB_Vector c = NULL ;
     169           1 :     GrB_Matrix A = NULL ;
     170             : 
     171             :     // c and A are NULL
     172           1 :     int result = LAGraph_scc (NULL, A, msg) ;
     173           1 :     printf ("\nresult: %d\n", result) ;
     174           1 :     TEST_CHECK (result == GrB_NULL_POINTER) ;
     175             : 
     176             :     // A is rectangular
     177           1 :     OK (GrB_Matrix_new (&A, GrB_BOOL, 3, 4)) ;
     178           1 :     result = LAGraph_scc (&c, A, msg) ;
     179           1 :     TEST_CHECK (result == GrB_DIMENSION_MISMATCH) ;
     180             : 
     181           1 :     OK (GrB_free (&c)) ;
     182           1 :     OK (GrB_free (&A)) ;
     183             :     #else
     184             :     printf ("test skipped\n") ;
     185             :     #endif
     186           1 :     LAGraph_Finalize (msg) ;
     187           1 : }
     188             : 
     189             : //****************************************************************************
     190             : 
     191             : TEST_LIST = {
     192             :     {"scc", test_scc},
     193             :     {"scc_errors", test_errors},
     194             :     {NULL, NULL}
     195             : };

Generated by: LCOV version 1.14