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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_Cached_NSelfEdges.c:  test LAGraph_Cached_NSelfEdges
       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             : #include "LAGraph_test.h"
      19             : 
      20             : //------------------------------------------------------------------------------
      21             : // global variables
      22             : //------------------------------------------------------------------------------
      23             : 
      24             : LAGraph_Graph G = NULL ;
      25             : GrB_Info info ;
      26             : char msg [LAGRAPH_MSG_LEN] ;
      27             : GrB_Matrix A = NULL ;
      28             : #define LEN 512
      29             : char filename [LEN+1] ;
      30             : 
      31             : //------------------------------------------------------------------------------
      32             : // test matrices
      33             : //------------------------------------------------------------------------------
      34             : 
      35             : typedef struct
      36             : {
      37             :     GrB_Index nself_edges ;
      38             :     const char *name ;
      39             : }
      40             : matrix_info ;
      41             : 
      42             : const matrix_info files [ ] =
      43             : {
      44             :      0, "A.mtx",
      45             :     14, "LFAT5.mtx",
      46             :   2003, "bcsstk13.mtx",
      47             : //   3, "complex.mtx",
      48             :      0, "cover.mtx",
      49             :      0, "cover_structure.mtx",
      50             :   2500, "cryg2500.mtx",
      51             :      3, "full.mtx",
      52             :      4, "full_symmetric.mtx",
      53             :   1138, "jagmesh7.mtx",
      54             :      0, "karate.mtx",
      55             :      0, "ldbc-cdlp-directed-example.mtx",
      56             :      0, "ldbc-cdlp-undirected-example.mtx",
      57             :      0, "ldbc-directed-example-bool.mtx",
      58             :      0, "ldbc-directed-example-unweighted.mtx",
      59             :      0, "ldbc-directed-example.mtx",
      60             :      0, "ldbc-undirected-example-bool.mtx",
      61             :      0, "ldbc-undirected-example-unweighted.mtx",
      62             :      0, "ldbc-undirected-example.mtx",
      63             :      0, "ldbc-wcc-example.mtx",
      64             :      0, "matrix_bool.mtx",
      65             :      0, "matrix_fp32.mtx",
      66             :      0, "matrix_fp32_structure.mtx",
      67             :      0, "matrix_fp64.mtx",
      68             :      0, "matrix_int16.mtx",
      69             :      0, "matrix_int32.mtx",
      70             :      0, "matrix_int64.mtx",
      71             :      0, "matrix_int8.mtx",
      72             :      0, "matrix_uint16.mtx",
      73             :      0, "matrix_uint32.mtx",
      74             :      0, "matrix_uint64.mtx",
      75             :      0, "matrix_uint8.mtx",
      76             :      0, "msf1.mtx",
      77             :      0, "msf2.mtx",
      78             :      0, "msf3.mtx",
      79             :   1000, "olm1000.mtx",
      80             :      0, "structure.mtx",
      81             :      0, "sample.mtx",
      82             :      0, "sample2.mtx",
      83             :      0, "skew_fp32.mtx",
      84             :      0, "skew_fp64.mtx",
      85             :      0, "skew_int16.mtx",
      86             :      0, "skew_int32.mtx",
      87             :      0, "skew_int64.mtx",
      88             :      0, "skew_int8.mtx",
      89             :      0, "tree-example.mtx",
      90             :      2, "west0067.mtx",
      91             :      2, "west0067_jumbled.mtx",
      92             :      0, ""
      93             : } ;
      94             : 
      95             : //------------------------------------------------------------------------------
      96             : // setup: start a test
      97             : //------------------------------------------------------------------------------
      98             : 
      99           1 : void setup (void)
     100             : {
     101           1 :     OK (LAGraph_Init (msg)) ;
     102           1 : }
     103             : 
     104             : //------------------------------------------------------------------------------
     105             : // teardown: finalize a test
     106             : //------------------------------------------------------------------------------
     107             : 
     108           1 : void teardown (void)
     109             : {
     110           1 :     OK (LAGraph_Finalize (msg)) ;
     111           1 : }
     112             : 
     113             : //------------------------------------------------------------------------------
     114             : // test_Cached_NSelfEdges:  test LAGraph_Cached_NSelfEdges
     115             : //------------------------------------------------------------------------------
     116             : 
     117           1 : void test_Cached_NSelfEdges (void)
     118             : {
     119             : 
     120             :     //--------------------------------------------------------------------------
     121             :     // start up the test
     122             :     //--------------------------------------------------------------------------
     123             : 
     124           1 :     setup ( ) ;
     125             : 
     126           1 :     for (int k = 0 ; ; k++)
     127          47 :     {
     128             : 
     129             :         //----------------------------------------------------------------------
     130             :         // load in the kth file
     131             :         //----------------------------------------------------------------------
     132             : 
     133          48 :         const char *aname = files [k].name ;
     134          48 :         if (strlen (aname) == 0) break;
     135          47 :         TEST_CASE (aname) ;
     136          47 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
     137          47 :         FILE *f = fopen (filename, "r") ;
     138          47 :         TEST_CHECK (f != NULL) ;
     139          47 :         OK (LAGraph_MMRead (&A, f, msg)) ;
     140          47 :         OK (fclose (f)) ;
     141          47 :         TEST_MSG ("Failed to load %s\n", aname) ;
     142             : 
     143             :         //----------------------------------------------------------------------
     144             :         // construct a directed graph and count self-edges
     145             :         //----------------------------------------------------------------------
     146             : 
     147          47 :         OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ;
     148          47 :         OK (LAGraph_Cached_NSelfEdges (G, msg)) ;
     149          47 :         TEST_CHECK (G->nself_edges == files [k].nself_edges) ;
     150             : 
     151             :         //----------------------------------------------------------------------
     152             :         // free the graph
     153             :         //----------------------------------------------------------------------
     154             : 
     155          47 :         OK (LAGraph_Delete (&G, msg)) ;
     156             :     }
     157             : 
     158           1 :     TEST_CHECK (LAGraph_Cached_NSelfEdges (NULL, msg) == GrB_NULL_POINTER) ;
     159             : 
     160             :     //--------------------------------------------------------------------------
     161             :     // finish the test
     162             :     //--------------------------------------------------------------------------
     163             : 
     164           1 :     teardown ( ) ;
     165           1 : }
     166             : 
     167             : //------------------------------------------------------------------------------
     168             : // test_Cached_NSelfEdges_brutal
     169             : //------------------------------------------------------------------------------
     170             : 
     171             : #if LAGRAPH_SUITESPARSE
     172           1 : void test_Cached_NSelfEdges_brutal (void)
     173             : {
     174           1 :     OK (LG_brutal_setup (msg)) ;
     175             : 
     176           1 :     for (int k = 0 ; ; k++)
     177          47 :     {
     178             : 
     179             :         //----------------------------------------------------------------------
     180             :         // load in the kth file
     181             :         //----------------------------------------------------------------------
     182             : 
     183          48 :         const char *aname = files [k].name ;
     184          48 :         if (strlen (aname) == 0) break;
     185          47 :         TEST_CASE (aname) ;
     186          47 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
     187          47 :         FILE *f = fopen (filename, "r") ;
     188          47 :         TEST_CHECK (f != NULL) ;
     189          47 :         OK (LAGraph_MMRead (&A, f, msg)) ;
     190          47 :         OK (fclose (f)) ;
     191          47 :         TEST_MSG ("Failed to load %s\n", aname) ;
     192             : 
     193             :         //----------------------------------------------------------------------
     194             :         // construct a directed graph and count self-edges
     195             :         //----------------------------------------------------------------------
     196             : 
     197          47 :         OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ;
     198         493 :         LG_BRUTAL (LAGraph_Cached_NSelfEdges (G, msg)) ;
     199          47 :         TEST_CHECK (G->nself_edges == files [k].nself_edges) ;
     200             : 
     201             :         //----------------------------------------------------------------------
     202             :         // free the graph
     203             :         //----------------------------------------------------------------------
     204             : 
     205          47 :         OK (LAGraph_Delete (&G, msg)) ;
     206             :     }
     207             : 
     208           1 :     OK (LG_brutal_teardown (msg)) ;
     209           1 : }
     210             : #endif
     211             : 
     212             : //-----------------------------------------------------------------------------
     213             : // TEST_LIST: the list of tasks for this entire test
     214             : //-----------------------------------------------------------------------------
     215             : 
     216             : TEST_LIST =
     217             : {
     218             :     { "NSelfEdges", test_Cached_NSelfEdges },
     219             :     #if LAGRAPH_SUITESPARSE
     220             :     { "NSelfEdges_brutal", test_Cached_NSelfEdges_brutal },
     221             :     #endif
     222             :     { NULL, NULL }
     223             : } ;

Generated by: LCOV version 1.14