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

          Line data    Source code
       1             : //-----------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_Vector_Print.c: test LAGraph_Vector_Print
       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             : char msg [LAGRAPH_MSG_LEN] ;
      21             : GrB_Vector v = NULL ;
      22             : GrB_Index n = 40 ;
      23             : 
      24             : //-----------------------------------------------------------------------------
      25             : // test_print
      26             : //-----------------------------------------------------------------------------
      27             : 
      28           1 : void test_print (void)
      29             : {
      30           1 :     OK (LAGraph_Init (msg)) ;
      31           1 :     printf ("\n") ;
      32           1 :     LAGraph_PrintLevel pr = LAGraph_SHORT ;
      33             : 
      34           1 :     OK (GrB_Vector_new (&v, GrB_BOOL, n)) ;
      35           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      36           1 :     OK (GrB_Vector_setElement (v, 1, 0)) ;
      37           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      38           1 :     OK (GrB_Vector_free (&v)) ;
      39             : 
      40           1 :     OK (GrB_Vector_new (&v, GrB_INT8, n)) ;
      41           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      42           1 :     OK (GrB_Vector_setElement (v, -8, 0)) ;
      43           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      44           1 :     OK (GrB_Vector_free (&v)) ;
      45             : 
      46           1 :     OK (GrB_Vector_new (&v, GrB_INT16, n)) ;
      47           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      48           1 :     OK (GrB_Vector_setElement (v, -16, 0)) ;
      49           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      50           1 :     OK (GrB_Vector_free (&v)) ;
      51             : 
      52           1 :     OK (GrB_Vector_new (&v, GrB_INT32, n)) ;
      53           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      54           1 :     OK (GrB_Vector_setElement (v, -32, 0)) ;
      55           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      56           1 :     OK (GrB_Vector_free (&v)) ;
      57             : 
      58           1 :     OK (GrB_Vector_new (&v, GrB_INT64, n)) ;
      59           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      60           1 :     OK (GrB_Vector_setElement (v, -64, 0)) ;
      61           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      62           1 :     OK (GrB_Vector_free (&v)) ;
      63             : 
      64           1 :     OK (GrB_Vector_new (&v, GrB_UINT8, n)) ;
      65           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      66           1 :     OK (GrB_Vector_setElement (v, 8, 0)) ;
      67           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      68           1 :     OK (GrB_Vector_free (&v)) ;
      69             : 
      70           1 :     OK (GrB_Vector_new (&v, GrB_UINT16, n)) ;
      71           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      72           1 :     OK (GrB_Vector_setElement (v, 16, 0)) ;
      73           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      74           1 :     OK (GrB_Vector_free (&v)) ;
      75             : 
      76           1 :     OK (GrB_Vector_new (&v, GrB_UINT32, n)) ;
      77           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      78           1 :     OK (GrB_Vector_setElement (v, 32, 0)) ;
      79           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      80           1 :     OK (GrB_Vector_free (&v)) ;
      81             : 
      82           1 :     OK (GrB_Vector_new (&v, GrB_UINT64, n)) ;
      83           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      84           1 :     OK (GrB_Vector_setElement (v, 64, 0)) ;
      85           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      86           1 :     OK (GrB_Vector_free (&v)) ;
      87             : 
      88           1 :     OK (GrB_Vector_new (&v, GrB_FP32, n)) ;
      89           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      90           1 :     OK (GrB_Vector_setElement (v, 3.14159, 0)) ;
      91           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      92           1 :     OK (GrB_Vector_free (&v)) ;
      93             : 
      94           1 :     OK (GrB_Vector_new (&v, GrB_FP64, n)) ;
      95           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      96           1 :     OK (GrB_Vector_setElement (v, 99.999, 0)) ;
      97           1 :     OK (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
      98             : 
      99             :     // attempt to print to a NULL file, which should fail
     100           1 :     int result = LAGraph_Vector_Print (v, pr, NULL, msg) ;
     101           1 :     TEST_CHECK (result == GrB_NULL_POINTER) ;
     102           1 :     OK (GrB_Vector_free (&v)) ;
     103             : 
     104             :     // attempt to print a vector with a user-defined type, which should fail
     105           1 :     GrB_Type type = NULL ;
     106           1 :     OK (GrB_Type_new (&type, sizeof (int))) ;
     107           1 :     OK (GrB_Vector_new (&v, type, n)) ;
     108           1 :     result = LAGraph_Vector_Print (v, pr, stdout, msg) ;
     109           1 :     TEST_CHECK (result == GrB_NOT_IMPLEMENTED) ;
     110           1 :     OK (GrB_Vector_free (&v)) ;
     111             : 
     112           1 :     OK (GrB_Type_free (&type)) ;
     113           1 :     OK (LAGraph_Finalize (msg)) ;
     114           1 : }
     115             : 
     116             : //-----------------------------------------------------------------------------
     117             : // test_print_brutal
     118             : //-----------------------------------------------------------------------------
     119             : 
     120             : #if LAGRAPH_SUITESPARSE
     121           1 : void test_print_brutal (void)
     122             : {
     123           1 :     OK (LG_brutal_setup (msg)) ;
     124           1 :     printf ("\n") ;
     125           1 :     LAGraph_PrintLevel pr = LAGraph_SHORT ;
     126             : 
     127           1 :     OK (GrB_Vector_new (&v, GrB_BOOL, n)) ;
     128           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     129           1 :     OK (GrB_Vector_setElement (v, 1, 0)) ;
     130           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     131           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     132           1 :     OK (GrB_Vector_free (&v)) ;
     133             : 
     134           1 :     OK (GrB_Vector_new (&v, GrB_INT8, n)) ;
     135           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     136           1 :     OK (GrB_Vector_setElement (v, -8, 0)) ;
     137           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     138           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     139           1 :     OK (GrB_Vector_free (&v)) ;
     140             : 
     141           1 :     OK (GrB_Vector_new (&v, GrB_INT16, n)) ;
     142           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     143           1 :     OK (GrB_Vector_setElement (v, -16, 0)) ;
     144           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     145           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     146           1 :     OK (GrB_Vector_free (&v)) ;
     147             : 
     148           1 :     OK (GrB_Vector_new (&v, GrB_INT32, n)) ;
     149           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     150           1 :     OK (GrB_Vector_setElement (v, -32, 0)) ;
     151           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     152           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     153           1 :     OK (GrB_Vector_free (&v)) ;
     154             : 
     155           1 :     OK (GrB_Vector_new (&v, GrB_INT64, n)) ;
     156           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     157           1 :     OK (GrB_Vector_setElement (v, -64, 0)) ;
     158           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     159           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     160           1 :     OK (GrB_Vector_free (&v)) ;
     161             : 
     162           1 :     OK (GrB_Vector_new (&v, GrB_UINT8, n)) ;
     163           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     164           1 :     OK (GrB_Vector_setElement (v, 8, 0)) ;
     165           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     166           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     167           1 :     OK (GrB_Vector_free (&v)) ;
     168             : 
     169           1 :     OK (GrB_Vector_new (&v, GrB_UINT16, n)) ;
     170           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     171           1 :     OK (GrB_Vector_setElement (v, 16, 0)) ;
     172           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     173           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     174           1 :     OK (GrB_Vector_free (&v)) ;
     175             : 
     176           1 :     OK (GrB_Vector_new (&v, GrB_UINT32, n)) ;
     177           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     178           1 :     OK (GrB_Vector_setElement (v, 32, 0)) ;
     179           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     180           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     181           1 :     OK (GrB_Vector_free (&v)) ;
     182             : 
     183           1 :     OK (GrB_Vector_new (&v, GrB_UINT64, n)) ;
     184           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     185           1 :     OK (GrB_Vector_setElement (v, 64, 0)) ;
     186           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     187           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     188           1 :     OK (GrB_Vector_free (&v)) ;
     189             : 
     190           1 :     OK (GrB_Vector_new (&v, GrB_FP32, n)) ;
     191           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     192           1 :     OK (GrB_Vector_setElement (v, 3.14159, 0)) ;
     193           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     194           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     195           1 :     OK (GrB_Vector_free (&v)) ;
     196             : 
     197           1 :     OK (GrB_Vector_new (&v, GrB_FP64, n)) ;
     198           1 :     OK (GrB_assign (v, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
     199           1 :     OK (GrB_Vector_setElement (v, 99.999, 0)) ;
     200           1 :     OK (GrB_wait (v, GrB_MATERIALIZE)) ;
     201           3 :     LG_BRUTAL_BURBLE (LAGraph_Vector_Print (v, pr, stdout, msg)) ;
     202           1 :     OK (GrB_Vector_free (&v)) ;
     203             : 
     204           1 :     OK (LG_brutal_teardown (msg)) ;
     205           1 : }
     206             : #endif
     207             : 
     208             : //-----------------------------------------------------------------------------
     209             : // TEST_LIST: the list of tasks for this entire test
     210             : //-----------------------------------------------------------------------------
     211             : 
     212             : TEST_LIST = {
     213             :     {"test_print", test_print},
     214             :     #if LAGRAPH_SUITESPARSE
     215             :     {"test_print_brutal", test_print_brutal},
     216             :     #endif
     217             :     {NULL, NULL}
     218             : };

Generated by: LCOV version 1.14