#include "LAGraph_test.h"
LAGraph_Graph G = NULL ;
char msg [LAGRAPH_MSG_LEN] ;
GrB_Matrix A = NULL ;
#define LEN 512
char filename [LEN+1] ;
void setup (void)
{
OK (LAGraph_Init (msg)) ;
}
void teardown (void)
{
OK (LAGraph_Finalize (msg)) ;
}
typedef struct
{
LAGraph_Kind kind ;
const char *name ;
}
matrix_info ;
const matrix_info files [ ] =
{
LAGraph_ADJACENCY_DIRECTED, "cover.mtx",
LAGraph_ADJACENCY_DIRECTED, "ldbc-directed-example.mtx",
LAGraph_ADJACENCY_UNDIRECTED, "ldbc-undirected-example.mtx",
LAGRAPH_UNKNOWN, ""
} ;
void test_New (void)
{
setup ( ) ;
for (int k = 0 ; ; k++)
{
const char *aname = files [k].name ;
LAGraph_Kind kind = files [k].kind ;
if (strlen (aname) == 0) break;
TEST_CASE (aname) ;
snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
FILE *f = fopen (filename, "r") ;
TEST_CHECK (f != NULL) ;
OK (LAGraph_MMRead (&A, f, msg)) ;
OK (fclose (f)) ;
TEST_MSG ("Loading of adjacency matrix failed") ;
OK (LAGraph_New (&G, &A, kind, msg)) ;
TEST_CHECK (A == NULL) ;
OK (LAGraph_CheckGraph (G, msg)) ;
TEST_CHECK (G->kind == kind) ;
if (kind == LAGraph_ADJACENCY_DIRECTED)
{
TEST_CHECK (G->is_symmetric_structure == LAGRAPH_UNKNOWN) ;
}
else
{
TEST_CHECK (G->is_symmetric_structure == LAGraph_TRUE) ;
}
OK (LAGraph_Delete (&G, msg)) ;
TEST_CHECK (G == NULL) ;
}
teardown ( ) ;
}
#if LG_BRUTAL_TESTS
void test_New_brutal (void)
{
OK (LG_brutal_setup (msg)) ;
printf ("\n") ;
for (int k = 0 ; ; k++)
{
const char *aname = files [k].name ;
LAGraph_Kind kind = files [k].kind ;
if (strlen (aname) == 0) break;
TEST_CASE (aname) ;
snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
FILE *f = fopen (filename, "r") ;
TEST_CHECK (f != NULL) ;
OK (LAGraph_MMRead (&A, f, msg)) ;
OK (fclose (f)) ;
TEST_MSG ("Loading of adjacency matrix failed") ;
LG_BRUTAL_BURBLE (LAGraph_New (&G, &A, kind, msg)) ;
TEST_CHECK (A == NULL) ;
LG_BRUTAL_BURBLE (LAGraph_CheckGraph (G, msg)) ;
LG_BRUTAL_BURBLE (LAGraph_Delete (&G, msg)) ;
TEST_CHECK (G == NULL) ;
}
OK (LG_brutal_teardown (msg)) ;
}
#endif
void test_New_failures (void)
{
setup ( ) ;
TEST_CHECK (LAGraph_New (NULL, NULL, 0, msg) == GrB_NULL_POINTER) ;
printf ("\nmsg: %s\n", msg) ;
OK (LAGraph_New (&G, NULL, 0, msg)) ;
TEST_CHECK (LAGraph_CheckGraph (G, msg) == LAGRAPH_INVALID_GRAPH) ;
printf ("msg: %s\n", msg) ;
OK (LAGraph_Delete (&G, msg)) ;
TEST_CHECK (G == NULL) ;
OK (LAGraph_Delete (&G, msg)) ;
TEST_CHECK (G == NULL) ;
OK (LAGraph_Delete (NULL, msg)) ;
teardown ( ) ;
}
TEST_LIST =
{
{ "New", test_New },
{ "New_failures", test_New_failures },
#if LG_BRUTAL_TESTS
{ "New_brutal", test_New_brutal },
#endif
{ NULL, NULL }
} ;