1 
2 #include <igraph.h>
3 
4 #include "test_utilities.inc"
5 
main()6 int main() {
7     igraph_t graph;
8     igraph_vector_t walk, weights;
9     igraph_integer_t ec, i;
10 
11     igraph_rng_seed(igraph_rng_default(), 137);
12 
13     igraph_vector_init(&walk, 0);
14     igraph_vector_init(&weights, 0);
15 
16     /* This directed graph has loop edges.
17        It also has multi-edges when considered as undirected. */
18     igraph_de_bruijn(&graph, 3, 2);
19     ec = igraph_ecount(&graph);
20 
21     /* unweighted, directed */
22     igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
23     IGRAPH_ASSERT(igraph_vector_size(&walk) == 1000);
24 
25     /* unweighted, undirected */
26     igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
27     IGRAPH_ASSERT(igraph_vector_size(&walk) == 1000);
28 
29     igraph_vector_resize(&weights, ec);
30     for (i = 0; i < ec; ++i) {
31         VECTOR(weights)[i] = igraph_rng_get_unif01(igraph_rng_default());
32     }
33 
34     /* weighted, directed */
35     igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
36     IGRAPH_ASSERT(igraph_vector_size(&walk) == 1000);
37 
38     /* weighted, undirecetd */
39     igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
40     IGRAPH_ASSERT(igraph_vector_size(&walk) == 1000);
41 
42     igraph_destroy(&graph);
43 
44     /* 1-vertex graph, should get stuck */
45     igraph_empty(&graph, 1, /* directed = */ 0);
46     igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
47     IGRAPH_ASSERT(igraph_vector_size(&walk) == 0);
48     igraph_destroy(&graph);
49 
50     igraph_vector_destroy(&weights);
51     igraph_vector_destroy(&walk);
52 
53     VERIFY_FINALLY_STACK();
54 
55     return 0;
56 }
57