Add some simple tests
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include "../set.h"
|
||||
|
||||
int main(void) {
|
||||
set_t* set = set_create(sizeof(int));
|
||||
if (!set) {
|
||||
fprintf(stderr, "Failed to create set\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (set_insert(set, &i) != 0) {
|
||||
fprintf(stderr, "Failed to insert %d\n", i);
|
||||
set_destroy(&set);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < set_size(set); ++i) {
|
||||
int* value = (int*)set_get_const(set, i);
|
||||
if (value) {
|
||||
printf("set[%zu] = %d\n", i, *value);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to get value at index %zu\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
set_destroy(&set);
|
||||
if (set != NULL) {
|
||||
fprintf(stderr, "Set pointer was not set to NULL after destruction\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user