/src/igraph/fuzzing/basic_properties_undirected.cpp
Line | Count | Source |
1 | | /* |
2 | | igraph library. |
3 | | Copyright (C) 2024 The igraph development team |
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, write to the Free Software |
17 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | | 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include <igraph.h> |
22 | | #include <cstdlib> |
23 | | |
24 | 663 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
25 | 663 | igraph_t graph; |
26 | 663 | igraph_vector_int_t edges; |
27 | | |
28 | 663 | igraph_set_warning_handler(igraph_warning_handler_ignore); |
29 | | |
30 | 663 | if (Size % 2 == 0 || Size > 512+1 || Size < 1) { |
31 | 14 | return 0; |
32 | 14 | } |
33 | | |
34 | 649 | igraph_vector_int_init(&edges, Size-1); |
35 | 39.2k | for (size_t i=0; i < Size-1; ++i) { |
36 | 38.5k | VECTOR(edges)[i] = Data[i+1]; |
37 | 38.5k | } |
38 | | |
39 | | /* Undirected */ |
40 | 649 | if (igraph_create(&graph, &edges, Data[0], IGRAPH_UNDIRECTED) == IGRAPH_SUCCESS) { |
41 | 649 | igraph_bool_t has_multi, has_loop, is_simple, is_complete, is_bipartite; |
42 | 649 | igraph_bool_t is_connected, is_acyclic, is_tree, is_biconnected, is_chordal; |
43 | 649 | igraph_bool_t has_eulerian_path, has_eulerian_cycle; |
44 | 649 | igraph_int_t vcount, ecount; |
45 | 649 | igraph_real_t r; |
46 | | |
47 | | /* Tip for reading the assertions below: |
48 | | * "A implies B" is equivalent to "!A || B". |
49 | | */ |
50 | | |
51 | 649 | vcount = igraph_vcount(&graph); |
52 | 649 | ecount = igraph_ecount(&graph); |
53 | | |
54 | 649 | igraph_has_multiple(&graph, &has_multi); |
55 | 649 | igraph_has_loop(&graph, &has_loop); |
56 | 649 | igraph_invalidate_cache(&graph); |
57 | | |
58 | 649 | igraph_is_simple(&graph, &is_simple, IGRAPH_DIRECTED); |
59 | 649 | igraph_invalidate_cache(&graph); |
60 | | |
61 | 649 | IGRAPH_ASSERT((has_loop || has_multi) == !is_simple); |
62 | | |
63 | 649 | igraph_is_complete(&graph, &is_complete); |
64 | 649 | igraph_invalidate_cache(&graph); |
65 | | |
66 | 649 | IGRAPH_ASSERT(!is_complete || ecount >= vcount*(vcount-1) / 2); /* valid for undirected */ |
67 | | |
68 | 649 | igraph_is_bipartite(&graph, &is_bipartite, NULL); |
69 | 649 | igraph_invalidate_cache(&graph); |
70 | | |
71 | 649 | IGRAPH_ASSERT(!is_complete || !is_bipartite || vcount <= 2); |
72 | | |
73 | 649 | igraph_is_connected(&graph, &is_connected, IGRAPH_WEAK); |
74 | 649 | igraph_invalidate_cache(&graph); |
75 | | |
76 | 649 | IGRAPH_ASSERT(!is_complete || is_connected || vcount == 0); |
77 | 649 | IGRAPH_ASSERT(!is_connected || ecount >= vcount - 1); |
78 | | |
79 | 649 | igraph_is_acyclic(&graph, &is_acyclic); |
80 | 649 | igraph_invalidate_cache(&graph); |
81 | | |
82 | 649 | IGRAPH_ASSERT(!is_complete || !is_acyclic || vcount <= 2); |
83 | | |
84 | 649 | igraph_is_tree(&graph, &is_tree, NULL, IGRAPH_ALL); |
85 | 649 | igraph_invalidate_cache(&graph); |
86 | | |
87 | 649 | IGRAPH_ASSERT(!(is_connected && is_acyclic) || is_tree); |
88 | | |
89 | 649 | igraph_is_eulerian(&graph, &has_eulerian_path, &has_eulerian_cycle); |
90 | 649 | igraph_invalidate_cache(&graph); |
91 | | |
92 | 649 | IGRAPH_ASSERT(!has_eulerian_cycle || has_eulerian_path); |
93 | | |
94 | 649 | igraph_is_biconnected(&graph, &is_biconnected); |
95 | 649 | igraph_invalidate_cache(&graph); |
96 | | |
97 | 649 | IGRAPH_ASSERT(!is_biconnected || is_connected); |
98 | | |
99 | 649 | igraph_is_chordal(&graph, NULL, NULL, &is_chordal, NULL, NULL); |
100 | 649 | igraph_invalidate_cache(&graph); |
101 | | |
102 | 649 | igraph_density(&graph, NULL, &r, false); |
103 | | |
104 | 649 | IGRAPH_ASSERT(!is_complete || r >= 1 || vcount <= 1); |
105 | | |
106 | 649 | igraph_density(&graph, NULL, &r, true); |
107 | | |
108 | 649 | igraph_destroy(&graph); |
109 | 649 | } |
110 | | |
111 | 649 | igraph_vector_int_destroy(&edges); |
112 | | |
113 | 649 | IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY); |
114 | | |
115 | 649 | return 0; // Non-zero return values are reserved for future use. |
116 | 649 | } |