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 preference;
25 
26     igraph_rng_seed(igraph_rng_default(), 42);
27 
28     /*No nodes*/
29     igraph_vector_init_int_end(&preference, -1, 1, 1, -1);
30     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 0, /*edges_per_node*/ 5, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_SUCCESS);
31     IGRAPH_ASSERT(igraph_vcount(&g) == 0);
32     igraph_destroy(&g);
33     igraph_vector_destroy(&preference);
34 
35     /*No edges*/
36     igraph_vector_init_int_end(&preference, -1, 1, 1, -1);
37     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 0, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_SUCCESS);
38     IGRAPH_ASSERT(igraph_vcount(&g) == 9);
39     IGRAPH_ASSERT(igraph_ecount(&g) == 0);
40     igraph_destroy(&g);
41     igraph_vector_destroy(&preference);
42 
43     /*Only cite un-cited to make a line*/
44     igraph_vector_init_int_end(&preference, -1, 0, 1, -1);
45     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 1, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_SUCCESS);
46     print_graph_canon(&g);
47     igraph_destroy(&g);
48     igraph_vector_destroy(&preference);
49 
50     /*Hugely prefer cited to make a star*/
51     igraph_vector_init_real(&preference, 2, 1e30, 1e-30);
52     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 1, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 1) == IGRAPH_SUCCESS);
53     print_graph_canon(&g);
54     igraph_destroy(&g);
55     igraph_vector_destroy(&preference);
56 
57     VERIFY_FINALLY_STACK();
58     igraph_set_error_handler(igraph_error_handler_ignore);
59 
60     /*Negative number of nodes*/
61     igraph_vector_init_int_end(&preference, -1, 1, 1, -1);
62     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ -9, /*edges_per_node*/ 1, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_EINVAL);
63     igraph_vector_destroy(&preference);
64 
65     /*Too few agebins*/
66     igraph_vector_init_int_end(&preference, -1, 1, -1);
67     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 1, /*agebins*/ 0, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_EINVAL);
68     igraph_vector_destroy(&preference);
69 
70     /*Wrong vector size*/
71     igraph_vector_init_int_end(&preference, -1, 1, -1);
72     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 1, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_EINVAL);
73     igraph_vector_destroy(&preference);
74 
75     /*No uncited preference*/
76     igraph_vector_init_int_end(&preference, -1, 1, 0, -1);
77     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 1, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_EINVAL);
78     igraph_vector_destroy(&preference);
79 
80     /*Negative preference*/
81     igraph_vector_init_int_end(&preference, -1, -1, 1, -1);
82     IGRAPH_ASSERT(igraph_lastcit_game(&g, /*nodes*/ 9, /*edges_per_node*/ 1, /*agebins*/ 1, /*preference*/ &preference, /*directed*/ 0) == IGRAPH_EINVAL);
83     igraph_vector_destroy(&preference);
84 
85     VERIFY_FINALLY_STACK();
86     return 0;
87 }
88