summaryrefslogtreecommitdiffhomepage
path: root/tests/test_new_queue.c
diff options
context:
space:
mode:
authortylo <[email protected]>2021-09-17 11:24:39 +0200
committertylo <[email protected]>2021-09-17 11:24:39 +0200
commit2bed88914afe24dc3a245f398b321e8f236d23d7 (patch)
tree7724be6dff0e5d61189f3e890d4533e50309e48a /tests/test_new_queue.c
parentce75e57b326f6d6368b366760336b20e660f272f (diff)
downloadSTC-modified-2bed88914afe24dc3a245f398b321e8f236d23d7.tar.gz
STC-modified-2bed88914afe24dc3a245f398b321e8f236d23d7.zip
Moved tests and v1 files
Diffstat (limited to 'tests/test_new_queue.c')
-rw-r--r--tests/test_new_queue.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_new_queue.c b/tests/test_new_queue.c
new file mode 100644
index 00000000..a76f4fde
--- /dev/null
+++ b/tests/test_new_queue.c
@@ -0,0 +1,43 @@
+#include <stc/crandom.h>
+#include <stc/forward.h>
+#include <stdio.h>
+
+forward_cqueue(pnt, struct Point);
+
+struct Point { int x, y; } typedef Point;
+int point_compare(const Point* a, const Point* b) {
+ int c = c_default_compare(&a->x, &b->x);
+ return c ? c : c_default_compare(&a->y, &b->y);
+}
+#define F_tag pnt
+#define i_val Point
+#define i_cmp point_compare
+#include <stc/cqueue.h>
+
+#define i_val int
+#include <stc/cqueue.h>
+#include <time.h>
+
+int main() {
+ int n = 60000000;
+ stc64_t rng = stc64_init(time(NULL));
+ stc64_uniform_t dist = stc64_uniform_init(0, n);
+
+ c_forauto (cqueue_int, Q)
+ {
+ // Push eight million random numbers onto the queue.
+ for (int i=0; i<n; ++i)
+ cqueue_int_push(&Q, stc64_uniform(&rng, &dist));
+
+ // Push or pop on the queue ten million times
+ printf("befor: size %zu, capacity %zu\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
+ for (int i=n; i>0; --i) {
+ int r = stc64_uniform(&rng, &dist);
+ if (r & 1)
+ cqueue_int_push(&Q, r);
+ else
+ cqueue_int_pop(&Q);
+ }
+ printf("after: size %zu, capacity %zu\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
+ }
+} \ No newline at end of file