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
check(igraph_t * graph,igraph_es_t * es)22 void check(igraph_t *graph, igraph_es_t *es) {
23 igraph_eit_t eit;
24 igraph_integer_t edge;
25 IGRAPH_ASSERT(igraph_eit_create(graph, *es, &eit) == IGRAPH_SUCCESS);
26 for (; !IGRAPH_EIT_END(eit); IGRAPH_EIT_NEXT(eit)) {
27 edge = IGRAPH_EIT_GET(eit);
28 printf("%" IGRAPH_PRId " %" IGRAPH_PRId "\n", IGRAPH_FROM(graph, edge), IGRAPH_TO(graph, edge));
29 }
30 igraph_eit_destroy(&eit);
31 }
32
main()33 int main() {
34 igraph_t g, g_no_vertices, g_no_edges;
35 igraph_es_t es;
36 igraph_vector_t v, check_as_vector;
37 igraph_eit_t eit;
38
39 igraph_small(&g, 5, IGRAPH_DIRECTED, 0,1, 0,2, 1,1, 1,3, 2,0, 2,3, 3,4, -1);
40 igraph_small(&g_no_vertices, 0, IGRAPH_UNDIRECTED, -1);
41 igraph_small(&g_no_edges, 5, IGRAPH_UNDIRECTED, -1);
42
43 igraph_set_error_handler(igraph_error_handler_ignore);
44
45 printf("Checking es_vector:\n");
46 igraph_vector_init_int(&v, 3, 2, 3, 4);
47 IGRAPH_ASSERT(igraph_es_vector(&es, &v) == IGRAPH_SUCCESS);
48 check(&g, &es);
49 IGRAPH_ASSERT(igraph_eit_create(&g_no_edges, es, &eit) == IGRAPH_EINVAL);
50 IGRAPH_ASSERT(igraph_eit_create(&g_no_vertices, es, &eit) == IGRAPH_EINVAL);
51 igraph_vector_destroy(&v);
52
53 printf("es_vector with negative entry should fail.\n");
54 igraph_vector_init_int(&v, 3, -2, 3, 4);
55 IGRAPH_ASSERT(igraph_es_vector(&es, &v) == IGRAPH_SUCCESS);
56 IGRAPH_ASSERT(igraph_eit_create(&g, es, &eit) == IGRAPH_EINVAL);
57 igraph_vector_destroy(&v);
58
59 printf("Fromto not implemented.\n");
60 IGRAPH_ASSERT(igraph_es_fromto(&es, igraph_vss_all(), igraph_vss_all()) == IGRAPH_UNIMPLEMENTED);
61
62 printf("Checking es_seq:\n");
63 IGRAPH_ASSERT(igraph_es_seq(&es, 2, 4) == IGRAPH_SUCCESS);
64 check(&g, &es);
65 IGRAPH_ASSERT(igraph_eit_create(&g_no_edges, es, &eit) == IGRAPH_EINVAL);
66 IGRAPH_ASSERT(igraph_eit_create(&g_no_vertices, es, &eit) == IGRAPH_EINVAL);
67
68 printf("Checking eit_as_vector using seq:\n");
69 IGRAPH_ASSERT(igraph_eit_create(&g, es, &eit) == IGRAPH_SUCCESS);
70 igraph_vector_init_int(&check_as_vector, 0);
71 igraph_eit_as_vector(&eit, &check_as_vector);
72 igraph_vector_print(&check_as_vector);
73 igraph_vector_destroy(&check_as_vector);
74
75 printf("Checking ess_seq using es_seq parameters:\n");
76 es = igraph_ess_seq(2, 4);
77 check(&g, &es);
78 IGRAPH_ASSERT(igraph_eit_create(&g_no_edges, es, &eit) == IGRAPH_EINVAL);
79 IGRAPH_ASSERT(igraph_eit_create(&g_no_vertices, es, &eit) == IGRAPH_EINVAL);
80
81 printf("Checking es_path:\n");
82 igraph_vector_init_int(&v, 3, 4, 3, 2);
83 IGRAPH_ASSERT(igraph_es_path(&es, &v, /*directed*/0) == IGRAPH_SUCCESS);
84 check(&g, &es);
85 IGRAPH_ASSERT(igraph_eit_create(&g_no_vertices, es, &eit) == IGRAPH_EINVVID);
86 IGRAPH_ASSERT(igraph_eit_create(&g_no_edges, es, &eit) == IGRAPH_EINVAL);
87 igraph_es_destroy(&es);
88
89 IGRAPH_ASSERT(igraph_es_path(&es, &v, /*directed*/1) == IGRAPH_SUCCESS);
90 IGRAPH_ASSERT(igraph_eit_create(&g, es, &eit) == IGRAPH_EINVAL);
91 igraph_vector_destroy(&v);
92 igraph_es_destroy(&es);
93
94 printf("es_path with negative entry should fail.\n");
95 igraph_vector_init_int(&v, 3, -4, 3, 2);
96 IGRAPH_ASSERT(igraph_es_path(&es, &v, /*directed*/0) == IGRAPH_SUCCESS);
97 IGRAPH_ASSERT(igraph_eit_create(&g, es, &eit) == IGRAPH_EINVVID);
98
99 printf("Checking es_type.\n");
100 IGRAPH_ASSERT(igraph_es_type(&es) == IGRAPH_ES_PATH);
101 igraph_es_destroy(&es);
102 igraph_vector_destroy(&v);
103
104 igraph_destroy(&g);
105 igraph_destroy(&g_no_vertices);
106 igraph_destroy(&g_no_edges);
107
108 VERIFY_FINALLY_STACK();
109 return 0;
110 }
111