aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_htable.c15
-rw-r--r--tests/test_pque.c64
-rw-r--r--tests/test_pqueue.c8
-rw-r--r--tests/test_vec.c2
4 files changed, 13 insertions, 76 deletions
diff --git a/tests/test_htable.c b/tests/test_htable.c
index 3608b5c..3dee2d3 100644
--- a/tests/test_htable.c
+++ b/tests/test_htable.c
@@ -13,16 +13,17 @@ int main() {
Int2IntHashTable ht;
Int2IntHashTable_init(&ht);
for (int i = 0; i < 10000; i++) {
- Int2IntHashTable_insert(&ht, &i, &i);
+ Int2IntHashTable_insert(&ht, i, i*2);
assert(ht.ht.size == i + 1);
assert(ht.ht.taken == i + 1);
assert(ht.ht.cap >= i + 1);
}
for (int i = 0; i < 10000; i++) {
- assert(Int2IntHashTable_get(&ht, &i) != NULL);
+ assert(Int2IntHashTable_get(&ht, i) != NULL);
+ assert(*Int2IntHashTable_get(&ht, i) == i * 2);
int t = 10000 + i;
- assert(Int2IntHashTable_get(&ht, &t) == NULL);
+ assert(Int2IntHashTable_get(&ht, t) == NULL);
}
memset(found, 0, sizeof(bool) * 10000);
@@ -36,17 +37,17 @@ int main() {
}
for (int i = 0; i < 5000; i++) {
- Int2IntHashTableIter iter = Int2IntHashTable_find(&ht, &i);
+ Int2IntHashTableIter iter = Int2IntHashTable_find(&ht, i);
Int2IntHashTable_remove(&ht, iter);
}
for (int i = 0; i < 5000; i++) {
- assert(Int2IntHashTable_find(&ht, &i) == NULL);
+ assert(Int2IntHashTable_find(&ht, i) == NULL);
int t = 5000 + i;
- assert(Int2IntHashTable_find(&ht, &t) != NULL);
+ assert(Int2IntHashTable_find(&ht, t) != NULL);
}
for (int i = 0; i < 5000; i++) {
- Int2IntHashTable_insert(&ht, &i, &i);
+ Int2IntHashTable_insert(&ht, i, i);
}
memset(found, 0, sizeof(bool) * 10000);
diff --git a/tests/test_pque.c b/tests/test_pque.c
deleted file mode 100644
index 6503174..0000000
--- a/tests/test_pque.c
+++ /dev/null
@@ -1,64 +0,0 @@
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pqueue.h"
-#include "basic_traits.h"
-
-typedef Int MinInt;
-
-int MinInt_cmp(Int *lhs, Int *rhs) {
- return -Int_cmp(lhs, rhs);
-}
-
-VECTOR_DEF(MinInt);
-VECTOR_IMPL(MinInt);
-
-PQUEUE_DEF(MinInt);
-PQUEUE_IMPL(MinInt);
-
-int main() {
- printf("[TEST] pqueue\n");
-
- IntPQueue pq;
- IntPQueue_init(&pq);
- int elems[10] = {1, 3, 2, 4, 6, 5, 9, 7, 8, 10};
- for (int i = 0; i < 10; i++) {
- int e = elems[i];
- IntPQueue_push(&pq, &e);
- }
- for (int i = 10; i >= 1; i--) {
- int *top = IntPQueue_top(&pq);
- assert(i == *top);
- IntPQueue_pop(&pq);
- }
- assert(IntPQueue_top(&pq) == NULL);
-
-
- MinIntPQueue minpq;
- MinIntPQueue_init(&minpq);
- for (int i = 0; i < 10; i++) {
- int e = elems[i];
- MinIntPQueue_push(&minpq, &e);
- }
- for (int i = 1; i <= 10; i++) {
- int *top = MinIntPQueue_top(&minpq);
- assert(i == *top);
- MinIntPQueue_pop(&minpq);
- }
- assert(MinIntPQueue_top(&minpq) == NULL);
- MinIntVector_free(&minpq.vec);
-
- int elems2[10] = {-10, -8, -7, -9, -5, -6, -4, -2, -3, -1};
- int expected[10] = {-10, -8, -7, -7, -5, -5, -4, -2, -2, -1};
- for (int i = 0; i < 10; i++) {
- int e = elems2[i];
- IntPQueue_push(&pq, &e);
- int *top = IntPQueue_top(&pq);
- assert(*top == expected[i]);
- }
- IntVector_free(&pq.vec);
- printf("[PASS] pqueue\n");
- return 0;
-}
diff --git a/tests/test_pqueue.c b/tests/test_pqueue.c
index 6503174..436a583 100644
--- a/tests/test_pqueue.c
+++ b/tests/test_pqueue.c
@@ -8,7 +8,7 @@
typedef Int MinInt;
-int MinInt_cmp(Int *lhs, Int *rhs) {
+int MinInt_cmp(Int lhs, Int rhs) {
return -Int_cmp(lhs, rhs);
}
@@ -26,7 +26,7 @@ int main() {
int elems[10] = {1, 3, 2, 4, 6, 5, 9, 7, 8, 10};
for (int i = 0; i < 10; i++) {
int e = elems[i];
- IntPQueue_push(&pq, &e);
+ IntPQueue_push(&pq, e);
}
for (int i = 10; i >= 1; i--) {
int *top = IntPQueue_top(&pq);
@@ -40,7 +40,7 @@ int main() {
MinIntPQueue_init(&minpq);
for (int i = 0; i < 10; i++) {
int e = elems[i];
- MinIntPQueue_push(&minpq, &e);
+ MinIntPQueue_push(&minpq, e);
}
for (int i = 1; i <= 10; i++) {
int *top = MinIntPQueue_top(&minpq);
@@ -54,7 +54,7 @@ int main() {
int expected[10] = {-10, -8, -7, -7, -5, -5, -4, -2, -2, -1};
for (int i = 0; i < 10; i++) {
int e = elems2[i];
- IntPQueue_push(&pq, &e);
+ IntPQueue_push(&pq, e);
int *top = IntPQueue_top(&pq);
assert(*top == expected[i]);
}
diff --git a/tests/test_vec.c b/tests/test_vec.c
index 4cbc96f..6abdd78 100644
--- a/tests/test_vec.c
+++ b/tests/test_vec.c
@@ -11,7 +11,7 @@ int main() {
for (int i = 0; i < 1000; i++) {
assert(vec.size == i);
- IntVector_push_back(&vec, &i);
+ IntVector_push_back(&vec, i);
assert(*(IntVector_end(&vec) - 1) == i);
}
assert(*IntVector_begin(&vec) == 0);