1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
Projet d'algorithmique et programmation 2013-2014
(cours de C.Matthieu et J.Stern)
Alex AUVOLAT, Mendes OULAMARA
Série élémentaire de tests pour les différentes fonctions ensemblistes.
*/
#include <stdio.h>
#include "sets.h"
int fails = 0;
#define ASSERT(x) if (!(x)) { fprintf(stderr, "Assert fail: %s\n", #x); fails++; }
int main() {
set empty = empty_set(200);
int i;
set s = empty_set(200);
dump_set(s);
set_add_ip(42, s);
dump_set(s);
set k = singleton(200, 12);
dump_set(k);
set_add_ip(126, k);
dump_set(k);
set j = set_add(76, k);
dump_set(j);
ASSERT(set_mem(76, j));
ASSERT(set_mem(126, j));
ASSERT(!set_mem(42, k));
ASSERT(set_mem(42, s));
set r = set_remove(42, s);
ASSERT(!set_mem(42, r));
ASSERT(is_set_empty(r));
set_remove_ip(42, s);
ASSERT(!set_mem(42, s));
ASSERT(is_set_empty(s));
dump_set(s);
dump_set(r);
ASSERT(sets_equal(s, r));
set_add_ip(4, r);
set_add_ip(12, r);
set_add_ip(3, r);
set_add_ip(6, r);
printf("A: "); dump_set(r);
set x = empty_set(200);
set_union_ip(x, r);
printf("A(copy): "); dump_set(x);
set_add_ip(3, s);
set_add_ip(7, s);
set_add_ip(4, s);
set_add_ip(1, s);
set_add_ip(2, s);
set_add_ip(4, s);
set_add_ip(7, s);
printf("B: "); dump_set(s);
set u = set_union(r, s);
printf("AuB: "); dump_set(u);
set d = set_diff(r, s);
printf("A\\B: "); dump_set(d);
set n = set_inter(r, s);
printf("AnB: "); dump_set(n);
set A = set_inter(empty, r);
set B = set_inter(r, empty);
printf("@nA: "); dump_set(A);
printf("An@: "); dump_set(B);
ASSERT(is_set_empty(A));
ASSERT(is_set_empty(B));
set_union_ip(A, r);
printf("@uA: "); dump_set(A);
set C = set_union(r, empty);
printf("Au@: "); dump_set(C);
ASSERT(sets_equal(A, r));
ASSERT(sets_equal(C, r));
set_diff_ip(A, empty);
printf("A\\@: "); dump_set(A);
ASSERT(sets_equal(A, r));
set_diff_ip(C, u);
printf("A\\(AuB): "); dump_set(C);
ASSERT(is_set_empty(C));
delete_set(s);
delete_set(k);
delete_set(j);
delete_set(r);
delete_set(u);
delete_set(d);
delete_set(n);
delete_set(empty);
delete_set(A);
delete_set(B);
delete_set(C);
return fails;
}
|