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_comb(igraph_attribute_combination_t * comb)22 void print_comb(igraph_attribute_combination_t *comb) {
23 int i;
24 igraph_attribute_combination_record_t *r;
25 for (i = 0; i < igraph_vector_ptr_size(&comb->list); i++) {
26 r = VECTOR(comb->list)[i];
27 if (r->name) {
28 printf("name: %s", r->name);
29 } else {
30 printf("name: NULL");
31 }
32 printf(", type: %d\n", r->type);
33 }
34 printf("\n");
35 }
36
main()37 int main() {
38 igraph_attribute_combination_t comb;
39
40 igraph_attribute_combination(&comb,
41 "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
42 "type", IGRAPH_ATTRIBUTE_COMBINE_FIRST,
43 "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
44 IGRAPH_NO_MORE_ATTRIBUTES);
45
46 printf("starting combinations:\n");
47 print_comb(&comb);
48
49 printf("Removing nonexistent combination:\n");
50 igraph_attribute_combination_remove(&comb, "nonexistent_name");
51 print_comb(&comb);
52
53 printf("Removing weight:\n");
54 igraph_attribute_combination_remove(&comb, "weight");
55 print_comb(&comb);
56
57 printf("Removing type and NULL:\n");
58 igraph_attribute_combination_remove(&comb, "type");
59 igraph_attribute_combination_remove(&comb, NULL);
60 print_comb(&comb);
61
62 printf("Removing nonexistent combination again:\n");
63 igraph_attribute_combination_remove(&comb, "nonexistent_name");
64 igraph_attribute_combination_remove(&comb, NULL);
65 print_comb(&comb);
66
67 igraph_attribute_combination_destroy(&comb);
68
69 VERIFY_FINALLY_STACK();
70 return 0;
71 }
72