1 /* vim:set ts=4 sw=4 sts=4 et: */
2
3 #include <igraph.h>
4
5 #include "test_utilities.inc"
6
main()7 int main() {
8 igraph_t g;
9 igraph_vector_t result;
10 igraph_vector_t weights;
11
12 igraph_vector_init(&result, 0);
13
14 /* null graph */
15 igraph_empty(&g, 0, IGRAPH_UNDIRECTED);
16 igraph_vector_init(&weights, 0);
17
18 printf("Null graph:\n");
19 igraph_diversity(&g, &weights, &result, igraph_vss_all());
20 print_vector(&result);
21
22 igraph_vector_destroy(&weights);
23 igraph_destroy(&g);
24
25 /* graph with no edges */
26 igraph_empty(&g, 5, IGRAPH_UNDIRECTED);
27 igraph_vector_init(&weights, 0);
28
29 printf("Empty graph:\n");
30 igraph_diversity(&g, &weights, &result, igraph_vss_all());
31 print_vector(&result);
32
33 igraph_vector_destroy(&weights);
34 igraph_destroy(&g);
35
36 /* real graph */
37 igraph_small(&g, 4, IGRAPH_UNDIRECTED, 0,1, 0,2, 1,2, 1,3, 2,3, -1);
38 igraph_vector_init_int_end(&weights, -1, 3, 2, 8, 1, 1, -1);
39
40 printf("Graph with 4 nodes and 5 edges:\n");
41 igraph_diversity(&g, &weights, &result, igraph_vss_all());
42 print_vector(&result);
43
44 igraph_vector_destroy(&weights);
45 igraph_destroy(&g);
46
47 /* error conditions are tested from now on */
48 VERIFY_FINALLY_STACK();
49 igraph_set_error_handler(igraph_error_handler_ignore);
50
51 /* graph with multiple edges */
52 igraph_small(&g, 3, IGRAPH_UNDIRECTED, 0,1, 0,2, 2,0, -1);
53 igraph_vector_init_int_end(&weights, -1, 3, 2, 8, -1);
54 IGRAPH_ASSERT(igraph_diversity(&g, &weights, &result, igraph_vss_all()) == IGRAPH_EINVAL);
55 igraph_vector_destroy(&weights);
56 igraph_destroy(&g);
57
58 /* directed graph */
59 igraph_small(&g, 3, IGRAPH_DIRECTED, 0,1, 0,2, -1);
60 igraph_vector_init_int_end(&weights, -1, 3, 2, -1);
61 IGRAPH_ASSERT(igraph_diversity(&g, &weights, &result, igraph_vss_all()) == IGRAPH_EINVAL);
62 igraph_vector_destroy(&weights);
63 igraph_destroy(&g);
64
65 igraph_vector_destroy(&result);
66
67 VERIFY_FINALLY_STACK();
68
69 return 0;
70 }
71