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
print_vector(igraph_vector_t * v,FILE * f)26 void print_vector(igraph_vector_t *v, FILE *f) {
27 long int i;
28 for (i = 0; i < igraph_vector_size(v); i++) {
29 fprintf(f, " %li", (long int) VECTOR(*v)[i]);
30 }
31 fprintf(f, "\n");
32 }
33
main()34 int main() {
35
36 igraph_t g;
37 igraph_vector_t v;
38 int ret;
39
40 /* Create graph */
41 igraph_vector_init(&v, 8);
42 VECTOR(v)[0] = 0;
43 VECTOR(v)[1] = 1;
44 VECTOR(v)[2] = 1;
45 VECTOR(v)[3] = 2;
46 VECTOR(v)[4] = 2;
47 VECTOR(v)[5] = 3;
48 VECTOR(v)[6] = 2;
49 VECTOR(v)[7] = 2;
50 igraph_create(&g, &v, 0, 1);
51
52 /* Add edges */
53 igraph_vector_resize(&v, 4);
54 VECTOR(v)[0] = 2;
55 VECTOR(v)[1] = 1;
56 VECTOR(v)[2] = 3;
57 VECTOR(v)[3] = 3;
58 igraph_add_edges(&g, &v, 0);
59
60 /* Check result */
61 igraph_get_edgelist(&g, &v, 0);
62 igraph_vector_sort(&v);
63 print_vector(&v, stdout);
64
65 /* Error, vector length */
66 igraph_set_error_handler(igraph_error_handler_ignore);
67 igraph_vector_resize(&v, 3);
68 VECTOR(v)[0] = 0;
69 VECTOR(v)[1] = 1;
70 VECTOR(v)[2] = 2;
71 ret = igraph_add_edges(&g, &v, 0);
72 if (ret != IGRAPH_EINVEVECTOR) {
73 return 1;
74 }
75
76 /* Check result */
77 igraph_get_edgelist(&g, &v, 0);
78 igraph_vector_sort(&v);
79 print_vector(&v, stdout);
80
81 /* Error, vector ids */
82 igraph_vector_resize(&v, 4);
83 VECTOR(v)[0] = 0;
84 VECTOR(v)[1] = 1;
85 VECTOR(v)[2] = 2;
86 VECTOR(v)[3] = 4;
87 ret = igraph_add_edges(&g, &v, 0);
88 if (ret != IGRAPH_EINVVID) {
89 return 2;
90 }
91
92 /* Check result */
93 igraph_get_edgelist(&g, &v, 0);
94 igraph_vector_sort(&v);
95 print_vector(&v, stdout);
96
97 igraph_vector_destroy(&v);
98 igraph_destroy(&g);
99
100 return 0;
101 }
102