feat(set): add set

This commit is contained in:
2026-03-16 23:06:29 +01:00
parent e7f2d6cdeb
commit a6740769b9
4 changed files with 178 additions and 13 deletions
+31
View File
@@ -0,0 +1,31 @@
#include "../set/myset.h"
#include <assert.h>
void test_set1(void) {
set_s *set = set_new(sizeof(int));
assert(set != NULL);
int a = 10;
int b = 20;
int another_a = 10;
int missing = 99;
assert(set_add(set, &a) == 0);
assert(set_add(set, &b) == 0);
/* Duplicate values are ignored and treated as success. */
assert(set_add(set, &another_a) == 0);
assert(set_contains(set, &a) == 1);
assert(set_contains(set, &another_a) == 1);
assert(set_contains(set, &missing) == 0);
assert(set_remove(set, &a) == 0);
assert(set_contains(set, &a) == 0);
assert(set_remove(set, &a) == -1);
assert(set_clear(set) == 0);
assert(set_contains(set, &b) == 0);
set_free(set);
}