1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2006-2021 The igraph development team <igraph@igraph.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <igraph.h>
21
22 #include "test_utilities.inc"
23
main()24 int main() {
25 igraph_t g;
26 igraph_bool_t simple;
27
28 /* Ensure that the test is deterministic */
29 igraph_rng_seed(igraph_rng_default(), 137);
30
31 /* G(n,p) */
32
33 /* Empty graph */
34
35 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.0,
36 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
37 IGRAPH_ASSERT(igraph_ecount(&g) == 0);
38 IGRAPH_ASSERT(! igraph_is_directed(&g));
39 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
40 igraph_destroy(&g);
41
42 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.0,
43 IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
44 IGRAPH_ASSERT(igraph_ecount(&g) == 0);
45 IGRAPH_ASSERT(igraph_is_directed(&g));
46 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
47 igraph_destroy(&g);
48
49 /* Complete graph */
50
51 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 1.0,
52 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
53 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 9 / 2);
54 IGRAPH_ASSERT(! igraph_is_directed(&g));
55 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
56 igraph_destroy(&g);
57
58 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 1.0,
59 IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
60 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 9);
61 IGRAPH_ASSERT(igraph_is_directed(&g));
62 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
63 igraph_destroy(&g);
64
65 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 1.0,
66 IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
67 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 11 / 2);
68 IGRAPH_ASSERT(! igraph_is_directed(&g));
69 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(! simple);
70 igraph_destroy(&g);
71
72 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 1.0,
73 IGRAPH_DIRECTED, IGRAPH_LOOPS);
74 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 10);
75 IGRAPH_ASSERT(igraph_is_directed(&g));
76 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(! simple);
77 igraph_destroy(&g);
78
79 /* Random graph */
80
81 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.5,
82 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
83 IGRAPH_ASSERT(! igraph_is_directed(&g));
84 igraph_destroy(&g);
85
86 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.5,
87 IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
88 IGRAPH_ASSERT(igraph_is_directed(&g));
89 igraph_destroy(&g);
90
91 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.5,
92 IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
93 IGRAPH_ASSERT(! igraph_is_directed(&g));
94 igraph_destroy(&g);
95
96 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.5,
97 IGRAPH_DIRECTED, IGRAPH_LOOPS);
98 IGRAPH_ASSERT(igraph_is_directed(&g));
99 igraph_destroy(&g);
100
101 /* Create a couple of large graphs too */
102
103 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0 / 100000,
104 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
105 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
106 igraph_destroy(&g);
107
108 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0 / 100000,
109 IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
110 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
111 igraph_destroy(&g);
112
113 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0 / 100000,
114 IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
115 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
116 igraph_destroy(&g);
117
118 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0 / 100000,
119 IGRAPH_DIRECTED, IGRAPH_LOOPS);
120 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
121 igraph_destroy(&g);
122
123
124 /* --------------------------------------------------------------------- */
125 /* G(n,m) */
126
127 /* directed with loops */
128 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10 * 10 - 1,
129 IGRAPH_DIRECTED, IGRAPH_LOOPS);
130 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
131 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 10 - 1);
132 IGRAPH_ASSERT(igraph_is_directed(&g));
133
134 igraph_simplify(&g, /*multiple=*/0, /*loops=*/1, /*edge_comb=*/ NULL);
135 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 9 || igraph_ecount(&g) == 10 * 9 - 1);
136
137 igraph_destroy(&g);
138
139 /* directed without loops */
140 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10 * 9 - 1,
141 IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
142 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
143 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 9 - 1);
144 IGRAPH_ASSERT(igraph_is_directed(&g));
145 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
146 igraph_destroy(&g);
147
148 /* undirected with loops */
149 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10 * 11 / 2 - 1,
150 IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
151 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
152 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 11 / 2 - 1);
153 IGRAPH_ASSERT(! igraph_is_directed(&g));
154
155 igraph_simplify(&g, /*multiple=*/0, /*loops=*/1, /*edge_comb=*/ NULL);
156 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 9 / 2 || igraph_ecount(&g) == 10 * 9 / 2 - 1);
157
158 igraph_destroy(&g);
159
160 /* undirected without loops */
161 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10 * 9 / 2 - 1,
162 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
163 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
164 IGRAPH_ASSERT(igraph_ecount(&g) == 10 * 9 / 2 - 1);
165 IGRAPH_ASSERT(! igraph_is_directed(&g));
166 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
167 igraph_destroy(&g);
168
169
170 /* Create a couple of large graphs too */
171 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0 * 100000,
172 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
173 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
174 IGRAPH_ASSERT(igraph_ecount(&g) == 200000);
175 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
176 igraph_destroy(&g);
177
178 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0 * 100000,
179 IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
180 igraph_is_simple(&g, &simple); IGRAPH_ASSERT(simple);
181 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
182 IGRAPH_ASSERT(igraph_ecount(&g) == 200000);
183 igraph_destroy(&g);
184
185 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0 * 100000,
186 IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
187 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
188 IGRAPH_ASSERT(igraph_ecount(&g) == 200000);
189 igraph_simplify(&g, 0, 1, /*edge_comb=*/ 0); /* only remove loops */
190 igraph_destroy(&g);
191
192 igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0 * 100000,
193 IGRAPH_DIRECTED, IGRAPH_LOOPS);
194 IGRAPH_ASSERT(igraph_vcount(&g) == 100000);
195 IGRAPH_ASSERT(igraph_ecount(&g) == 200000);
196 igraph_destroy(&g);
197
198 VERIFY_FINALLY_STACK();
199
200 return 0;
201 }
202