1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard street, 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
26 #include "test_utilities.inc"
27
main()28 int main() {
29 igraph_t g;
30 igraph_vector_t deg;
31 igraph_bool_t is_simple;
32
33 igraph_set_error_handler(&igraph_error_handler_ignore);
34
35 igraph_vector_init(°, 0);
36
37 /* k-regular undirected graph, even degrees, no multiple edges */
38 igraph_k_regular_game(&g, 10, 4, 0, 0);
39 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_ALL, 1);
40 igraph_vector_print(°);
41 igraph_is_simple(&g, &is_simple);
42 if (!is_simple) {
43 return 1;
44 }
45 if (igraph_is_directed(&g)) {
46 return 1;
47 }
48 igraph_destroy(&g);
49
50 /* k-regular undirected graph, odd degrees, even number of vertices, no multiple edges */
51 igraph_k_regular_game(&g, 10, 3, 0, 0);
52 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_ALL, 1);
53 igraph_vector_print(°);
54 igraph_is_simple(&g, &is_simple);
55 if (!is_simple) {
56 return 2;
57 }
58 if (igraph_is_directed(&g)) {
59 return 2;
60 }
61 igraph_destroy(&g);
62
63 /* k-regular undirected graph, odd degrees, odd number of vertices, no multiple edges */
64 if (!igraph_k_regular_game(&g, 9, 3, 0, 0)) {
65 return 3;
66 }
67
68 /* k-regular undirected graph, even degrees, multiple edges */
69 igraph_k_regular_game(&g, 10, 4, 0, 1);
70 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_ALL, 1);
71 igraph_vector_print(°);
72 if (igraph_is_directed(&g)) {
73 return 14;
74 }
75 igraph_destroy(&g);
76
77 /* k-regular undirected graph, odd degrees, even number of vertices, multiple edges */
78 igraph_k_regular_game(&g, 10, 3, 0, 1);
79 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_ALL, 1);
80 igraph_vector_print(°);
81 if (igraph_is_directed(&g)) {
82 return 15;
83 }
84 igraph_destroy(&g);
85
86 /* k-regular undirected graph, odd degrees, odd number of vertices, multiple edges */
87 if (!igraph_k_regular_game(&g, 9, 3, 0, 1)) {
88 return 4;
89 }
90
91 /* k-regular directed graph, even degrees, no multiple edges */
92 igraph_k_regular_game(&g, 10, 4, 1, 0);
93 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_IN, 1);
94 igraph_vector_print(°);
95 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_OUT, 1);
96 igraph_vector_print(°);
97 igraph_is_simple(&g, &is_simple);
98 if (!is_simple) {
99 return 5;
100 }
101 if (!igraph_is_directed(&g)) {
102 return 5;
103 }
104 igraph_destroy(&g);
105
106 /* k-regular directed graph, odd degrees, even number of vertices, no multiple edges */
107 igraph_k_regular_game(&g, 10, 3, 1, 0);
108 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_IN, 1);
109 igraph_vector_print(°);
110 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_OUT, 1);
111 igraph_vector_print(°);
112 igraph_is_simple(&g, &is_simple);
113 if (!is_simple) {
114 return 6;
115 }
116 if (!igraph_is_directed(&g)) {
117 return 6;
118 }
119 igraph_destroy(&g);
120
121 /* k-regular directed graph, odd degrees, odd number of vertices, no multiple edges */
122 igraph_k_regular_game(&g, 9, 3, 1, 0);
123 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_IN, 1);
124 igraph_vector_print(°);
125 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_OUT, 1);
126 igraph_vector_print(°);
127 igraph_is_simple(&g, &is_simple);
128 if (!is_simple) {
129 return 7;
130 }
131 if (!igraph_is_directed(&g)) {
132 return 7;
133 }
134 igraph_destroy(&g);
135
136 /* k-regular directed graph, even degrees, multiple edges */
137 igraph_k_regular_game(&g, 10, 4, 1, 1);
138 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_IN, 1);
139 igraph_vector_print(°);
140 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_OUT, 1);
141 igraph_vector_print(°);
142 if (!igraph_is_directed(&g)) {
143 return 16;
144 }
145 igraph_destroy(&g);
146
147 /* k-regular directed graph, odd degrees, even number of vertices, multiple edges */
148 igraph_k_regular_game(&g, 10, 3, 1, 1);
149 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_IN, 1);
150 igraph_vector_print(°);
151 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_OUT, 1);
152 igraph_vector_print(°);
153 if (!igraph_is_directed(&g)) {
154 return 17;
155 }
156 igraph_destroy(&g);
157
158 /* k-regular directed graph, odd degrees, odd number of vertices, multiple edges */
159 igraph_k_regular_game(&g, 9, 3, 1, 1);
160 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_IN, 1);
161 igraph_vector_print(°);
162 igraph_degree(&g, °, igraph_vss_all(), IGRAPH_OUT, 1);
163 igraph_vector_print(°);
164 if (!igraph_is_directed(&g)) {
165 return 18;
166 }
167 igraph_destroy(&g);
168
169 /* k-regular undirected graph, too large degree, no multiple edges */
170 if (!igraph_k_regular_game(&g, 10, 10, 0, 0)) {
171 return 8;
172 }
173
174 /* k-regular directed graph, too large degree, no multiple edges */
175 if (!igraph_k_regular_game(&g, 10, 10, 1, 0)) {
176 return 9;
177 }
178
179 /* empty graph */
180 if (igraph_k_regular_game(&g, 0, 0, 0, 0)) {
181 return 10;
182 }
183 if (igraph_vcount(&g) != 0 || igraph_ecount(&g) != 0 || igraph_is_directed(&g)) {
184 return 11;
185 }
186 igraph_destroy(&g);
187 if (igraph_k_regular_game(&g, 0, 0, 1, 0)) {
188 return 12;
189 }
190 if (igraph_vcount(&g) != 0 || igraph_ecount(&g) != 0 || !igraph_is_directed(&g)) {
191 return 13;
192 }
193 igraph_destroy(&g);
194
195 igraph_vector_destroy(°);
196
197 VERIFY_FINALLY_STACK();
198
199 return 0;
200 }
201