1 /* -*- mode: C -*-  */
2 /* vim:set ts=4 sw=4 sts=4 et: */
3 /*
4    IGraph library.
5    Copyright (C) 2007-2012  Gabor Csardi <csardi.gabor@gmail.com>
6    334 Harvard street, Cambridge, MA 02139 USA
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301 USA
22 
23 */
24 
25 #include <igraph.h>
26 
27 #include "../../tests/unit/test_utilities.inc"
28 
main()29 int main() {
30     igraph_t g;
31     igraph_integer_t k;
32     igraph_vector_t membership;
33     igraph_real_t modularity;
34 
35     igraph_rng_seed(igraph_rng_default(), 247);
36 
37     /* Empty graph */
38     igraph_small(&g, 0, IGRAPH_UNDIRECTED, -1);
39     igraph_vector_init(&membership, 0);
40     igraph_vector_push_back(&membership, 1);
41     igraph_community_fluid_communities(&g, 2, &membership, &modularity);
42     if (!igraph_is_nan(modularity) || igraph_vector_size(&membership) != 0) {
43         return 2;
44     }
45     igraph_vector_destroy(&membership);
46     igraph_destroy(&g);
47 
48     /* Graph with one vertex only */
49     igraph_small(&g, 1, IGRAPH_UNDIRECTED, -1);
50     igraph_vector_init(&membership, 0);
51     igraph_community_fluid_communities(&g, 2, &membership, &modularity);
52     if (!igraph_is_nan(modularity) || igraph_vector_size(&membership) != 1 || VECTOR(membership)[0] != 0) {
53         return 3;
54     }
55     igraph_vector_destroy(&membership);
56     igraph_destroy(&g);
57 
58     /* Zachary Karate club -- this is just a quick smoke test */
59     igraph_small(&g, 0, IGRAPH_UNDIRECTED,
60                  0,  1,  0,  2,  0,  3,  0,  4,  0,  5,
61                  0,  6,  0,  7,  0,  8,  0, 10,  0, 11,
62                  0, 12,  0, 13,  0, 17,  0, 19,  0, 21,
63                  0, 31,  1,  2,  1,  3,  1,  7,  1, 13,
64                  1, 17,  1, 19,  1, 21,  1, 30,  2,  3,
65                  2,  7,  2,  8,  2,  9,  2, 13,  2, 27,
66                  2, 28,  2, 32,  3,  7,  3, 12,  3, 13,
67                  4,  6,  4, 10,  5,  6,  5, 10,  5, 16,
68                  6, 16,  8, 30,  8, 32,  8, 33,  9, 33,
69                  13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
70                  18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
71                  22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
72                  23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
73                  25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
74                  28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
75                  31, 32, 31, 33, 32, 33,
76                  -1);
77 
78     igraph_vector_init(&membership, 0);
79     k = 2;
80     igraph_community_fluid_communities(&g, k, &membership,
81                                        /*modularity=*/ 0);
82     if (!igraph_vector_contains(&membership, 0) || !igraph_vector_contains(&membership, 1)) {
83         printf("Resulting graph does not have exactly 2 communities as expected.\n");
84         igraph_vector_print(&membership);
85         return 1;
86     }
87 
88     igraph_destroy(&g);
89     igraph_vector_destroy(&membership);
90 
91     VERIFY_FINALLY_STACK();
92 
93     return 0;
94 }
95