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