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 
print_and_destroy(igraph_t * g,igraph_integer_t center,igraph_vector_t * order,igraph_error_type_t error)22 void print_and_destroy(igraph_t *g, igraph_integer_t center, igraph_vector_t *order, igraph_error_type_t error) {
23     igraph_matrix_t result;
24     igraph_matrix_init(&result, 0, 0);
25     IGRAPH_ASSERT(igraph_layout_star(g, &result, center, order) == error);
26     if (error == IGRAPH_SUCCESS) {
27         matrix_chop(&result, 1e-13);
28         print_matrix(&result);
29     }
30 
31     igraph_matrix_destroy(&result);
32     igraph_destroy(g);
33     if(order) {
34         igraph_vector_destroy(order);
35     }
36 
37 }
38 
main()39 int main() {
40     igraph_t g;
41     igraph_vector_t order;
42 
43     printf("Star of 8 points and a center:\n");
44     igraph_small(&g, 9, 0, -1);
45     print_and_destroy(&g, 0, NULL, IGRAPH_SUCCESS);
46 
47     printf("Star of 8 points and a center in reverse:\n");
48     igraph_small(&g, 9, 0, -1);
49     igraph_vector_init_int(&order, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
50     print_and_destroy(&g, 0, &order, IGRAPH_SUCCESS);
51 
52     VERIFY_FINALLY_STACK();
53     igraph_set_error_handler(igraph_error_handler_ignore);
54 
55     printf("Checking if negative center fails nicely.\n");
56     igraph_small(&g, 9, 0, -1);
57     print_and_destroy(&g, -10, NULL, IGRAPH_EINVAL);
58 
59     printf("Checking if order out of range fails nicely.\n");
60     igraph_small(&g, 9, 0, -1);
61     igraph_vector_init_int(&order, 9, -1, -1, -1, 10, 10, 10, 2, 1, 0);
62     print_and_destroy(&g, 0, &order, IGRAPH_EINVAL);
63 
64     VERIFY_FINALLY_STACK();
65     return 0;
66 }
67