LCOV - code coverage report
Current view: top level - src/test - test_DeleteCached.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: 3b461aa. Current time (UTC): 2024-01-25T16:04:32Z Lines: 82 82 100.0 %
Date: 2024-01-25 16:05:28 Functions: 4 4 100.0 %

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_DeleteCached.c:  test LAGraph_DeleteCached
       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             : char msg [LAGRAPH_MSG_LEN] ;
      26             : GrB_Matrix A = NULL ;
      27             : #define LEN 512
      28             : char filename [LEN+1] ;
      29             : 
      30             : //------------------------------------------------------------------------------
      31             : // setup: start a test
      32             : //------------------------------------------------------------------------------
      33             : 
      34           1 : void setup (void)
      35             : {
      36           1 :     OK (LAGraph_Init (msg)) ;
      37           1 : }
      38             : 
      39             : //------------------------------------------------------------------------------
      40             : // teardown: finalize a test
      41             : //------------------------------------------------------------------------------
      42             : 
      43           1 : void teardown (void)
      44             : {
      45           1 :     OK (LAGraph_Finalize (msg)) ;
      46           1 : }
      47             : 
      48             : //------------------------------------------------------------------------------
      49             : // test_DeleteCached:  test LAGraph_DeleteCached
      50             : //------------------------------------------------------------------------------
      51             : 
      52             : typedef struct
      53             : {
      54             :     LAGraph_Kind kind ;
      55             :     const char *name ;
      56             : }
      57             : matrix_info ;
      58             : 
      59             : const matrix_info files [ ] =
      60             : {
      61             :     LAGraph_ADJACENCY_DIRECTED,   "cover.mtx",
      62             :     LAGraph_ADJACENCY_DIRECTED,   "ldbc-directed-example.mtx",
      63             :     LAGraph_ADJACENCY_UNDIRECTED, "ldbc-undirected-example.mtx",
      64             :     LAGraph_ADJACENCY_UNDIRECTED, "A.mtx",
      65             :     LAGraph_ADJACENCY_UNDIRECTED, "bcsstk13.mtx",
      66             :     LAGRAPH_UNKNOWN,              ""
      67             : } ;
      68             : 
      69           1 : void test_DeleteCached (void)
      70             : {
      71           1 :     setup ( ) ;
      72             : 
      73           1 :     for (int k = 0 ; ; k++)
      74           5 :     {
      75             : 
      76             :         // load the matrix as A
      77           6 :         const char *aname = files [k].name ;
      78           6 :         if (strlen (aname) == 0) break;
      79           5 :         LAGraph_Kind kind = files [k].kind ;
      80           5 :         TEST_CASE (aname) ;
      81           5 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
      82           5 :         FILE *f = fopen (filename, "r") ;
      83           5 :         TEST_CHECK (f != NULL) ;
      84           5 :         OK (LAGraph_MMRead (&A, f, msg)) ;
      85           5 :         OK (fclose (f)) ;
      86           5 :         TEST_MSG ("Loading of adjacency matrix failed") ;
      87             : 
      88             :         // construct the graph G with adjacency matrix A
      89           5 :         OK (LAGraph_New (&G, &A, kind, msg)) ;
      90           5 :         TEST_CHECK (A == NULL) ;
      91             : 
      92             :         // create all cached properties (see test_Cached_* for tests of content)
      93           5 :         int ok_result = (kind == LAGraph_ADJACENCY_UNDIRECTED) ?
      94           5 :             LAGRAPH_CACHE_NOT_NEEDED : GrB_SUCCESS ;
      95           5 :         OK (LAGraph_Cached_OutDegree (G, msg)) ;
      96           5 :         int result = LAGraph_Cached_InDegree (G, msg) ;
      97           5 :         TEST_CHECK (result == ok_result) ;
      98           5 :         result = LAGraph_Cached_AT (G, msg) ;
      99           5 :         TEST_CHECK (result == ok_result) ;
     100           5 :         OK (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
     101             : 
     102             :         // print them
     103           5 :         printf ("\nGraph: nself_edges %g, symmetric structure: %d\n",
     104           5 :             (double) G->nself_edges, G->is_symmetric_structure) ;
     105           5 :         printf ("  adj matrix: ") ;
     106           5 :         int rr = (LAGraph_Matrix_Print (G->A, LAGraph_SHORT, stdout, msg)) ;
     107           5 :         printf ("result: %d msg: %s\n", rr, msg) ;
     108           5 :         printf ("  out degree: ") ;
     109           5 :         OK (LAGraph_Vector_Print (G->out_degree, LAGraph_SHORT, stdout, msg)) ;
     110           5 :         if (kind == LAGraph_ADJACENCY_DIRECTED)
     111             :         {
     112           2 :             printf ("  adj transposed: ") ;
     113           2 :             OK (LAGraph_Matrix_Print (G->AT, LAGraph_SHORT, stdout, msg)) ;
     114           2 :             printf ("  in degree: ") ;
     115           2 :             OK (LAGraph_Vector_Print (G->in_degree, LAGraph_SHORT, stdout,
     116             :                 msg)) ;
     117             :         }
     118             :         else
     119             :         {
     120           3 :             TEST_CHECK (G->AT == NULL) ;
     121           3 :             TEST_CHECK (G->in_degree == NULL) ;
     122             :         }
     123             : 
     124          15 :         for (int trial = 0 ; trial <= 1 ; trial++)
     125             :         {
     126             :             // delete all the cached properties
     127          10 :             OK (LAGraph_DeleteCached (G, msg)) ;
     128          10 :             TEST_CHECK (G->AT == NULL) ;
     129          10 :             TEST_CHECK (G->out_degree == NULL) ;
     130          10 :             TEST_CHECK (G->in_degree == NULL) ;
     131             :         }
     132             : 
     133           5 :         OK (LAGraph_Delete (&G, msg)) ;
     134             :     }
     135             : 
     136           1 :     OK (LAGraph_DeleteCached (NULL, msg)) ;
     137             : 
     138           1 :     teardown ( ) ;
     139           1 : }
     140             : 
     141             : //-----------------------------------------------------------------------------
     142             : 
     143             : #if LAGRAPH_SUITESPARSE
     144           1 : void test_del_brutal (void)
     145             : {
     146           1 :     OK (LG_brutal_setup (msg)) ;
     147             : 
     148           1 :     for (int k = 0 ; ; k++)
     149           5 :     {
     150             : 
     151             :         // load the matrix as A
     152           6 :         const char *aname = files [k].name ;
     153           6 :         if (strlen (aname) == 0) break;
     154           5 :         LAGraph_Kind kind = files [k].kind ;
     155           5 :         TEST_CASE (aname) ;
     156           5 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
     157           5 :         FILE *f = fopen (filename, "r") ;
     158           5 :         TEST_CHECK (f != NULL) ;
     159           5 :         OK (LAGraph_MMRead (&A, f, msg)) ;
     160           5 :         OK (fclose (f)) ;
     161           5 :         TEST_MSG ("Loading of adjacency matrix failed") ;
     162             : 
     163             :         // construct the graph G with adjacency matrix A
     164          10 :         LG_BRUTAL (LAGraph_New (&G, &A, kind, msg)) ;
     165           5 :         TEST_CHECK (A == NULL) ;
     166             : 
     167             :         // create all cached properties (see test_Cached_* for tests of content)
     168          39 :         LG_BRUTAL (LAGraph_Cached_OutDegree (G, msg)) ;
     169          19 :         LG_BRUTAL (LAGraph_Cached_InDegree (G, msg)) ;
     170          15 :         LG_BRUTAL (LAGraph_Cached_AT (G, msg)) ;
     171          17 :         LG_BRUTAL (LAGraph_Cached_IsSymmetricStructure (G, msg)) ;
     172             : 
     173          15 :         for (int trial = 0 ; trial <= 1 ; trial++)
     174             :         {
     175             :             // delete all the cached properties
     176          10 :             LG_BRUTAL (LAGraph_DeleteCached (G, msg)) ;
     177          10 :             TEST_CHECK (G->AT == NULL) ;
     178          10 :             TEST_CHECK (G->out_degree == NULL) ;
     179          10 :             TEST_CHECK (G->in_degree == NULL) ;
     180             :         }
     181             : 
     182           5 :         LG_BRUTAL (LAGraph_Delete (&G, msg)) ;
     183           5 :         LG_BRUTAL (LAGraph_DeleteCached (NULL, msg)) ;
     184             :     }
     185             : 
     186           1 :     OK (LG_brutal_teardown (msg)) ;
     187           1 : }
     188             : #endif
     189             : 
     190             : //-----------------------------------------------------------------------------
     191             : // TEST_LIST: the list of tasks for this entire test
     192             : //-----------------------------------------------------------------------------
     193             : 
     194             : TEST_LIST =
     195             : {
     196             :     { "test_DeleteCached", test_DeleteCached },
     197             :     #if LAGRAPH_SUITESPARSE
     198             :     { "test_DeleteCached_brutal", test_del_brutal },
     199             :     #endif
     200             :     { NULL, NULL }
     201             : } ;

Generated by: LCOV version 1.14