Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
seq_tests.h File Reference
#include <stdio.h>
#include <serene/rt/context.h>
#include <serene/rt/impl/seq.h>
#include "base.h"
Include dependency graph for seq_tests.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  seq_dummy
 

Macros

#define SEQ_TESTS(X)
 
#define SEQ_TEST_LOG(...)
 

Typedefs

typedef struct seq_dummy seq_dummy
 

Functions

static void test_seq_empty ()
 
void test_seq_push_less_than_32 ()
 
void test_seq_push_more_than_32 ()
 

Macro Definition Documentation

◆ SEQ_TEST_LOG

#define SEQ_TEST_LOG ( ...)

Definition at line 36 of file seq_tests.h.

◆ SEQ_TESTS

#define SEQ_TESTS ( X)
Value:
X("seq::empty", test_seq_empty), \
X("seq::push_less_than_32", test_seq_push_less_than_32), \
X("seq::push_more_than_32", test_seq_push_more_than_32)
void test_seq_push_more_than_32()
Definition seq_tests.h:82
void test_seq_push_less_than_32()
Definition seq_tests.h:58
static void test_seq_empty()
Definition seq_tests.h:44

Definition at line 28 of file seq_tests.h.

28#define SEQ_TESTS(X) \
29 X("seq::empty", test_seq_empty), \
30 X("seq::push_less_than_32", test_seq_push_less_than_32), \
31 X("seq::push_more_than_32", test_seq_push_more_than_32)

Typedef Documentation

◆ seq_dummy

typedef struct seq_dummy seq_dummy

Function Documentation

◆ test_seq_empty()

static void test_seq_empty ( )
static

Definition at line 44 of file seq_tests.h.

44 {
45 MAKE_ENGINE(mm, engine);
46 MAKE_CONTEXT(engine, ctx);
47 auto s = seq_empty(ctx);
48
49 TEST_CHECK(s.len == 0);
50 TEST_CHECK(s.tail_len == 0);
51 TEST_CHECK(s.root == nullptr);
52 TEST_CHECK(s.maybe_error == nullptr);
53
54 RELEASE_CONTEXT(ctx);
55 SHUTDOWN_ENGINE(mm, engine);
56}
#define TEST_CHECK(cond)
Definition acutest.h:96
#define RELEASE_CONTEXT(x)
Definition base.h:46
#define SHUTDOWN_ENGINE(mm, engine)
Definition base.h:38
#define MAKE_ENGINE(mm, engine)
Definition base.h:32
#define MAKE_CONTEXT(engine, x)
Definition base.h:42
seq_t seq_empty(const srn_context_t *ctx)
Definition seq.c:76
Here is the call graph for this function:

◆ test_seq_push_less_than_32()

void test_seq_push_less_than_32 ( )

Definition at line 58 of file seq_tests.h.

58 {
59 MAKE_ENGINE(mm, engine);
60 MAKE_CONTEXT(engine, ctx);
61
62 seq_dummy d = {.foo = 10, .bar = 20}; // NOLINT
63 auto s = seq_empty(ctx);
64 auto s1 = seq_push(ctx, &s, (seq_elem_t)&d);
65 TEST_CHECK(s.len == 0);
66 TEST_CHECK(s.tail_len == 0);
67 TEST_CHECK(s.root == nullptr);
68 TEST_CHECK(s.maybe_error == nullptr);
69
70 TEST_CHECK(s1.len == 1);
71 TEST_CHECK(s1.tail_len == 1);
72 TEST_CHECK(s1.root == nullptr);
73 TEST_CHECK(s1.maybe_error == nullptr);
74 seq_dummy *d1 = (seq_dummy *)s1.tail[0];
75 TEST_CHECK(d1->foo == 10);
76 TEST_CHECK(d1->bar == 20);
77
78 RELEASE_CONTEXT(ctx);
79 SHUTDOWN_ENGINE(mm, engine);
80}
seq_t seq_push(const srn_context_t *ctx, const seq_t *seq, seq_elem_t x)
Definition seq.c:87
void * seq_elem_t
We use generic pointers to refer to internal nodes, leaf nodes and even elements.
Definition seq.h:131
Here is the call graph for this function:

◆ test_seq_push_more_than_32()

void test_seq_push_more_than_32 ( )

Definition at line 82 of file seq_tests.h.

82 {
83 MAKE_ENGINE(mm, engine);
84 MAKE_CONTEXT(engine, ctx);
85
86 seq_t s = seq_empty(ctx);
87
88 for (int i = 0; i < 2000; i++) {
89
90 seq_dummy *d = ALLOC(ctx, seq_dummy);
91 d->foo = i;
92 d->bar = 3000 - i;
93 s = seq_push(ctx, &s, (seq_elem_t)d);
94 }
95
96 TEST_CHECK(s.len == 2000);
97 TEST_CHECK(s.tail_len == 16);
98 TEST_CHECK(s.root != nullptr);
99 TEST_CHECK(s.maybe_error == nullptr);
100
101 seq_dummy *d1 = (seq_dummy *)s.tail[0];
102
103 ASSERT_NOT_NULL(d1);
104 TEST_CHECK(d1->foo == 1984);
105 TEST_CHECK(d1->bar == 3000 - d1->foo);
106
107 seq_dummy *d2 = (seq_dummy *)s.tail[s.tail_len - 1];
108 ASSERT_NOT_NULL(d2);
109 TEST_CHECK(d2->foo == 1999);
110 TEST_CHECK(d2->bar == 3000 - d2->foo);
111
112 for (int i = 0; i < 2000; i++) {
113 seq_lookup_result_t res = seq_get(ctx, &s, (size_t)i);
114 TEST_CHECK(res.maybe_error == nullptr);
116 seq_dummy *d = (seq_dummy *)res.data;
117
118 SEQ_TEST_LOG("%d %d %d", i, d->foo, d->bar);
119 TEST_CHECK(d->foo == i);
120 TEST_CHECK(d->bar == 3000 - i);
121 };
122
123 RELEASE_CONTEXT(ctx);
124 SHUTDOWN_ENGINE(mm, engine);
125}
#define ASSERT_NOT_NULL(x)
Definition base.h:30
#define ALLOC(ctx, T)
Definition context.h:82
seq_lookup_result_t seq_get(const srn_context_t *ctx, const seq_t *seq, size_t n)
Negative index is not supported.
Definition seq.c:173
#define SEQ_TEST_LOG(...)
Definition seq_tests.h:36
seq_elem_t data
Definition seq.h:135
Definition seq.h:155
size_t len
logical length.
Definition seq.h:161
seq_node_t * root
NULL means “all data is in tail”
Definition seq.h:167
seq_elem_t * tail
small tail array for fast push/pop.
Definition seq.h:170
uint16_t tail_len
0..SEQ_BR
Definition seq.h:163
Here is the call graph for this function: