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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_Vector_Structure.c:  test LAGraph_Vector_Structure
       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             : #include "LG_internal.h"
      20             : 
      21             : //------------------------------------------------------------------------------
      22             : // global variables
      23             : //------------------------------------------------------------------------------
      24             : 
      25             : char msg [LAGRAPH_MSG_LEN] ;
      26             : GrB_Vector w = NULL, u = NULL ;
      27             : #define LEN 512
      28             : char wtype_name [LAGRAPH_MAX_NAME_LEN] ;
      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_Vector_Structure:  test LAGraph_Vector_Structure
      50             : //------------------------------------------------------------------------------
      51             : 
      52           1 : void test_Vector_Structure (void)
      53             : {
      54           1 :     setup ( ) ;
      55           1 :     printf ("\n") ;
      56             : 
      57             :     // create a test vector
      58           1 :     GrB_Index n = 10 ;
      59           1 :     OK (GrB_Vector_new (&u, GrB_FP64, n)) ;
      60           1 :     OK (GrB_Vector_setElement_FP64 (u, 3.5, 0)) ;
      61           1 :     OK (GrB_Vector_setElement_FP64 (u, 4.7, 3)) ;
      62           1 :     OK (GrB_Vector_setElement_FP64 (u, 9.8, 7)) ;
      63           1 :     OK (LAGraph_Vector_Print (u, LAGraph_COMPLETE_VERBOSE, stdout, msg)) ;
      64             : 
      65             :     // get its structure
      66           1 :     int result = LAGraph_Vector_Structure (&w, u, msg) ;
      67           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
      68           1 :     OK (LAGraph_Vector_Print (w, LAGraph_COMPLETE_VERBOSE, stdout, msg)) ;
      69             : 
      70             :     // check it
      71             :     GrB_Index nvals ;
      72           1 :     OK (GrB_Vector_size (&n, u)) ;
      73           1 :     TEST_CHECK (n == 10) ;
      74           1 :     OK (GrB_Vector_nvals (&nvals, u)) ;
      75           1 :     TEST_CHECK (nvals == 3) ;
      76           1 :     OK (LAGraph_Vector_TypeName (wtype_name, w, msg)) ;
      77           1 :     TEST_CHECK (MATCHNAME (wtype_name, "bool")) ;
      78             : 
      79           1 :     bool x = false ;
      80           1 :     result = GrB_Vector_extractElement_BOOL (&x, w, 0) ;
      81           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
      82           1 :     TEST_CHECK (x) ;
      83             : 
      84           1 :     x = false ;
      85           1 :     result = GrB_Vector_extractElement_BOOL (&x, w, 3) ;
      86           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
      87           1 :     TEST_CHECK (x) ;
      88             : 
      89           1 :     x = false ;
      90           1 :     result = GrB_Vector_extractElement_BOOL (&x, w, 7) ;
      91           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
      92           1 :     TEST_CHECK (x) ;
      93             : 
      94           1 :     OK (GrB_free (&w)) ;
      95           1 :     OK (GrB_free (&u)) ;
      96             : 
      97           1 :     teardown ( ) ;
      98           1 : }
      99             : 
     100             : //------------------------------------------------------------------------------
     101             : // test_Vector_Structure_brutal
     102             : //------------------------------------------------------------------------------
     103             : 
     104             : #if LAGRAPH_SUITESPARSE
     105           1 : void test_Vector_Structure_brutal (void)
     106             : {
     107           1 :     OK (LG_brutal_setup (msg)) ;
     108           1 :     printf ("\n") ;
     109             : 
     110             :     // create a test vector
     111           1 :     GrB_Index n = 10 ;
     112           1 :     OK (GrB_Vector_new (&u, GrB_FP64, n)) ;
     113           1 :     OK (GrB_Vector_setElement_FP64 (u, 3.5, 0)) ;
     114           1 :     OK (GrB_Vector_setElement_FP64 (u, 4.7, 3)) ;
     115           1 :     OK (GrB_Vector_setElement_FP64 (u, 9.8, 7)) ;
     116             : 
     117             :     // get its structure
     118           1 :     int result = LAGraph_Vector_Structure (&w, u, msg) ;
     119           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
     120           1 :     OK (LAGraph_Vector_Print (w, LAGraph_COMPLETE_VERBOSE, stdout, msg)) ;
     121             : 
     122             :     // check it
     123             :     GrB_Index nvals ;
     124           1 :     OK (GrB_Vector_size (&n, u)) ;
     125           1 :     TEST_CHECK (n == 10) ;
     126           1 :     OK (GrB_Vector_nvals (&nvals, u)) ;
     127           1 :     TEST_CHECK (nvals == 3) ;
     128           1 :     OK (LAGraph_Vector_TypeName (wtype_name, w, msg)) ;
     129           1 :     TEST_CHECK (MATCHNAME (wtype_name, "bool")) ;
     130             : 
     131           1 :     bool x = false ;
     132           1 :     result = GrB_Vector_extractElement_BOOL (&x, w, 0) ;
     133           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
     134           1 :     TEST_CHECK (x) ;
     135             : 
     136           1 :     x = false ;
     137           1 :     result = GrB_Vector_extractElement_BOOL (&x, w, 3) ;
     138           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
     139           1 :     TEST_CHECK (x) ;
     140             : 
     141           1 :     x = false ;
     142           1 :     result = GrB_Vector_extractElement_BOOL (&x, w, 7) ;
     143           1 :     TEST_CHECK (result == GrB_SUCCESS) ;
     144           1 :     TEST_CHECK (x) ;
     145             : 
     146             : 
     147           1 :     OK (GrB_free (&w)) ;
     148           1 :     OK (GrB_free (&u)) ;
     149             : 
     150             : 
     151           1 :     OK (LG_brutal_teardown (msg)) ;
     152           1 : }
     153             : #endif
     154             : 
     155             : //------------------------------------------------------------------------------
     156             : // test_Vector_Structure_failures: test LAGraph_Vector_Structure error handling
     157             : //------------------------------------------------------------------------------
     158             : 
     159           1 : void test_Vector_Structure_failures (void)
     160             : {
     161           1 :     setup ( ) ;
     162             : 
     163           1 :     w = NULL ;
     164           1 :     int result = LAGraph_Vector_Structure (NULL, NULL, msg) ;
     165           1 :     TEST_CHECK (result == GrB_NULL_POINTER) ;
     166           1 :     printf ("\nmsg: [%s]\n", msg) ;
     167           1 :     result = LAGraph_Vector_Structure (&w, NULL, msg) ;
     168           1 :     TEST_CHECK (result == GrB_NULL_POINTER) ;
     169           1 :     printf ("msg: [%s]\n", msg) ;
     170           1 :     TEST_CHECK (w == NULL) ;
     171             : 
     172           1 :     teardown ( ) ;
     173           1 : }
     174             : 
     175             : //-----------------------------------------------------------------------------
     176             : // TEST_LIST: the list of tasks for this entire test
     177             : //-----------------------------------------------------------------------------
     178             : 
     179             : TEST_LIST =
     180             : {
     181             :     { "Vector_Structure", test_Vector_Structure },
     182             :     { "Vector_Structure_failures", test_Vector_Structure_failures },
     183             :     #if LAGRAPH_SUITESPARSE
     184             :     { "Vector_Structure_brutal", test_Vector_Structure_brutal },
     185             :     #endif
     186             :     { NULL, NULL }
     187             : } ;

Generated by: LCOV version 1.14