summaryrefslogblamecommitdiff
path: root/set_test.c
blob: 4685bc3d4ba2481252dc876c97c4ede1a27abd74 (plain) (tree)
1
2
3
4
5
6
7
8







                                                                                   







                                                                                  


                                   




                          
                                   


















                                  

                    







                                   
                               



















































                                          
/*
	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;
}