Updated tests
This commit is contained in:
1 parent
762b95db26
commit
e95379bdd7
8 files changed
+316
-137
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c11 -Wall -Wextra
|
||||
CFLAGS += -Wno-unused-function -Wno-unused-paramter -Wno-unused-variable -Wno-unused-label
|
||||
CFLAGS += -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-unused-label
|
||||
|
||||
main:
|
||||
$(CC) foreach.c -o foreach.exe $(CFLAGS)
|
||||
|
||||
+79
-25
@@ -31,6 +31,10 @@ COLLECTION_GENERATE(TREEMAP, tm, tmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE(HASHSET, hs, hset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* FMOD */, , int)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm, mmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE(MULTISET, ms, mset, , , int)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
list *l = l_new(1000);
|
||||
@@ -41,12 +45,16 @@ int main(void)
|
||||
heap *h = h_new(1000, cmc_max_heap, intcmp);
|
||||
tset *ts = ts_new(intcmp);
|
||||
tmap *tm = tm_new(intcmp);
|
||||
hset *hs = hs_new(1000, 0.9, intcmp, inthash);
|
||||
hmap *hm = hm_new(1000, 0.9, intcmp, inthash);
|
||||
hset *hs = hs_new(1000, 0.6, intcmp, inthash);
|
||||
hmap *hm = hm_new(1000, 0.6, intcmp, inthash);
|
||||
|
||||
bool a[10] = {false, false, false, false, false, false, false, false, false, false},
|
||||
b[10] = {false, false, false, false, false, false, false, false, false, false},
|
||||
c[10] = {true, true, true, true, true, true, true, true, true, true};
|
||||
iheap *ih = ih_new(1000, intcmp);
|
||||
mmap *mm = mm_new(1000, 0.8, intcmp, inthash);
|
||||
mset *ms = ms_new(1000, 0.6, intcmp, inthash);
|
||||
|
||||
bool a[13] = {false, false, false, false, false, false, false, false, false, false, false, false, false},
|
||||
b[13] = {false, false, false, false, false, false, false, false, false, false, false, false, false},
|
||||
c[13] = {true, true, true, true, true, true, true, true, true, true, true, true, true};
|
||||
|
||||
b[0] = d_contains(d, 1, intcmp);
|
||||
b[1] = hm_contains(hm, 1);
|
||||
@@ -59,6 +67,10 @@ int main(void)
|
||||
b[8] = tm_contains(tm, 1);
|
||||
b[9] = ts_contains(ts, 1);
|
||||
|
||||
b[10] = ih_contains(ih, 1);
|
||||
b[11] = mm_contains(mm, 1);
|
||||
b[12] = ms_contains(ms, 1);
|
||||
|
||||
for (int i = 1; i < 1001; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
@@ -81,6 +93,10 @@ int main(void)
|
||||
tm_insert(tm, i, i);
|
||||
hs_insert(hs, i);
|
||||
hm_insert(hm, i, i);
|
||||
|
||||
ih_insert(ih, i);
|
||||
mm_insert(mm, i, i);
|
||||
ms_insert(ms, i);
|
||||
}
|
||||
|
||||
for (int i = 1; i < 1001; i++)
|
||||
@@ -95,6 +111,10 @@ int main(void)
|
||||
c[7] = c[7] && s_contains(s, i, intcmp);
|
||||
c[8] = c[8] && tm_contains(tm, i);
|
||||
c[9] = c[9] && ts_contains(ts, i);
|
||||
|
||||
c[10] = c[10] && ih_contains(ih, i);
|
||||
c[11] = c[11] && mm_contains(mm, i);
|
||||
c[12] = c[12] && ms_contains(ms, i);
|
||||
}
|
||||
|
||||
for (int i = -500; i < 1; i++)
|
||||
@@ -109,6 +129,10 @@ int main(void)
|
||||
a[7] = a[7] || s_contains(s, i, intcmp);
|
||||
a[8] = a[8] || tm_contains(tm, i);
|
||||
a[9] = a[9] || ts_contains(ts, i);
|
||||
|
||||
a[10] = a[10] || ih_contains(ih, i);
|
||||
a[11] = a[11] || mm_contains(mm, i);
|
||||
a[12] = a[12] || ms_contains(ms, i);
|
||||
}
|
||||
|
||||
for (int i = 1001; i < 1500; i++)
|
||||
@@ -123,6 +147,10 @@ int main(void)
|
||||
a[7] = a[7] || s_contains(s, i, intcmp);
|
||||
a[8] = a[8] || tm_contains(tm, i);
|
||||
a[9] = a[9] || ts_contains(ts, i);
|
||||
|
||||
a[10] = a[10] || ih_contains(ih, i);
|
||||
a[11] = a[11] || mm_contains(mm, i);
|
||||
a[12] = a[12] || ms_contains(ms, i);
|
||||
}
|
||||
|
||||
d_clear(d, NULL);
|
||||
@@ -136,6 +164,10 @@ int main(void)
|
||||
tm_clear(tm, NULL);
|
||||
ts_clear(ts, NULL);
|
||||
|
||||
ih_clear(ih, NULL);
|
||||
mm_clear(mm, NULL);
|
||||
ms_clear(ms, NULL);
|
||||
|
||||
b[0] = b[0] || d_contains(d, 1, intcmp);
|
||||
b[1] = b[1] || hm_contains(hm, 1);
|
||||
b[2] = b[2] || hs_contains(hs, 1);
|
||||
@@ -147,47 +179,65 @@ int main(void)
|
||||
b[8] = b[8] || tm_contains(tm, 1);
|
||||
b[9] = b[9] || ts_contains(ts, 1);
|
||||
|
||||
b[10] = b[10] || ih_contains(ih, 1);
|
||||
b[11] = b[11] || mm_contains(mm, 1);
|
||||
b[12] = b[12] || ms_contains(ms, 1);
|
||||
|
||||
printf("-------------------- CONTAINS --------------------\n");
|
||||
if (c[0] && !a[0] && !b[0])
|
||||
printf("%10s PASSED\n", "DEQUE");
|
||||
printf("%12s PASSED\n", "DEQUE");
|
||||
else
|
||||
printf("%10s FAILED\n", "DEQUE");
|
||||
printf("%12s FAILED\n", "DEQUE");
|
||||
if (c[1] && !a[1] && !b[1])
|
||||
printf("%10s PASSED\n", "HASHMAP");
|
||||
printf("%12s PASSED\n", "HASHMAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "HASHMAP");
|
||||
printf("%12s FAILED\n", "HASHMAP");
|
||||
if (c[2] && !a[2] && !b[2])
|
||||
printf("%10s PASSED\n", "HASHSET");
|
||||
printf("%12s PASSED\n", "HASHSET");
|
||||
else
|
||||
printf("%10s FAILED\n", "HASHSET");
|
||||
printf("%12s FAILED\n", "HASHSET");
|
||||
if (c[3] && !a[3] && !b[3])
|
||||
printf("%10s PASSED\n", "HEAP");
|
||||
printf("%12s PASSED\n", "HEAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "HEAP");
|
||||
printf("%12s FAILED\n", "HEAP");
|
||||
if (c[4] && !a[4] && !b[4])
|
||||
printf("%10s PASSED\n", "LINKEDLIST");
|
||||
printf("%12s PASSED\n", "LINKEDLIST");
|
||||
else
|
||||
printf("%10s FAILED\n", "LINKEDLIST");
|
||||
printf("%12s FAILED\n", "LINKEDLIST");
|
||||
if (c[5] && !a[5] && !b[5])
|
||||
printf("%10s PASSED\n", "LIST");
|
||||
printf("%12s PASSED\n", "LIST");
|
||||
else
|
||||
printf("%10s FAILED\n", "LIST");
|
||||
printf("%12s FAILED\n", "LIST");
|
||||
if (c[6] && !a[6] && !b[6])
|
||||
printf("%10s PASSED\n", "QUEUE");
|
||||
printf("%12s PASSED\n", "QUEUE");
|
||||
else
|
||||
printf("%10s FAILED\n", "QUEUE");
|
||||
printf("%12s FAILED\n", "QUEUE");
|
||||
if (c[7] && !a[7] && !b[7])
|
||||
printf("%10s PASSED\n", "STACK");
|
||||
printf("%12s PASSED\n", "STACK");
|
||||
else
|
||||
printf("%10s FAILED\n", "STACK");
|
||||
printf("%12s FAILED\n", "STACK");
|
||||
if (c[8] && !a[8] && !b[8])
|
||||
printf("%10s PASSED\n", "TREEMAP");
|
||||
printf("%12s PASSED\n", "TREEMAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "TREEMAP");
|
||||
printf("%12s FAILED\n", "TREEMAP");
|
||||
if (c[9] && !a[9] && !b[9])
|
||||
printf("%10s PASSED\n", "TREESET");
|
||||
printf("%12s PASSED\n", "TREESET");
|
||||
else
|
||||
printf("%10s FAILED\n", "TREESET");
|
||||
printf("%12s FAILED\n", "TREESET");
|
||||
if (c[10] && !a[10] && !b[10])
|
||||
printf("%12s PASSED\n", "INTERVALHEAP");
|
||||
else
|
||||
printf("%12s FAILED\n", "INTERVALHEAP");
|
||||
if (c[11] && !a[11] && !b[11])
|
||||
printf("%12s PASSED\n", "MULTIMAP");
|
||||
else
|
||||
printf("%12s FAILED\n", "MULTIMAP");
|
||||
if (c[12] && !a[12] && !b[12])
|
||||
printf("%12s PASSED\n", "MULTISET");
|
||||
else
|
||||
printf("%12s FAILED\n", "MULTISET");
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
l_free(l, NULL);
|
||||
ll_free(ll, NULL);
|
||||
@@ -200,5 +250,9 @@ int main(void)
|
||||
hs_free(hs, NULL);
|
||||
hm_free(hm, NULL);
|
||||
|
||||
ih_free(ih, NULL);
|
||||
mm_free(mm, NULL);
|
||||
ms_free(ms, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+172
-103
@@ -1,5 +1,6 @@
|
||||
#include "../src/macro_collections.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
@@ -30,6 +31,10 @@ COLLECTION_GENERATE(TREEMAP, tm, tmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE(HASHSET, hs, hset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* FMOD */, , int)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm, mmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE(MULTISET, ms, mset, , , int)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
list *l = l_new(1000);
|
||||
@@ -40,208 +45,268 @@ int main(void)
|
||||
heap *h = h_new(1000, cmc_max_heap, intcmp);
|
||||
tset *ts = ts_new(intcmp);
|
||||
tmap *tm = tm_new(intcmp);
|
||||
hset *hs = hs_new(1000, 0.9, intcmp, inthash);
|
||||
hmap *hm = hm_new(1000, 0.9, intcmp, inthash);
|
||||
hset *hs = hs_new(1000, 0.6, intcmp, inthash);
|
||||
hmap *hm = hm_new(1000, 0.6, intcmp, inthash);
|
||||
|
||||
iheap *ih = ih_new(1000, intcmp);
|
||||
mmap *mm = mm_new(1000, 0.8, intcmp, inthash);
|
||||
mset *ms = ms_new(1000, 0.6, intcmp, inthash);
|
||||
|
||||
bool p = true;
|
||||
|
||||
for (int i = 1; i < 10001; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
d_push_front(d, i);
|
||||
l_push_front(l, i);
|
||||
ll_push_front(ll, i);
|
||||
assert(d_push_front(d, i));
|
||||
assert(l_push_front(l, i));
|
||||
assert(ll_push_front(ll, i));
|
||||
}
|
||||
else
|
||||
{
|
||||
d_push_back(d, i);
|
||||
l_push_back(l, i);
|
||||
ll_push_back(ll, i);
|
||||
assert(d_push_back(d, i));
|
||||
assert(l_push_back(l, i));
|
||||
assert(ll_push_back(ll, i));
|
||||
}
|
||||
|
||||
s_push(s, i);
|
||||
q_enqueue(q, i);
|
||||
h_insert(h, i);
|
||||
ts_insert(ts, i);
|
||||
tm_insert(tm, i, i);
|
||||
hs_insert(hs, i);
|
||||
hm_insert(hm, i, i);
|
||||
assert(s_push(s, i));
|
||||
assert(q_enqueue(q, i));
|
||||
assert(h_insert(h, i));
|
||||
assert(ts_insert(ts, i));
|
||||
assert(tm_insert(tm, i, i));
|
||||
assert(hs_insert(hs, i));
|
||||
assert(hm_insert(hm, i, i));
|
||||
|
||||
assert(ih_insert(ih, i));
|
||||
assert(mm_insert(mm, i, i));
|
||||
assert(ms_insert(ms, i));
|
||||
}
|
||||
|
||||
int sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0,
|
||||
sum7 = 0, sum8 = 0, sum9 = 0, sum10 = 0, sum11 = 0;
|
||||
int sums[16] = {0};
|
||||
|
||||
FOR_EACH(d, deque, d, {
|
||||
sum3 += d_iter_value(&iter);
|
||||
sums[0] += d_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(hm, hmap, hm, {
|
||||
sum10 += hm_iter_key(&iter);
|
||||
sum11 += hm_iter_value(&iter);
|
||||
sums[1] += hm_iter_key(&iter);
|
||||
sums[2] += hm_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(hs, hset, hs, {
|
||||
sum9 += hs_iter_value(&iter);
|
||||
sums[3] += hs_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(h, heap, h, {
|
||||
sum5 += h_iter_value(&iter);
|
||||
sums[4] += h_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(ll, linked, ll, {
|
||||
sum4 += ll_iter_value(&iter);
|
||||
sums[5] += ll_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(l, list, l, {
|
||||
sum0 += l_iter_value(&iter);
|
||||
sums[6] += l_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(q, queue, q, {
|
||||
sum2 += q_iter_value(&iter);
|
||||
sums[7] += q_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(s, stack, s, {
|
||||
sum1 += s_iter_value(&iter);
|
||||
sums[8] += s_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(tm, tmap, tm, {
|
||||
sum7 += tm_iter_key(&iter);
|
||||
sum8 += tm_iter_value(&iter);
|
||||
sums[9] += tm_iter_key(&iter);
|
||||
sums[10] += tm_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(ts, tset, ts, {
|
||||
sum6 += ts_iter_value(&iter);
|
||||
sums[11] += ts_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(ih, iheap, ih, {
|
||||
sums[12] += ih_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(mm, mmap, mm, {
|
||||
sums[13] += mm_iter_key(&iter);
|
||||
sums[14] += mm_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH(ms, mset, ms, {
|
||||
sums[15] += ms_iter_value(&iter);
|
||||
});
|
||||
|
||||
printf("\n-------------------- FOR_EACH --------------------\n");
|
||||
if (sum3 == 50005000)
|
||||
printf("%10s PASSED\n", "DEQUE");
|
||||
if (sums[0] == 50005000)
|
||||
printf("%12s PASSED\n", "DEQUE");
|
||||
else
|
||||
printf("%10s FAILED\n", "DEQUE");
|
||||
if (sum9 == 50005000)
|
||||
printf("%10s PASSED\n", "HASHSET");
|
||||
printf("%12s FAILED\n", "DEQUE");
|
||||
if (sums[1] == 50005000 && sums[2] == 50005000)
|
||||
printf("%12s PASSED\n", "HASHMAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "HASHSET");
|
||||
if (sum10 == 50005000 && sum11 == 50005000)
|
||||
printf("%10s PASSED\n", "HASHMAP");
|
||||
printf("%12s FAILED\n", "HASHMAP");
|
||||
if (sums[3] == 50005000)
|
||||
printf("%12s PASSED\n", "HASHSET");
|
||||
else
|
||||
printf("%10s FAILED\n", "HASHMAP");
|
||||
if (sum5 == 50005000)
|
||||
printf("%10s PASSED\n", "HEAP");
|
||||
printf("%12s FAILED\n", "HASHSET");
|
||||
if (sums[4] == 50005000)
|
||||
printf("%12s PASSED\n", "HEAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "HEAP");
|
||||
if (sum4 == 50005000)
|
||||
printf("%10s PASSED\n", "LINKEDLIST");
|
||||
printf("%12s FAILED\n", "HEAP");
|
||||
if (sums[5] == 50005000)
|
||||
printf("%12s PASSED\n", "LINKEDLIST");
|
||||
else
|
||||
printf("%10s FAILED\n", "LINKEDLIST");
|
||||
if (sum0 == 50005000)
|
||||
printf("%10s PASSED\n", "LIST");
|
||||
printf("%12s FAILED\n", "LINKEDLIST");
|
||||
if (sums[6] == 50005000)
|
||||
printf("%12s PASSED\n", "LIST");
|
||||
else
|
||||
printf("%10s FAILED\n", "LIST");
|
||||
if (sum2 == 50005000)
|
||||
printf("%10s PASSED\n", "QUEUE");
|
||||
printf("%12s FAILED\n", "LIST");
|
||||
if (sums[7] == 50005000)
|
||||
printf("%12s PASSED\n", "QUEUE");
|
||||
else
|
||||
printf("%10s FAILED\n", "QUEUE");
|
||||
if (sum1 == 50005000)
|
||||
printf("%10s PASSED\n", "STACK");
|
||||
printf("%12s FAILED\n", "QUEUE");
|
||||
if (sums[8] == 50005000)
|
||||
printf("%12s PASSED\n", "STACK");
|
||||
else
|
||||
printf("%10s FAILED\n", "STACK");
|
||||
if (sum7 == 50005000 && sum8 == 50005000)
|
||||
printf("%10s PASSED\n", "TREEMAP");
|
||||
printf("%12s FAILED\n", "STACK");
|
||||
if (sums[9] == 50005000 && sums[10] == 50005000)
|
||||
printf("%12s PASSED\n", "TREEMAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "TREEMAP");
|
||||
if (sum6 == 50005000)
|
||||
printf("%10s PASSED\n", "TREESET");
|
||||
printf("%12s FAILED\n", "TREEMAP");
|
||||
if (sums[11] == 50005000)
|
||||
printf("%12s PASSED\n", "TREESET");
|
||||
else
|
||||
printf("%10s FAILED\n", "TREESET");
|
||||
printf("%12s FAILED\n", "TREESET");
|
||||
if (sums[12] == 50005000)
|
||||
printf("%12s PASSED\n", "INTERVALHEAP");
|
||||
else
|
||||
printf("%12s FAILED\n", "INTERVALHEAP");
|
||||
if (sums[13] == 50005000 && sums[14] == 50005000)
|
||||
printf("%12s PASSED\n", "MULTIMAP");
|
||||
else
|
||||
printf("%12s FAILED\n", "MULTIMAP");
|
||||
if (sums[15] == 50005000)
|
||||
printf("%12s PASSED\n", "MULTISET");
|
||||
else
|
||||
printf("%12s FAILED\n", "MULTISET");
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0,
|
||||
sum7 = 0, sum8 = 0, sum9 = 0, sum10 = 0, sum11 = 0;
|
||||
memset(sums, 0, sizeof sums);
|
||||
|
||||
FOR_EACH_REV(d, deque, d, {
|
||||
sum3 += d_iter_value(&iter);
|
||||
sums[0] += d_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(hm, hmap, hm, {
|
||||
sum10 += hm_iter_key(&iter);
|
||||
sum11 += hm_iter_value(&iter);
|
||||
sums[1] += hm_iter_key(&iter);
|
||||
sums[2] += hm_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(hs, hset, hs, {
|
||||
sum9 += hs_iter_value(&iter);
|
||||
sums[3] += hs_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(h, heap, h, {
|
||||
sum5 += h_iter_value(&iter);
|
||||
sums[4] += h_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(ll, linked, ll, {
|
||||
sum4 += ll_iter_value(&iter);
|
||||
sums[5] += ll_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(l, list, l, {
|
||||
sum0 += l_iter_value(&iter);
|
||||
sums[6] += l_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(q, queue, q, {
|
||||
sum2 += q_iter_value(&iter);
|
||||
sums[7] += q_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(s, stack, s, {
|
||||
sum1 += s_iter_value(&iter);
|
||||
sums[8] += s_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(tm, tmap, tm, {
|
||||
sum7 += tm_iter_key(&iter);
|
||||
sum8 += tm_iter_value(&iter);
|
||||
sums[9] += tm_iter_key(&iter);
|
||||
sums[10] += tm_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(ts, tset, ts, {
|
||||
sum6 += ts_iter_value(&iter);
|
||||
sums[11] += ts_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(ih, iheap, ih, {
|
||||
sums[12] += ih_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(mm, mmap, mm, {
|
||||
sums[13] += mm_iter_key(&iter);
|
||||
sums[14] += mm_iter_value(&iter);
|
||||
});
|
||||
|
||||
FOR_EACH_REV(ms, mset, ms, {
|
||||
sums[15] += ms_iter_value(&iter);
|
||||
});
|
||||
|
||||
printf("-------------------- FOR_EACH_REV --------------------\n");
|
||||
if (sum3 == 50005000)
|
||||
printf("%10s PASSED\n", "DEQUE");
|
||||
if (sums[0] == 50005000)
|
||||
printf("%12s PASSED\n", "DEQUE");
|
||||
else
|
||||
printf("%10s FAILED\n", "DEQUE");
|
||||
if (sum10 == 50005000 && sum11 == 50005000)
|
||||
printf("%10s PASSED\n", "HASHMAP");
|
||||
printf("%12s FAILED\n", "DEQUE");
|
||||
if (sums[1] == 50005000 && sums[2] == 50005000)
|
||||
printf("%12s PASSED\n", "HASHMAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "HASHMAP");
|
||||
if (sum9 == 50005000)
|
||||
printf("%10s PASSED\n", "HASHSET");
|
||||
printf("%12s FAILED\n", "HASHMAP");
|
||||
if (sums[3] == 50005000)
|
||||
printf("%12s PASSED\n", "HASHSET");
|
||||
else
|
||||
printf("%10s FAILED\n", "HASHSET");
|
||||
if (sum5 == 50005000)
|
||||
printf("%10s PASSED\n", "HEAP");
|
||||
printf("%12s FAILED\n", "HASHSET");
|
||||
if (sums[4] == 50005000)
|
||||
printf("%12s PASSED\n", "HEAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "HEAP");
|
||||
if (sum4 == 50005000)
|
||||
printf("%10s PASSED\n", "LINKEDLIST");
|
||||
printf("%12s FAILED\n", "HEAP");
|
||||
if (sums[5] == 50005000)
|
||||
printf("%12s PASSED\n", "LINKEDLIST");
|
||||
else
|
||||
printf("%10s FAILED\n", "LINKEDLIST");
|
||||
if (sum0 == 50005000)
|
||||
printf("%10s PASSED\n", "LIST");
|
||||
printf("%12s FAILED\n", "LINKEDLIST");
|
||||
if (sums[6] == 50005000)
|
||||
printf("%12s PASSED\n", "LIST");
|
||||
else
|
||||
printf("%10s FAILED\n", "LIST");
|
||||
if (sum2 == 50005000)
|
||||
printf("%10s PASSED\n", "QUEUE");
|
||||
printf("%12s FAILED\n", "LIST");
|
||||
if (sums[7] == 50005000)
|
||||
printf("%12s PASSED\n", "QUEUE");
|
||||
else
|
||||
printf("%10s FAILED\n", "QUEUE");
|
||||
if (sum1 == 50005000)
|
||||
printf("%10s PASSED\n", "STACK");
|
||||
printf("%12s FAILED\n", "QUEUE");
|
||||
if (sums[8] == 50005000)
|
||||
printf("%12s PASSED\n", "STACK");
|
||||
else
|
||||
printf("%10s FAILED\n", "STACK");
|
||||
if (sum7 == 50005000 && sum8 == 50005000)
|
||||
printf("%10s PASSED\n", "TREEMAP");
|
||||
printf("%12s FAILED\n", "STACK");
|
||||
if (sums[9] == 50005000 && sums[10] == 50005000)
|
||||
printf("%12s PASSED\n", "TREEMAP");
|
||||
else
|
||||
printf("%10s FAILED\n", "TREEMAP");
|
||||
if (sum6 == 50005000)
|
||||
printf("%10s PASSED\n", "TREESET");
|
||||
printf("%12s FAILED\n", "TREEMAP");
|
||||
if (sums[11] == 50005000)
|
||||
printf("%12s PASSED\n", "TREESET");
|
||||
else
|
||||
printf("%10s FAILED\n", "TREESET");
|
||||
printf("%12s FAILED\n", "TREESET");
|
||||
if (sums[12] == 50005000)
|
||||
printf("%12s PASSED\n", "INTERVALHEAP");
|
||||
else
|
||||
printf("%12s FAILED\n", "INTERVALHEAP");
|
||||
if (sums[13] == 50005000 && sums[14] == 50005000)
|
||||
printf("%12s PASSED\n", "MULTIMAP");
|
||||
else
|
||||
printf("%12s FAILED\n", "MULTIMAP");
|
||||
if (sums[15] == 50005000)
|
||||
printf("%12s PASSED\n", "MULTISET");
|
||||
else
|
||||
printf("%12s FAILED\n", "MULTISET");
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
l_free(l, NULL);
|
||||
ll_free(ll, NULL);
|
||||
@@ -254,5 +319,9 @@ int main(void)
|
||||
hs_free(hs, NULL);
|
||||
hm_free(hm, NULL);
|
||||
|
||||
ih_free(ih, NULL);
|
||||
mm_free(mm, NULL);
|
||||
ms_free(ms, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+18
-6
@@ -1,6 +1,5 @@
|
||||
#include "../src/macro_collections.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
@@ -30,6 +29,10 @@ COLLECTION_GENERATE(TREEMAP, tm, tmap, /* FMOD */, int, double)
|
||||
COLLECTION_GENERATE(HASHSET, hs, hset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, double)
|
||||
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* FMOD */, , int)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm, mmap, /* FMOD */, int, double)
|
||||
COLLECTION_GENERATE(MULTISET, ms, mset, , , int)
|
||||
|
||||
#define ITERATOR_TEST(NAME, PFX, sname, initfunc, insertbody, sumbody, validation1, validation2) \
|
||||
void NAME##_iterator_test(void) \
|
||||
{ \
|
||||
@@ -71,22 +74,25 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, double)
|
||||
\
|
||||
PFX##_free(coll, NULL); \
|
||||
\
|
||||
if (validation1 && validation2) \
|
||||
printf("%10s PASSED\n", #NAME); \
|
||||
if ((validation1) && (validation2)) \
|
||||
printf("%12s PASSED\n", #NAME); \
|
||||
else \
|
||||
printf("%10s FAILED\n", #NAME); \
|
||||
printf("%12s FAILED\n", #NAME); \
|
||||
}
|
||||
|
||||
ITERATOR_TEST(DEQUE, d, deque, d_new(20), d_push_front(coll, i), sum1 += d_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(HASHMAP, hm, hmap, hm_new(50, 0.6, intcmp, inthash), hm_insert(coll, i, (double)i / 10.0), sum1 += hm_iter_key(&iter); sum2 += hm_iter_value(&iter), sum1 == 450, sum2 == 45.0)
|
||||
ITERATOR_TEST(HASHMAP, hm, hmap, hm_new(50, 0.6, intcmp, inthash), hm_insert(coll, i, (double)i / 10.0), sum1 += hm_iter_key(&iter); sum2 += hm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
|
||||
ITERATOR_TEST(HASHSET, hs, hset, hs_new(50, 0.6, intcmp, inthash), hs_insert(coll, i), sum1 += hs_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(HEAP, h, heap, h_new(20, cmc_max_heap, intcmp), h_insert(coll, i), sum1 += h_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(LINKEDLIST, ll, linked, ll_new(), ll_push_back(coll, i), sum1 += ll_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(LIST, l, list, l_new(20), l_push_back(coll, i), sum1 += l_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(QUEUE, q, queue, q_new(20), q_enqueue(coll, i), sum1 += q_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(STACK, s, stack, s_new(20), s_push(coll, i), sum1 += s_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(TREEMAP, tm, tmap, tm_new(intcmp), tm_insert(coll, i, (double)i / 10.0), sum1 += tm_iter_key(&iter); sum2 += tm_iter_value(&iter), sum1 == 450, sum2 == 45.0)
|
||||
ITERATOR_TEST(TREEMAP, tm, tmap, tm_new(intcmp), tm_insert(coll, i, (double)i / 10.0), sum1 += tm_iter_key(&iter); sum2 += tm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
|
||||
ITERATOR_TEST(TREESET, ts, tset, ts_new(intcmp), ts_insert(coll, i), sum1 += ts_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(INTERVALHEAP, ih, iheap, ih_new(20, intcmp), ih_insert(coll, i), sum1 += ih_iter_value(&iter), sum1 == 450, 1)
|
||||
ITERATOR_TEST(MULTIMAP, mm, mmap, mm_new(50, 0.8, intcmp, inthash), mm_insert(coll, i, (double)i / 10.0), sum1 += mm_iter_key(&iter); sum2 += mm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
|
||||
ITERATOR_TEST(MULTISET, ms, mset, ms_new(50, 0.6, intcmp, inthash), ms_insert(coll, i), sum1 += ms_iter_value(&iter); sum2 += ms_iter_multiplicity(&iter), sum1 == 450, (size_t)sum2 == 100)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@@ -102,5 +108,11 @@ int main(void)
|
||||
TREEMAP_iterator_test();
|
||||
TREESET_iterator_test();
|
||||
|
||||
INTERVALHEAP_iterator_test();
|
||||
MULTIMAP_iterator_test();
|
||||
MULTISET_iterator_test();
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+10
-2
@@ -28,8 +28,12 @@ int main(void)
|
||||
heap *h = h_new(1000, cmc_max_heap, intcmp);
|
||||
tset *ts = ts_new(intcmp);
|
||||
tmap *tm = tm_new(intcmp);
|
||||
hset *hs = hs_new(1000, 0.9, intcmp, inthash);
|
||||
hmap *hm = hm_new(1000, 0.9, intcmp, inthash);
|
||||
hset *hs = hs_new(1000, 0.6, intcmp, inthash);
|
||||
hmap *hm = hm_new(1000, 0.6, intcmp, inthash);
|
||||
|
||||
iheap *ih = ih_new(1000, intcmp);
|
||||
mmap *mm = mm_new(1000, 0.8, intcmp, inthash);
|
||||
mset *ms = ms_new(1000, 0.6, intcmp, inthash);
|
||||
|
||||
printf("+--------------------------------------------------+\n");
|
||||
printf("| Separate Header and Source is Working |\n");
|
||||
@@ -46,5 +50,9 @@ int main(void)
|
||||
hs_free(hs, NULL);
|
||||
hm_free(hm, NULL);
|
||||
|
||||
ih_free(ih, NULL);
|
||||
mm_free(mm, NULL);
|
||||
ms_free(ms, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -10,3 +10,7 @@ COLLECTION_GENERATE_SOURCE(TREESET, ts, tset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE_SOURCE(TREEMAP, tm, tmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE_SOURCE(HASHSET, hs, hset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE_SOURCE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
|
||||
COLLECTION_GENERATE_SOURCE(INTERVALHEAP, ih, iheap, /* FMOD */, , int)
|
||||
COLLECTION_GENERATE_SOURCE(MULTIMAP, mm, mmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE_SOURCE(MULTISET, ms, mset, , , int)
|
||||
@@ -10,3 +10,7 @@ COLLECTION_GENERATE_HEADER(TREESET, ts, tset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE_HEADER(TREEMAP, tm, tmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE_HEADER(HASHSET, hs, hset, /* FMOD */, /* K */, int)
|
||||
COLLECTION_GENERATE_HEADER(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
|
||||
COLLECTION_GENERATE_HEADER(INTERVALHEAP, ih, iheap, /* FMOD */, , int)
|
||||
COLLECTION_GENERATE_HEADER(MULTIMAP, mm, mmap, /* FMOD */, int, int)
|
||||
COLLECTION_GENERATE_HEADER(MULTISET, ms, mset, , , int)
|
||||
@@ -36,6 +36,9 @@ COLLECTION_GENERATE(TREESET, ts0, tset0, static, /* K */, struct_t *)
|
||||
COLLECTION_GENERATE(TREEMAP, tm0, tmap0, static, struct_t *, struct_t *)
|
||||
COLLECTION_GENERATE(HASHSET, hs0, hset0, static, /* K */, struct_t *)
|
||||
COLLECTION_GENERATE(HASHMAP, hm0, hmap0, static, struct_t *, struct_t *)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih0, iheap0, static, struct_t *, struct_t *)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm0, mmap0, static, struct_t *, struct_t *)
|
||||
COLLECTION_GENERATE(MULTISET, ms0, mset0, static, struct_t *, struct_t *)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l1, list1, static, /* K */, struct_t)
|
||||
COLLECTION_GENERATE(STACK, s1, stack1, static, /* K */, struct_t)
|
||||
@@ -47,6 +50,9 @@ COLLECTION_GENERATE(TREESET, ts1, tset1, static, /* K */, struct_t)
|
||||
COLLECTION_GENERATE(TREEMAP, tm1, tmap1, static, struct_t, struct_t)
|
||||
COLLECTION_GENERATE(HASHSET, hs1, hset1, static, /* K */, struct_t)
|
||||
COLLECTION_GENERATE(HASHMAP, hm1, hmap1, static, struct_t, struct_t)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih1, iheap1, static, struct_t, struct_t)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm1, mmap1, static, struct_t, struct_t)
|
||||
COLLECTION_GENERATE(MULTISET, ms1, mset1, static, struct_t, struct_t)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l2, list2, static, /* K */, int)
|
||||
COLLECTION_GENERATE(STACK, s2, stack2, static, /* K */, int)
|
||||
@@ -58,6 +64,9 @@ COLLECTION_GENERATE(TREESET, ts2, tset2, static, /* K */, int)
|
||||
COLLECTION_GENERATE(TREEMAP, tm2, tmap2, static, int, int)
|
||||
COLLECTION_GENERATE(HASHSET, hs2, hset2, static, /* K */, int)
|
||||
COLLECTION_GENERATE(HASHMAP, hm2, hmap2, static, int, int)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih2, iheap2, static, /* K */, int)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm2, mmap2, static, int, int)
|
||||
COLLECTION_GENERATE(MULTISET, ms2, mset2, static, /* K */, int)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l3, list3, static, /* K */, int *)
|
||||
COLLECTION_GENERATE(STACK, s3, stack3, static, /* K */, int *)
|
||||
@@ -69,6 +78,9 @@ COLLECTION_GENERATE(TREESET, ts3, tset3, static, /* K */, int *)
|
||||
COLLECTION_GENERATE(TREEMAP, tm3, tmap3, static, int *, int *)
|
||||
COLLECTION_GENERATE(HASHSET, hs3, hset3, static, /* K */, int *)
|
||||
COLLECTION_GENERATE(HASHMAP, hm3, hmap3, static, int *, int *)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih3, iheap3, static, /* K */, int *)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm3, mmap3, static, int *, int *)
|
||||
COLLECTION_GENERATE(MULTISET, ms3, mset3, static, /* K */, int *)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l4, list4, static, /* K */, enum_t *)
|
||||
COLLECTION_GENERATE(STACK, s4, stack4, static, /* K */, enum_t *)
|
||||
@@ -80,6 +92,9 @@ COLLECTION_GENERATE(TREESET, ts4, tset4, static, /* K */, enum_t *)
|
||||
COLLECTION_GENERATE(TREEMAP, tm4, tmap4, static, enum_t *, enum_t *)
|
||||
COLLECTION_GENERATE(HASHSET, hs4, hset4, static, /* K */, enum_t *)
|
||||
COLLECTION_GENERATE(HASHMAP, hm4, hmap4, static, enum_t *, enum_t *)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih4, iheap4, static, /* K */, enum_t *)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm4, mmap4, static, enum_t *, enum_t *)
|
||||
COLLECTION_GENERATE(MULTISET, ms4, mset4, static, /* K */, enum_t *)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l5, list5, static, /* K */, enum_t)
|
||||
COLLECTION_GENERATE(STACK, s5, stack5, static, /* K */, enum_t)
|
||||
@@ -91,6 +106,9 @@ COLLECTION_GENERATE(TREESET, ts5, tset5, static, /* K */, enum_t)
|
||||
COLLECTION_GENERATE(TREEMAP, tm5, tmap5, static, enum_t, enum_t)
|
||||
COLLECTION_GENERATE(HASHSET, hs5, hset5, static, /* K */, enum_t)
|
||||
COLLECTION_GENERATE(HASHMAP, hm5, hmap5, static, enum_t, enum_t)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih5, iheap5, static, /* K */, enum_t)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm5, mmap5, static, enum_t, enum_t)
|
||||
COLLECTION_GENERATE(MULTISET, ms5, mset5, static, /* K */, enum_t)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l6, list6, static, /* K */, union_t *)
|
||||
COLLECTION_GENERATE(STACK, s6, stack6, static, /* K */, union_t *)
|
||||
@@ -102,6 +120,10 @@ COLLECTION_GENERATE(TREESET, ts6, tset6, static, /* K */, union_t *)
|
||||
COLLECTION_GENERATE(TREEMAP, tm6, tmap6, static, union_t *, union_t *)
|
||||
COLLECTION_GENERATE(HASHSET, hs6, hset6, static, /* K */, union_t *)
|
||||
COLLECTION_GENERATE(HASHMAP, hm6, hmap6, static, union_t *, union_t *)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih6, iheap6, static, /* K */, union_t *)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm6, mmap6, static, union_t *, union_t *)
|
||||
COLLECTION_GENERATE(MULTISET, ms6, mset6, static, /* K */, union_t *)
|
||||
|
||||
|
||||
COLLECTION_GENERATE(LIST, l7, list7, static, /* K */, union_t)
|
||||
COLLECTION_GENERATE(STACK, s7, stack7, static, /* K */, union_t)
|
||||
@@ -113,6 +135,9 @@ COLLECTION_GENERATE(TREESET, ts7, tset7, static, /* K */, union_t)
|
||||
COLLECTION_GENERATE(TREEMAP, tm7, tmap7, static, union_t, union_t)
|
||||
COLLECTION_GENERATE(HASHSET, hs7, hset7, static, /* K */, union_t)
|
||||
COLLECTION_GENERATE(HASHMAP, hm7, hmap7, static, union_t, union_t)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih7, iheap7, static, /* K */, union_t)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm7, mmap7, static, union_t, union_t)
|
||||
COLLECTION_GENERATE(MULTISET, ms7, mset7, static, /* K */, union_t)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l8, list8, static, /* K */, func_t)
|
||||
COLLECTION_GENERATE(STACK, s8, stack8, static, /* K */, func_t)
|
||||
@@ -124,6 +149,9 @@ COLLECTION_GENERATE(TREESET, ts8, tset8, static, /* K */, func_t)
|
||||
COLLECTION_GENERATE(TREEMAP, tm8, tmap8, static, func_t, func_t)
|
||||
COLLECTION_GENERATE(HASHSET, hs8, hset8, static, /* K */, func_t)
|
||||
COLLECTION_GENERATE(HASHMAP, hm8, hmap8, static, func_t, func_t)
|
||||
COLLECTION_GENERATE(INTERVALHEAP, ih8, iheap8, static, /* K */, func_t)
|
||||
COLLECTION_GENERATE(MULTIMAP, mm8, mmap8, static, func_t, func_t)
|
||||
COLLECTION_GENERATE(MULTISET, ms8, mset8, static, /* K */, func_t)
|
||||
|
||||
COLLECTION_GENERATE(LIST, l9, list9, static, /* K */, func_t)
|
||||
COLLECTION_GENERATE(STACK, s9, stack9, static, /* K */, func_t)
|
||||
|
||||
Reference in new issue
Block a user