#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(1000);
set s = empty_set(1000);
dump_set(s);
set_add_ip(42, s);
dump_set(s);
set k = singleton(1000, 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));
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(1000);
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;
}