#include "LAGraph_test.h"
#include "LG_internal.h"
char msg [LAGRAPH_MSG_LEN] ;
GrB_Vector w = NULL, u = NULL ;
#define LEN 512
char wtype_name [LAGRAPH_MAX_NAME_LEN] ;
void setup (void)
{
OK (LAGraph_Init (msg)) ;
}
void teardown (void)
{
OK (LAGraph_Finalize (msg)) ;
}
void test_Vector_Structure (void)
{
setup ( ) ;
printf ("\n") ;
GrB_Index n = 10 ;
OK (GrB_Vector_new (&u, GrB_FP64, n)) ;
OK (GrB_Vector_setElement_FP64 (u, 3.5, 0)) ;
OK (GrB_Vector_setElement_FP64 (u, 4.7, 3)) ;
OK (GrB_Vector_setElement_FP64 (u, 9.8, 7)) ;
OK (LAGraph_Vector_Print (u, LAGraph_COMPLETE_VERBOSE, stdout, msg)) ;
int result = LAGraph_Vector_Structure (&w, u, msg) ;
TEST_CHECK (result == GrB_SUCCESS) ;
OK (LAGraph_Vector_Print (w, LAGraph_COMPLETE_VERBOSE, stdout, msg)) ;
GrB_Index nvals ;
OK (GrB_Vector_size (&n, u)) ;
TEST_CHECK (n == 10) ;
OK (GrB_Vector_nvals (&nvals, u)) ;
TEST_CHECK (nvals == 3) ;
OK (LAGraph_Vector_TypeName (wtype_name, w, msg)) ;
TEST_CHECK (MATCHNAME (wtype_name, "bool")) ;
bool x = false ;
result = GrB_Vector_extractElement_BOOL (&x, w, 0) ;
TEST_CHECK (result == GrB_SUCCESS) ;
TEST_CHECK (x) ;
x = false ;
result = GrB_Vector_extractElement_BOOL (&x, w, 3) ;
TEST_CHECK (result == GrB_SUCCESS) ;
TEST_CHECK (x) ;
x = false ;
result = GrB_Vector_extractElement_BOOL (&x, w, 7) ;
TEST_CHECK (result == GrB_SUCCESS) ;
TEST_CHECK (x) ;
OK (GrB_free (&w)) ;
OK (GrB_free (&u)) ;
teardown ( ) ;
}
#if LG_BRUTAL_TESTS
void test_Vector_Structure_brutal (void)
{
OK (LG_brutal_setup (msg)) ;
printf ("\n") ;
GrB_Index n = 10 ;
OK (GrB_Vector_new (&u, GrB_FP64, n)) ;
OK (GrB_Vector_setElement_FP64 (u, 3.5, 0)) ;
OK (GrB_Vector_setElement_FP64 (u, 4.7, 3)) ;
OK (GrB_Vector_setElement_FP64 (u, 9.8, 7)) ;
int result = LAGraph_Vector_Structure (&w, u, msg) ;
TEST_CHECK (result == GrB_SUCCESS) ;
OK (LAGraph_Vector_Print (w, LAGraph_COMPLETE_VERBOSE, stdout, msg)) ;
GrB_Index nvals ;
OK (GrB_Vector_size (&n, u)) ;
TEST_CHECK (n == 10) ;
OK (GrB_Vector_nvals (&nvals, u)) ;
TEST_CHECK (nvals == 3) ;
OK (LAGraph_Vector_TypeName (wtype_name, w, msg)) ;
TEST_CHECK (MATCHNAME (wtype_name, "bool")) ;
bool x = false ;
result = GrB_Vector_extractElement_BOOL (&x, w, 0) ;
TEST_CHECK (result == GrB_SUCCESS) ;
TEST_CHECK (x) ;
x = false ;
result = GrB_Vector_extractElement_BOOL (&x, w, 3) ;
TEST_CHECK (result == GrB_SUCCESS) ;
TEST_CHECK (x) ;
x = false ;
result = GrB_Vector_extractElement_BOOL (&x, w, 7) ;
TEST_CHECK (result == GrB_SUCCESS) ;
TEST_CHECK (x) ;
OK (GrB_free (&w)) ;
OK (GrB_free (&u)) ;
OK (LG_brutal_teardown (msg)) ;
}
#endif
void test_Vector_Structure_failures (void)
{
setup ( ) ;
w = NULL ;
int result = LAGraph_Vector_Structure (NULL, NULL, msg) ;
TEST_CHECK (result == GrB_NULL_POINTER) ;
printf ("\nmsg: [%s]\n", msg) ;
result = LAGraph_Vector_Structure (&w, NULL, msg) ;
TEST_CHECK (result == GrB_NULL_POINTER) ;
printf ("msg: [%s]\n", msg) ;
TEST_CHECK (w == NULL) ;
teardown ( ) ;
}
TEST_LIST =
{
{ "Vector_Structure", test_Vector_Structure },
{ "Vector_Structure_failures", test_Vector_Structure_failures },
#if LG_BRUTAL_TESTS
{ "Vector_Structure_brutal", test_Vector_Structure_brutal },
#endif
{ NULL, NULL }
} ;