1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard street, Cambridge, MA 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25 #include <stdlib.h>
26
sort_and_print_vector(igraph_vector_t * v)27 void sort_and_print_vector(igraph_vector_t *v) {
28 long int i, n = igraph_vector_size(v);
29 igraph_vector_sort(v);
30 for (i = 0; i < n; i++) {
31 printf(" %li", (long int) VECTOR(*v)[i]);
32 }
33 printf("\n");
34 }
35
warning_handler_ignore(const char * reason,const char * file,int line,int e)36 void warning_handler_ignore(const char* reason, const char* file, int line, int e) {
37 }
38
main()39 int main() {
40
41 igraph_t g;
42 igraph_vector_ptr_t result;
43 igraph_integer_t no;
44 long int i;
45
46 igraph_set_warning_handler(warning_handler_ignore);
47
48 igraph_vector_ptr_init(&result, 0);
49 igraph_small(&g, 7, 0, 0, 1, 1, 2, 2, 3, 3, 0, 2, 4, 4, 5, 2, 5, -1);
50
51 igraph_biconnected_components(&g, &no, 0, 0, &result, 0);
52 if (no != 2 || no != igraph_vector_ptr_size(&result)) {
53 return 1;
54 }
55 for (i = 0; i < no; i++) {
56 sort_and_print_vector((igraph_vector_t*)VECTOR(result)[i]);
57 igraph_vector_destroy((igraph_vector_t*)VECTOR(result)[i]);
58 igraph_free((igraph_vector_t*)VECTOR(result)[i]);
59 }
60
61 igraph_biconnected_components(&g, &no, 0, &result, 0, 0);
62 if (no != 2 || no != igraph_vector_ptr_size(&result)) {
63 return 2;
64 }
65 for (i = 0; i < no; i++) {
66 sort_and_print_vector((igraph_vector_t*)VECTOR(result)[i]);
67 igraph_vector_destroy((igraph_vector_t*)VECTOR(result)[i]);
68 igraph_free((igraph_vector_t*)VECTOR(result)[i]);
69 }
70
71 igraph_biconnected_components(&g, &no, &result, 0, 0, 0);
72 if (no != 2 || no != igraph_vector_ptr_size(&result)) {
73 return 3;
74 }
75 for (i = 0; i < no; i++) {
76 sort_and_print_vector((igraph_vector_t*)VECTOR(result)[i]);
77 igraph_vector_destroy((igraph_vector_t*)VECTOR(result)[i]);
78 igraph_free((igraph_vector_t*)VECTOR(result)[i]);
79 }
80
81 igraph_vector_ptr_destroy(&result);
82 igraph_destroy(&g);
83
84 return 0;
85 }
86