1 /*
2    IGraph library.
3    Copyright (C) 2021  The igraph development team <igraph@igraph.org>
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 
19 #include <igraph.h>
20 #include "test_utilities.inc"
21 
main()22 int main() {
23     igraph_t g;
24 
25     igraph_rng_seed(igraph_rng_default(), 42);
26 
27     printf("No vertices:\n");
28     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/0, /*number of edges*/ 0,
29                   /*exponent_out*/ 2.0, /*exponent in*/ 2.0, /*loops*/ 0, /*multiple*/ 0,
30                   /*finite_size_correction*/ 1) == IGRAPH_SUCCESS);
31     print_graph_canon(&g);
32     igraph_destroy(&g);
33 
34     printf("No edges, undirected:\n");
35     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/10, /*number of edges*/ 0,
36                   /*exponent_out*/ 2.0, /*exponent in*/ -2.0, /*loops*/ 0, /*multiple*/ 0,
37                   /*finite_size_correction*/ 1) == IGRAPH_SUCCESS);
38     print_graph_canon(&g);
39     igraph_destroy(&g);
40 
41     printf("Checking some basic outputs.\n");
42     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/100, /*number of edges*/ 30,
43                   /*exponent_out*/ 2.0, /*exponent in*/ -2.0, /*loops*/ 1, /*multiple*/ 1,
44                   /*finite_size_correction*/ 1) == IGRAPH_SUCCESS);
45     IGRAPH_ASSERT(igraph_vcount(&g) == 100);
46     IGRAPH_ASSERT(igraph_ecount(&g) == 30);
47     igraph_destroy(&g);
48 
49     VERIFY_FINALLY_STACK();
50     igraph_set_error_handler(igraph_error_handler_ignore);
51 
52     printf("Negative number of vertices.\n");
53     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/-100, /*number of edges*/ 30,
54                   /*exponent_out*/ 2.0, /*exponent in*/ -2.0, /*loops*/ 1, /*multiple*/ 1,
55                   /*finite_size_correction*/ 1) == IGRAPH_EINVAL);
56     igraph_destroy(&g);
57 
58     printf("Negative number of edges.\n");
59     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/100, /*number of edges*/ -30,
60                   /*exponent_out*/ 2.0, /*exponent in*/ -2.0, /*loops*/ 1, /*multiple*/ 1,
61                   /*finite_size_correction*/ 1) == IGRAPH_EINVAL);
62     igraph_destroy(&g);
63 
64     printf("Exponent out too low.\n");
65     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/100, /*number of edges*/ 30,
66                   /*exponent_out*/ 1.0, /*exponent in*/ -2.0, /*loops*/ 1, /*multiple*/ 1,
67                   /*finite_size_correction*/ 1) == IGRAPH_EINVAL);
68     igraph_destroy(&g);
69 
70     printf("Exponent in too low but not negative.\n");
71     IGRAPH_ASSERT(igraph_static_power_law_game(&g, /*number of vertices*/100, /*number of edges*/ 30,
72                   /*exponent_out*/ 2.0, /*exponent in*/ 0.5, /*loops*/ 1, /*multiple*/ 1,
73                   /*finite_size_correction*/ 1) == IGRAPH_EINVAL);
74     igraph_destroy(&g);
75 
76     VERIFY_FINALLY_STACK();
77     return 0;
78 }
79