1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2006-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 
main()26 int main() {
27 
28     igraph_t g;
29     igraph_real_t res;
30 
31     /* Trivial cases */
32 
33     igraph_ring(&g, 100, IGRAPH_UNDIRECTED, 0, 0);
34     igraph_transitivity_undirected(&g, &res, IGRAPH_TRANSITIVITY_NAN);
35     igraph_destroy(&g);
36 
37     if (res != 0) {
38         return 1;
39     }
40 
41     igraph_full(&g, 20, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
42     igraph_transitivity_undirected(&g, &res, IGRAPH_TRANSITIVITY_NAN);
43     igraph_destroy(&g);
44 
45     if (res != 1) {
46         return 2;
47     }
48 
49     /* Degenerate cases */
50     igraph_small(&g, 0, IGRAPH_UNDIRECTED,
51                  0,  1,  2,  3,  4,  5, -1);
52     igraph_transitivity_undirected(&g, &res, IGRAPH_TRANSITIVITY_NAN);
53     /* res should be NaN here, any comparison must return false */
54     if (res == 0 || res > 0 || res < 0) {
55         return 4;
56     }
57     igraph_transitivity_undirected(&g, &res, IGRAPH_TRANSITIVITY_ZERO);
58     /* res should be zero here */
59     if (res) {
60         return 5;
61     }
62     igraph_destroy(&g);
63 
64     /* Zachary Karate club */
65 
66     igraph_small(&g, 0, IGRAPH_UNDIRECTED,
67                  0,  1,  0,  2,  0,  3,  0,  4,  0,  5,
68                  0,  6,  0,  7,  0,  8,  0, 10,  0, 11,
69                  0, 12,  0, 13,  0, 17,  0, 19,  0, 21,
70                  0, 31,  1,  2,  1,  3,  1,  7,  1, 13,
71                  1, 17,  1, 19,  1, 21,  1, 30,  2,  3,
72                  2,  7,  2,  8,  2,  9,  2, 13,  2, 27,
73                  2, 28,  2, 32,  3,  7,  3, 12,  3, 13,
74                  4,  6,  4, 10,  5,  6,  5, 10,  5, 16,
75                  6, 16,  8, 30,  8, 32,  8, 33,  9, 33,
76                  13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
77                  18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
78                  22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
79                  23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
80                  25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
81                  28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
82                  31, 32, 31, 33, 32, 33,
83                  -1);
84 
85     igraph_transitivity_undirected(&g, &res, IGRAPH_TRANSITIVITY_NAN);
86     igraph_destroy(&g);
87 
88     if (res != 0.2556818181818181767717) {
89         fprintf(stderr, "%f != %f\n", res, 0.2556818181818181767717);
90         return 3;
91     }
92 
93     return 0;
94 }
95