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
print_and_destroy(igraph_t * g,igraph_get_adjacency_t type)22 void print_and_destroy(igraph_t *g, igraph_get_adjacency_t type) {
23 igraph_spmatrix_t result;
24 igraph_spmatrix_init(&result, 0, 0);
25 IGRAPH_ASSERT(igraph_get_adjacency_sparse(g, &result, type) == IGRAPH_SUCCESS);
26 print_spmatrix(&result);
27 igraph_spmatrix_destroy(&result);
28 printf("\n");
29 }
30
main()31 int main() {
32 igraph_t g_null, g_lm, g_lm_undir, g_empty;
33
34 igraph_small(&g_null, 0, 0, -1);
35 igraph_small(&g_empty, 3, 0, -1);
36 igraph_small(&g_lm, 6, 1, 0,1, 0,2, 1,1, 1,3, 2,0, 2,3, 3,4, 3,4, -1);
37 igraph_small(&g_lm_undir, 6, 0, 0,1, 0,2, 1,1, 1,3, 2,0, 2,3, 3,4, 3,4, -1);
38
39 printf("No vertices:\n");
40 print_and_destroy(&g_null, IGRAPH_GET_ADJACENCY_BOTH);
41
42 printf("No edges:\n");
43 print_and_destroy(&g_empty, IGRAPH_GET_ADJACENCY_BOTH);
44
45 printf("Disconnected graph with loops and multiple edges:\n");
46 print_and_destroy(&g_lm, IGRAPH_GET_ADJACENCY_BOTH);
47
48 printf("Same graph, undirected, symmetric matrix:\n");
49 print_and_destroy(&g_lm_undir, IGRAPH_GET_ADJACENCY_BOTH);
50
51 printf("Same graph, undirected, upper triangular matrix:\n");
52 print_and_destroy(&g_lm_undir, IGRAPH_GET_ADJACENCY_UPPER);
53
54 printf("Same graph, undirected, lower triangular matrix:\n");
55 print_and_destroy(&g_lm_undir, IGRAPH_GET_ADJACENCY_LOWER);
56
57 igraph_destroy(&g_null);
58 igraph_destroy(&g_empty);
59 igraph_destroy(&g_lm);
60 igraph_destroy(&g_lm_undir);
61
62 VERIFY_FINALLY_STACK();
63 return 0;
64 }
65