1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2009-2021 The igraph development team
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA
20
21 */
22
23 #include <igraph.h>
24
25 #include "test_utilities.inc"
26
main()27 int main() {
28 igraph_t g;
29 igraph_vector_t vids, layers, parents;
30
31 igraph_vector_init(&vids, 0);
32 igraph_vector_init(&layers, 0);
33 igraph_vector_init(&parents, 0);
34
35 /* Test a ring graph */
36 igraph_ring(&g, 10, IGRAPH_UNDIRECTED, 0, 0);
37 igraph_bfs_simple(&g, 0, IGRAPH_ALL, &vids, &layers, &parents);
38 print_vector_round(&vids);
39 print_vector_round(&layers);
40 print_vector_round(&parents);
41 igraph_destroy(&g);
42
43 /* Test a tree graph */
44 igraph_tree(&g, 20, 2, IGRAPH_TREE_UNDIRECTED);
45 igraph_bfs_simple(&g, 0, IGRAPH_ALL, &vids, &layers, &parents);
46 print_vector_round(&vids);
47 print_vector_round(&layers);
48 print_vector_round(&parents);
49 igraph_destroy(&g);
50
51 /* Test th same graph with all arguments as nulls to see if we tolerate that */
52 igraph_tree(&g, 20, 2, IGRAPH_TREE_UNDIRECTED);
53 igraph_bfs_simple(&g, 0, IGRAPH_ALL, 0, 0, 0);
54 igraph_destroy(&g);
55
56 /* Also test the case when 'layers' is not null and 'vids' is null to ensure
57 * that we don't need 'vids' in the internal implementation to populate
58 * 'layers' */
59 igraph_tree(&g, 20, 2, IGRAPH_TREE_UNDIRECTED);
60 igraph_bfs_simple(&g, 0, IGRAPH_ALL, 0, &layers, 0);
61 print_vector_round(&layers);
62 igraph_destroy(&g);
63
64 igraph_vector_destroy(&vids);
65 igraph_vector_destroy(&layers);
66 igraph_vector_destroy(&parents);
67
68 VERIFY_FINALLY_STACK();
69
70 return 0;
71 }
72