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 igraph_vector_t pref, types;
25
26 igraph_rng_seed(igraph_rng_default(), 42);
27
28 printf("No nodes:\n");
29 igraph_vector_init_int(&pref, 2, 1, 1);
30 igraph_vector_init_int(&types, 0);
31 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 0, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_SUCCESS);
32 print_graph_canon(&g);
33 igraph_destroy(&g);
34 igraph_vector_destroy(&pref);
35 igraph_vector_destroy(&types);
36
37 printf("No edges:\n");
38 igraph_vector_init_int(&pref, 2, 1, 1);
39 igraph_vector_init_int(&types, 3, 1, 1, 1);
40 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 3, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 0, /*directed*/ 0) == IGRAPH_SUCCESS);
41 print_graph_canon(&g);
42 igraph_destroy(&g);
43 igraph_vector_destroy(&pref);
44 igraph_vector_destroy(&types);
45
46 printf("Make a star of double edges:\n");
47 igraph_vector_init_real(&pref, 3, 1.0, 0.0, 0.0);
48 igraph_vector_init_int(&types, 5, 0, 1, 1, 1, 1);
49 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 5, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 2, /*directed*/ 1) == IGRAPH_SUCCESS);
50 print_graph_canon(&g);
51 igraph_destroy(&g);
52 igraph_vector_destroy(&pref);
53 igraph_vector_destroy(&types);
54
55 printf("Make a line:\n");
56 igraph_vector_init_real(&pref, 7, 1.0e-30, 1.0e-20, 1.0e-10, 1.0, 1.0e+10, 1.0e+20, 0.0);
57 igraph_vector_init_int(&types, 7, 0, 1, 2, 3, 4, 5, 6);
58 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 7, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 1, /*directed*/ 1) == IGRAPH_SUCCESS);
59 print_graph_canon(&g);
60 igraph_destroy(&g);
61 igraph_vector_destroy(&pref);
62 igraph_vector_destroy(&types);
63
64 VERIFY_FINALLY_STACK();
65 igraph_set_error_handler(igraph_error_handler_ignore);
66
67 printf("Checking negative number of nodes error handling.\n");
68 igraph_vector_init_real(&pref, 2, 1.0, 1.0);
69 igraph_vector_init_int(&types, 2, 0, 1);
70 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ -5, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_EINVAL);
71 igraph_vector_destroy(&pref);
72 igraph_vector_destroy(&types);
73
74 printf("Checking too few types error handling.\n");
75 igraph_vector_init_real(&pref, 1, 1.0);
76 igraph_vector_init_int(&types, 0);
77 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 1, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_EINVAL);
78 igraph_vector_destroy(&pref);
79 igraph_vector_destroy(&types);
80
81 printf("Checking too many types error handling.\n");
82 igraph_vector_init_real(&pref, 3, 1.0, 1.0, 1.0);
83 igraph_vector_init_int(&types, 2, 0, 1);
84 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 1, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_EINVAL);
85 igraph_vector_destroy(&pref);
86 igraph_vector_destroy(&types);
87
88 printf("Checking negative type for error handling.\n");
89 igraph_vector_init_real(&pref, 2, 1.0, 1.0);
90 igraph_vector_init_int(&types, 2, 0, -5);
91 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 2, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_EINVAL);
92 igraph_vector_destroy(&pref);
93 igraph_vector_destroy(&types);
94
95 printf("Checking too big type for error handling.\n");
96 igraph_vector_init_real(&pref, 2, 1.0, 1.0);
97 igraph_vector_init_int(&types, 2, 0, 5);
98 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 2, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_EINVAL);
99 igraph_vector_destroy(&pref);
100 igraph_vector_destroy(&types);
101
102 printf("Checking negative preference error handling.\n");
103 igraph_vector_init_real(&pref, 2, 1.0, -1.0);
104 igraph_vector_init_int(&types, 2, 0, 1);
105 IGRAPH_ASSERT(igraph_cited_type_game(&g, /*nodes*/ 2, /*types*/ &types, /*pref*/ &pref, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_EINVAL);
106 igraph_vector_destroy(&pref);
107 igraph_vector_destroy(&types);
108
109 VERIFY_FINALLY_STACK();
110 return 0;
111 }
112