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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_New.c:  test LAGraph_New and LAGraph_Delete
       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           2 : void setup (void)
      35             : {
      36           2 :     OK (LAGraph_Init (msg)) ;
      37           2 : }
      38             : 
      39             : //------------------------------------------------------------------------------
      40             : // teardown: finalize a test
      41             : //------------------------------------------------------------------------------
      42             : 
      43           2 : void teardown (void)
      44             : {
      45           2 :     OK (LAGraph_Finalize (msg)) ;
      46           2 : }
      47             : 
      48             : //------------------------------------------------------------------------------
      49             : // test_New:  test LAGraph_New
      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_UNKNOWN,              ""
      65             : } ;
      66             : 
      67           1 : void test_New (void)
      68             : {
      69           1 :     setup ( ) ;
      70             : 
      71           1 :     for (int k = 0 ; ; k++)
      72           3 :     {
      73             : 
      74             :         // load the adjacency matrix as A
      75           4 :         const char *aname = files [k].name ;
      76           4 :         LAGraph_Kind kind = files [k].kind ;
      77           4 :         if (strlen (aname) == 0) break;
      78           3 :         TEST_CASE (aname) ;
      79           3 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
      80           3 :         FILE *f = fopen (filename, "r") ;
      81           3 :         TEST_CHECK (f != NULL) ;
      82           3 :         OK (LAGraph_MMRead (&A, f, msg)) ;
      83           3 :         OK (fclose (f)) ;
      84           3 :         TEST_MSG ("Loading of adjacency matrix failed") ;
      85             : 
      86             :         // create the graph
      87           3 :         OK (LAGraph_New (&G, &A, kind, msg)) ;
      88           3 :         TEST_CHECK (A == NULL) ;    // A has been moved into G->A
      89             : 
      90             :         // check the graph
      91           3 :         OK (LAGraph_CheckGraph (G, msg)) ;
      92           3 :         TEST_CHECK (G->kind == kind) ;
      93           3 :         if (kind == LAGraph_ADJACENCY_DIRECTED)
      94             :         {
      95           2 :             TEST_CHECK (G->is_symmetric_structure == LAGRAPH_UNKNOWN) ;
      96             :         }
      97             :         else
      98             :         {
      99           1 :             TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
     100             :         }
     101             : 
     102             :         // free the graph
     103           3 :         OK (LAGraph_Delete (&G, msg)) ;
     104           3 :         TEST_CHECK (G == NULL) ;
     105             :     }
     106           1 :     teardown ( ) ;
     107           1 : }
     108             : 
     109             : //------------------------------------------------------------------------------
     110             : // test_New_brutal
     111             : //------------------------------------------------------------------------------
     112             : 
     113             : #if LAGRAPH_SUITESPARSE
     114           1 : void test_New_brutal (void)
     115             : {
     116           1 :     OK (LG_brutal_setup (msg)) ;
     117           1 :     printf ("\n") ;
     118             : 
     119           1 :     for (int k = 0 ; ; k++)
     120           3 :     {
     121             : 
     122             :         // load the adjacency matrix as A
     123           4 :         const char *aname = files [k].name ;
     124           4 :         LAGraph_Kind kind = files [k].kind ;
     125           4 :         if (strlen (aname) == 0) break;
     126           3 :         TEST_CASE (aname) ;
     127           3 :         snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
     128           3 :         FILE *f = fopen (filename, "r") ;
     129           3 :         TEST_CHECK (f != NULL) ;
     130           3 :         OK (LAGraph_MMRead (&A, f, msg)) ;
     131           3 :         OK (fclose (f)) ;
     132           3 :         TEST_MSG ("Loading of adjacency matrix failed") ;
     133             : 
     134             :         // create the graph
     135           6 :         LG_BRUTAL_BURBLE (LAGraph_New (&G, &A, kind, msg)) ;
     136           3 :         TEST_CHECK (A == NULL) ;    // A has been moved into G->A
     137             : 
     138             :         // check the graph
     139           3 :         LG_BRUTAL_BURBLE (LAGraph_CheckGraph (G, msg)) ;
     140             : 
     141             :         // free the graph
     142           3 :         LG_BRUTAL_BURBLE (LAGraph_Delete (&G, msg)) ;
     143           3 :         TEST_CHECK (G == NULL) ;
     144             :     }
     145             : 
     146           1 :     OK (LG_brutal_teardown (msg)) ;
     147           1 : }
     148             : #endif
     149             : 
     150             : //------------------------------------------------------------------------------
     151             : // test_New_failures:  test error handling of LAGraph_New
     152             : //------------------------------------------------------------------------------
     153             : 
     154           1 : void test_New_failures (void)
     155             : {
     156           1 :     setup ( ) ;
     157             : 
     158             :     // G cannot be NULL
     159           1 :     TEST_CHECK (LAGraph_New (NULL, NULL, 0, msg) == GrB_NULL_POINTER) ;
     160           1 :     printf ("\nmsg: %s\n", msg) ;
     161             : 
     162             :     // create a graph with no adjacency matrix; this is OK, since the intent is
     163             :     // to create a graph for which the adjacency matrix can be defined later,
     164             :     // via assigning it to G->A.  However, the graph will be declared invalid
     165             :     // by LAGraph_CheckGraph since G->A is NULL.
     166           1 :     OK (LAGraph_New (&G, NULL, 0, msg)) ;
     167           1 :     TEST_CHECK (LAGraph_CheckGraph (G, msg) == LAGRAPH_INVALID_GRAPH) ;
     168           1 :     printf ("msg: %s\n", msg) ;
     169           1 :     OK (LAGraph_Delete (&G, msg)) ;
     170           1 :     TEST_CHECK (G == NULL) ;
     171           1 :     OK (LAGraph_Delete (&G, msg)) ;
     172           1 :     TEST_CHECK (G == NULL) ;
     173           1 :     OK (LAGraph_Delete (NULL, msg)) ;
     174           1 :     teardown ( ) ;
     175           1 : }
     176             : 
     177             : //-----------------------------------------------------------------------------
     178             : // TEST_LIST: the list of tasks for this entire test
     179             : //-----------------------------------------------------------------------------
     180             : 
     181             : TEST_LIST =
     182             : {
     183             :     { "New", test_New },
     184             :     { "New_failures", test_New_failures },
     185             :     #if LAGRAPH_SUITESPARSE
     186             :     { "New_brutal", test_New_brutal },
     187             :     #endif
     188             :     { NULL, NULL }
     189             : } ;

Generated by: LCOV version 1.14