1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2010-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard st, 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 <stdio.h>
26 
27 #define FAIL(msg, error) do { printf(msg "\n") ; return error; } while (0)
28 
main()29 int main() {
30 
31     igraph_t graph;
32     igraph_vector_t sep;
33     igraph_bool_t result;
34 
35     /* Simple star graph, remove the center */
36     igraph_star(&graph, 10, IGRAPH_STAR_UNDIRECTED, 0);
37     igraph_is_separator(&graph, igraph_vss_1(0), &result);
38     if (!result) {
39         FAIL("Center of star graph failed.", 1);
40     }
41 
42     /* Same graph, but another vertex */
43     igraph_is_separator(&graph, igraph_vss_1(6), &result);
44     if (result) {
45         FAIL("Non-center of star graph failed.", 2);
46     }
47 
48     /* Same graph, all vertices but the center */
49     igraph_is_separator(&graph, igraph_vss_seq(1, 9), &result);
50     if (result) {
51         FAIL("All non-central vertices of star graph failed.", 5);
52     }
53     igraph_destroy(&graph);
54 
55     /* Same graph, all vertices */
56     igraph_is_separator(&graph, igraph_vss_seq(0, 9), &result);
57     if (result) {
58         FAIL("All vertices of star graph failed.", 6);
59     }
60     igraph_destroy(&graph);
61 
62     /* Karate club */
63     igraph_famous(&graph, "zachary");
64     igraph_vector_init(&sep, 0);
65     igraph_vector_push_back(&sep, 32);
66     igraph_vector_push_back(&sep, 33);
67     igraph_is_separator(&graph, igraph_vss_vector(&sep), &result);
68     if (!result) {
69         FAIL("Karate network (32,33) failed", 3);
70     }
71 
72     igraph_vector_resize(&sep, 5);
73     VECTOR(sep)[0] = 8;
74     VECTOR(sep)[1] = 9;
75     VECTOR(sep)[2] = 19;
76     VECTOR(sep)[3] = 30;
77     VECTOR(sep)[4] = 31;
78     igraph_is_separator(&graph, igraph_vss_vector(&sep), &result);
79     if (result) {
80         FAIL("Karate network (8,9,19,30,31) failed", 4);
81     }
82 
83     igraph_destroy(&graph);
84     igraph_vector_destroy(&sep);
85 
86     return 0;
87 }
88