-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
49 lines (37 loc) · 959 Bytes
/
test.c
File metadata and controls
49 lines (37 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "the_one_ring.h"
void test_push_pop()
{
ringbuffer r;
rb_create(&r, 3);
int a = 1, b = 2, c = 3;
assert(rb_push_elem(&r, &a));
assert(rb_push_elem(&r, &b));
assert(rb_push_elem(&r, &c));
int * popped1 = (int *)rb_pop_elem(&r);
int * popped2 = (int *)rb_pop_elem(&r);
int * popped3 = (int *)rb_pop_elem(&r);
assert(*popped1 == 1);
assert(*popped2 == 2);
assert(*popped3 == 3);
rb_cleanup(&r);
}
void test_empty_pop()
{
ringbuffer r;
rb_create(&r, 5);
assert(rb_pop_elem(&r) == NULL);
rb_cleanup(&r);
}
// TODO: don't push on full ringbuffer
// TODO: bulk tests
int main()
{
test_push_pop();
printf("Basic push-pop test succeeded!\n");
test_empty_pop();
printf("Empty pop test succeeded!\n");
return 0;
}