35 lines
747 B
C
35 lines
747 B
C
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
#include "unit.h"
|
|
|
|
size_t int_hash(int *ptr) {
|
|
return *ptr;
|
|
}
|
|
|
|
int tests_hset_iter(int argc, char **argv) {
|
|
int_hset_t hset1, hset2;
|
|
hset_init(int_hset_t, hset1, int_hash, NULL);
|
|
hset_init(int_hset_t, hset2, int_hash, NULL);
|
|
|
|
for(int i = 0; i < 1000; i++)
|
|
hset_add(hset1, i);
|
|
|
|
void *saveptr = NULL;
|
|
int *data;
|
|
while ((data = hset_iter(hset2, saveptr)) != NULL)
|
|
hset_add(hset2, *data);
|
|
|
|
char msgbuf[100];
|
|
for(int i = 0; i < 1000; i++) {
|
|
snprintf(msgbuf, sizeof(msgbuf), "%d not in hset2", i);
|
|
chi_assert(msgbuf, hset_find(hset2, i));
|
|
}
|
|
|
|
hset_destroy(hset2);
|
|
hset_destroy(hset1);
|
|
|
|
return 0;
|
|
}
|