1 /*
2 IGraph library.
3 Copyright (C) 2021 The igraph development team <igraph@igraph.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #include <igraph.h>
20 #include "test_utilities.inc"
21
call_and_print(igraph_t * graph,igraph_real_t vertex,igraph_neimode_t mode)22 void call_and_print(igraph_t *graph, igraph_real_t vertex, igraph_neimode_t mode) {
23 igraph_vector_t result;
24 igraph_vector_init(&result, 0);
25 IGRAPH_ASSERT(igraph_subcomponent(graph, &result, vertex, mode) == IGRAPH_SUCCESS);
26 igraph_vector_sort(&result);
27 igraph_vector_print(&result);
28 igraph_vector_destroy(&result);
29 printf("\n");
30 }
31
32
main()33 int main() {
34 igraph_t g_0, g_1, g_lm, g_lmu;
35 igraph_vector_t result;
36 igraph_vector_init(&result, 0);
37 int i;
38
39 igraph_small(&g_0, 0, 0, -1);
40 igraph_small(&g_1, 1, 0, -1);
41 igraph_small(&g_lm, 6, 1, 0,1, 0,2, 1,1, 1,3, 2,0, 2,0, 2,3, 3,4, 3,4, -1);
42 igraph_small(&g_lmu, 6, 0, 0,1, 0,2, 1,1, 1,3, 2,0, 2,0, 2,3, 3,4, 3,4, -1);
43
44 printf("No vertices, should give error for impossible starting vertex.\n");
45 CHECK_ERROR(igraph_subcomponent(&g_0, &result, 0, IGRAPH_ALL), IGRAPH_EINVVID);
46
47 printf("One vertex.\n");
48 call_and_print(&g_1, 0, IGRAPH_ALL);
49
50 printf("All vertices of a graph, IGRAPH_OUT:\n");
51 for (i = 0; i < 6; i++) {
52 call_and_print(&g_lm, i, IGRAPH_OUT);
53 }
54
55 printf("All vertices of a graph, IGRAPH_IN:\n");
56 for (i = 0; i < 6; i++) {
57 call_and_print(&g_lm, i, IGRAPH_IN);
58 }
59
60 printf("All vertices of a graph, IGRAPH_ALL:\n");
61 for (i = 0; i < 6; i++) {
62 call_and_print(&g_lm, i, IGRAPH_ALL);
63 }
64
65 printf("All vertices of a graph, undirected:\n");
66 for (i = 0; i < 6; i++) {
67 call_and_print(&g_lmu, i, IGRAPH_OUT);
68 }
69
70 printf("Check for invalid mode error handling.\n");
71 CHECK_ERROR(igraph_subcomponent(&g_1, &result, 0, 100), IGRAPH_EINVMODE);
72
73 igraph_destroy(&g_0);
74 igraph_destroy(&g_1);
75 igraph_destroy(&g_lm);
76 igraph_destroy(&g_lmu);
77 igraph_vector_destroy(&result);
78
79 VERIFY_FINALLY_STACK();
80 return 0;
81 }
82