-
Notifications
You must be signed in to change notification settings - Fork 1
/
t_s_queue.cpp
58 lines (45 loc) · 1.55 KB
/
t_s_queue.cpp
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
#include <gtest/gtest.h>
#include <stdio.h>
#define T double
#define TEMPLATE_TYPE(a) a ##_double
#define TEMPLATE_FUNCTION(a,b) a ##_double_## b
#include "s_queue.h.h"
#include "s_queue.c.h"
#undef TEMPLATE_FUNCTION
#undef TEMPLATE_TYPE
#undef T
TEST(s_queue, init)
{
double queue_buf[64];
s_queue_double queue;
EXPECT_EQ(s_queue_double_init(&queue, queue_buf, 64), 0);
EXPECT_EQ(s_queue_double_size(&queue), 0);
EXPECT_TRUE(s_queue_double_empty(&queue));
EXPECT_FALSE(s_queue_double_full(&queue));
EXPECT_EQ(s_queue_double_capacity(&queue), 64);
EXPECT_EQ(s_queue_double_available(&queue), 64);
for (int i = 0; i < 64; i++) {
EXPECT_EQ(s_queue_double_enqueue(&queue, 1.2 * i), QUEUE_NOERR);
EXPECT_EQ(s_queue_double_size(&queue), i+1);
}
EXPECT_EQ(s_queue_double_enqueue(&queue, 3.14), QUEUE_FULL);
double tmp;
for (int i = 0; i < 10; i++) {
EXPECT_EQ(s_queue_double_dequeue(&queue, &tmp), QUEUE_NOERR);
EXPECT_EQ(tmp, 1.2 * i);
}
for (int i = 0; i < 10; i++) {
EXPECT_EQ(s_queue_double_enqueue(&queue, 1.2 * i), QUEUE_NOERR);
}
for (int i = 10; i < 64; i++) {
EXPECT_EQ(s_queue_double_dequeue(&queue, &tmp), QUEUE_NOERR);
EXPECT_EQ(tmp, 1.2 * i);
}
for (int i = 0; i < 10; i++) {
EXPECT_EQ(s_queue_double_dequeue(&queue, &tmp), QUEUE_NOERR);
EXPECT_EQ(tmp, 1.2 * i);
}
EXPECT_EQ(s_queue_double_dequeue(&queue, &tmp), QUEUE_EMPTY);
s_queue_double_clear(&queue);
EXPECT_EQ(s_queue_double_size(&queue), 0);
}