-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
56 lines (46 loc) · 910 Bytes
/
main.c
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
49
50
51
52
53
54
55
56
#include <stdio.h>
#include "ringb.h"
int test_case(void);
int
test_case(void)
{
ringb_t b = {0};
size_t i;
int a[] = { 5, 6, 3, 4, 2, 6, 7};
size_t a_len = 7;
unsigned int elt;
size_t count;
/* display array for visual test check */
printf("array: ");
for (i = 0; i < a_len; i++) {
printf("%d ", a[i]);
}
printf("\n\n");
/* add integers to the ring buffer */
ringb_init(&b, 3);
printf("size %u\n", b.bufmask + 1);
for (i = 0; i < 30; i++) {
if (ringb_is_full(&b)) {
printf("total:%zu elements added\n\n", i);
break;
}
ringb_add_unsafe(&b, a[i]);
printf("%d added to the ring \n", a[i]);
}
count = 0;
while (!ringb_get(&b, &elt)) {
printf("retrieved from the buffer : %d\n", elt);
count++;
}
printf("total:%zu elements retrieved\n", count);
ringb_clean(&b);
return 0;
}
int
main(int argc, char *argv[])
{
(void)argc;
(void)argv;
test_case();
return 0;
}