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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_Random.c: test cases for random vector generator
       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 <stdio.h>
      19             : #include <acutest.h>
      20             : 
      21             : #include <LAGraphX.h>
      22             : #include <LAGraph_test.h>
      23             : 
      24             : char msg [LAGRAPH_MSG_LEN] ;
      25             : GrB_Vector Seed = NULL ;
      26             : 
      27             : //------------------------------------------------------------------------------
      28             : // test_Random
      29             : //------------------------------------------------------------------------------
      30             : 
      31           1 : void test_Random (void)
      32             : {
      33           1 :     LAGraph_Init (msg) ;
      34           1 :     OK (LAGraph_Random_Init (msg)) ;
      35             : 
      36           1 :     uint64_t seed = 42 ;
      37           1 :     LAGraph_PrintLevel pr = LAGraph_COMPLETE_VERBOSE ;
      38             : 
      39           6 :     for (int trial = 0 ; trial <= 4 ; trial++)
      40             :     {
      41           5 :         seed++ ;
      42           5 :         printf ("\n=============================== seed: %g\n", (double) seed) ;
      43             : 
      44             :         // generate a seed vector (all entries present)
      45           5 :         printf ("\nDense random vector:\n") ;
      46           5 :         GrB_Index n = 8 ;
      47           5 :         OK (GrB_Vector_new (&Seed, GrB_UINT64, n)) ;
      48           5 :         OK (GrB_Vector_assign_UINT64 (Seed, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
      49           5 :         OK (LAGraph_Random_Seed (Seed, seed, msg)) ;
      50           5 :         OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;
      51           5 :         printf ("\nnext dense random vector:\n") ;
      52           5 :         OK (LAGraph_Random_Next (Seed, msg)) ;
      53           5 :         OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;
      54             : 
      55             :         // free all workspace
      56           5 :         OK (GrB_Vector_free (&Seed)) ;
      57             : 
      58             :         // generate a sparse seed vector
      59           5 :         printf ("\nSparse random vector (same seed):\n") ;
      60           5 :         OK (GrB_Vector_new (&Seed, GrB_UINT64, n)) ;
      61          25 :         for (int i = 0 ; i < n ; i += 2)
      62             :         {
      63          20 :             OK (GrB_Vector_setElement_UINT64 (Seed, 0, i)) ;
      64             :         }
      65           5 :         OK (LAGraph_Random_Seed (Seed, seed, msg)) ;
      66           5 :         OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;
      67           5 :         printf ("\nnext sparse random vector:\n") ;
      68           5 :         OK (LAGraph_Random_Next (Seed, msg)) ;
      69           5 :         OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;
      70             : 
      71             :         // free all workspace
      72           5 :         OK (GrB_Vector_free (&Seed)) ;
      73             :     }
      74             : 
      75           1 :     OK (LAGraph_Random_Finalize (msg)) ;
      76           1 :     LAGraph_Finalize (msg) ;
      77           1 : }
      78             : 
      79             : //------------------------------------------------------------------------------
      80             : // Test list
      81             : //------------------------------------------------------------------------------
      82             : 
      83             : TEST_LIST = {
      84             :     {"Random", test_Random},
      85             :     {NULL, NULL}
      86             : };

Generated by: LCOV version 1.14