1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard st, Cambridge MA, 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25 #include <stdlib.h>
26
27 #include "core/set.h"
28
29 #include "test_utilities.inc"
30
print_set(igraph_set_t * set,FILE * f)31 void print_set(igraph_set_t *set, FILE *f) {
32 long int state = 0;
33 igraph_integer_t element;
34 while (igraph_set_iterate(set, &state, &element)) {
35 fprintf(f, " %li", (long int) element);
36 }
37 fprintf(f, "\n");
38 }
39
main()40 int main() {
41
42 igraph_set_t set;
43 int i;
44
45 /* simple init */
46 igraph_set_init(&set, 0);
47 igraph_set_destroy(&set);
48
49 /* addition, igraph_set_size */
50 igraph_set_init(&set, 10);
51 i = 10;
52 while (igraph_set_size(&set) < 10) {
53 igraph_set_add(&set, 2 * i);
54 i--;
55 }
56 while (igraph_set_size(&set) < 21) {
57 igraph_set_add(&set, 2 * i + 1);
58 i++;
59 }
60 print_set(&set, stdout);
61
62 /* adding existing element */
63 igraph_set_add(&set, 8);
64 if (igraph_set_size(&set) != 21) {
65 return 4;
66 }
67
68 /* igraph_set_contains */
69 if (igraph_set_contains(&set, 42) || !igraph_set_contains(&set, 7)) {
70 return 3;
71 }
72
73 /* igraph_set_empty, igraph_set_clear */
74 if (igraph_set_empty(&set)) {
75 return 1;
76 }
77 igraph_set_clear(&set);
78 if (!igraph_set_empty(&set)) {
79 return 2;
80 }
81 igraph_set_destroy(&set);
82
83 VERIFY_FINALLY_STACK();
84
85 return 0;
86 }
87