Line data Source code
1 : //---------------------------------------------------------------------------- 2 : // LAGraph/src/test/test_HelloWorld.c: test cases for LAGraph_HelloWorld 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 : //----------------------------------------------------------------------------- 15 : 16 : // This is a very simple "hello world" example of a test program for an 17 : // algorithm in the experimental/algorithm folder. 18 : 19 : #include <stdio.h> 20 : #include <acutest.h> 21 : #include <LAGraphX.h> 22 : #include <LAGraph_test.h> 23 : #include <LG_Xtest.h> 24 : #include <LG_test.h> 25 : 26 : char msg [LAGRAPH_MSG_LEN] ; 27 : LAGraph_Graph G = NULL ; 28 : 29 : #define LEN 512 30 : char filename [LEN+1] ; 31 : 32 1 : void test_HelloWorld (void) 33 : { 34 : 35 : //-------------------------------------------------------------------------- 36 : // start LAGraph 37 : //-------------------------------------------------------------------------- 38 : 39 1 : LAGraph_Init (msg) ; 40 1 : GrB_Matrix Y = NULL, A = NULL ; 41 : 42 : //-------------------------------------------------------------------------- 43 : // test with the west0067 matrix 44 : //-------------------------------------------------------------------------- 45 : 46 : // create the graph 47 1 : snprintf (filename, LEN, LG_DATA_DIR "%s", "west0067.mtx") ; 48 1 : FILE *f = fopen (filename, "r") ; 49 1 : TEST_CHECK (f != NULL) ; 50 1 : OK (LAGraph_MMRead (&A, f, msg)) ; 51 1 : OK (fclose (f)) ; 52 1 : OK (LAGraph_New (&G, &A, LAGraph_ADJACENCY_DIRECTED, msg)) ; 53 1 : TEST_CHECK (A == NULL) ; // A has been moved into G->A 54 : 55 : // test the algorithm 56 1 : OK (LAGraph_HelloWorld (&Y, G, msg)) ; 57 : 58 : // print the result 59 1 : printf ("\nOutput of LAGraph_HelloWorld:\n") ; 60 1 : OK (LAGraph_Matrix_Print (Y, LAGraph_COMPLETE, stdout, msg)) ; 61 : 62 : // check the result (ensure Y is equal to G->A) 63 : bool ok ; 64 1 : OK (LAGraph_Matrix_IsEqual (&ok, Y, G->A, msg)) ; 65 1 : TEST_CHECK (ok) ; 66 : 67 : //-------------------------------------------------------------------------- 68 : // free everything and finalize LAGraph 69 : //-------------------------------------------------------------------------- 70 : 71 1 : OK (GrB_free (&Y)) ; 72 1 : OK (LAGraph_Delete (&G, msg)) ; 73 : 74 1 : LAGraph_Finalize (msg) ; 75 1 : } 76 : 77 : //---------------------------------------------------------------------------- 78 : // the make program is created by acutest, and it runs a list of tests: 79 : //---------------------------------------------------------------------------- 80 : 81 : TEST_LIST = 82 : { 83 : {"HelloWorld", test_HelloWorld}, // just one test in this example 84 : {NULL, NULL} 85 : } ;