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_matrix_t pref_empty, pref_bipartite, pref_line;
25 igraph_vector_t types_empty, types_bipartite, types_line;
26 igraph_bool_t bipartite;
27 int bipartite_elem[] = {0, 1, 1, 0};
28 int line_elem[] = {0, 0, 1, 0, 0,
29 1, 0, 0, 0, 0,
30 0, 1, 0, 0, 0,
31 0, 0, 1, 0, 0,
32 0, 0, 0, 1, 0,
33 };
34
35 igraph_rng_seed(igraph_rng_default(), 42);
36
37 igraph_matrix_init(&pref_empty, 0, 0);
38 igraph_vector_init(&types_empty, 0);
39
40 matrix_init_int_row_major(&pref_bipartite, 2, 2, bipartite_elem);
41 igraph_vector_init_int(&types_bipartite, 10, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0);
42
43 matrix_init_int_row_major(&pref_line, 5, 5, line_elem);
44 igraph_vector_init_int(&types_line, 5, 0, 1, 2, 3, 4);
45
46 printf("No nodes.\n");
47 IGRAPH_ASSERT(igraph_citing_cited_type_game(&g, /*nodes*/ 0, &types_empty, &pref_empty, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_SUCCESS);
48 IGRAPH_ASSERT(igraph_vcount(&g) == 0);
49 igraph_destroy(&g);
50
51 printf("Bipartite graph.\n");
52 IGRAPH_ASSERT(igraph_citing_cited_type_game(&g, /*nodes*/ 10, &types_bipartite, &pref_bipartite, /*edges_per_step*/ 5, /*directed*/ 0) == IGRAPH_SUCCESS);
53 igraph_is_bipartite(&g, &bipartite, NULL);
54 IGRAPH_ASSERT(bipartite);
55 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
56 IGRAPH_ASSERT(igraph_ecount(&g) == 45);
57 igraph_destroy(&g);
58
59 printf("No edges.\n");
60 IGRAPH_ASSERT(igraph_citing_cited_type_game(&g, /*nodes*/ 10, &types_bipartite, &pref_bipartite, /*edges_per_step*/ 0, /*directed*/ 0) == IGRAPH_SUCCESS);
61 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
62 IGRAPH_ASSERT(igraph_ecount(&g) == 0);
63 igraph_destroy(&g);
64
65 printf("A line.\n");
66 IGRAPH_ASSERT(igraph_citing_cited_type_game(&g, /*nodes*/ 5, &types_line, &pref_line, /*edges_per_step*/ 1, /*directed*/ 1) == IGRAPH_SUCCESS);
67 print_graph_canon(&g);
68 igraph_destroy(&g);
69
70 VERIFY_FINALLY_STACK();
71 igraph_set_error_handler(igraph_error_handler_ignore);
72
73 printf("Too few types for nodes.\n");
74 IGRAPH_ASSERT(igraph_citing_cited_type_game(&g, /*nodes*/ 5, &types_empty, &pref_empty, /*edges_per_step*/ 1, /*directed*/ 1) == IGRAPH_EINVAL);
75
76 printf("Too few prefs.\n");
77 IGRAPH_ASSERT(igraph_citing_cited_type_game(&g, /*nodes*/ 5, &types_line, &pref_empty, /*edges_per_step*/ 1, /*directed*/ 1) == IGRAPH_EINVAL);
78
79 igraph_matrix_destroy(&pref_empty);
80 igraph_vector_destroy(&types_empty);
81 igraph_matrix_destroy(&pref_bipartite);
82 igraph_vector_destroy(&types_bipartite);
83 igraph_matrix_destroy(&pref_line);
84 igraph_vector_destroy(&types_line);
85 VERIFY_FINALLY_STACK();
86 return 0;
87 }
88