-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_queue_test.cpp
81 lines (68 loc) · 1.68 KB
/
ds_queue_test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <gtest/gtest.h>
extern "C" {
#include <datastructures/ds_queue.h>
}
TEST(Queue, CreateDestroy)
{
ds_queue_t *s = ds_queue_create(1000);
ASSERT_TRUE(s != NULL);
ds_queue_destroy(&s);
ASSERT_TRUE(s == NULL);
}
TEST(Queue, PushPop)
{
const size_t size = 123;
ds_queue_t *s = ds_queue_create(size);
const size_t offset = 1000;
for (size_t i = offset; i < offset + size; i++) {
ds_queue_push(s, (void *)i);
}
for (size_t i = offset; i < offset + size; i++) {
EXPECT_EQ(ds_queue_pop(s), (void *)i);
}
ds_queue_destroy(&s);
}
TEST(Queue, Empty)
{
ds_queue_t *s = ds_queue_create(1000);
EXPECT_TRUE(ds_queue_empty(s));
ds_queue_push(s, (void *)1);
EXPECT_FALSE(ds_queue_empty(s));
ds_queue_push(s, (void *)1);
EXPECT_FALSE(ds_queue_empty(s));
ds_queue_pop(s);
EXPECT_FALSE(ds_queue_empty(s));
ds_queue_pop(s);
EXPECT_TRUE(ds_queue_empty(s));
ds_queue_destroy(&s);
}
TEST(Queue, Size)
{
const size_t size = 17;
ds_queue_t *s = ds_queue_create(size);
for (size_t i = 0; i < size; i++) {
EXPECT_EQ(ds_queue_size(s), i);
ds_queue_push(s, (void *)1);
}
for (size_t i = 0; i < size; i++) {
EXPECT_EQ(ds_queue_size(s), size - i);
ds_queue_pop(s);
}
EXPECT_EQ(ds_queue_size(s), 0);
ds_queue_destroy(&s);
}
TEST(Queue, PushPopResize)
{
const size_t size = 123;
ds_queue_t *s = ds_queue_create(size);
const size_t offset = 1000;
const size_t count = 3 * size;
for (size_t i = offset; i < offset + count; i++) {
ds_queue_push(s, (void *)i);
}
for (size_t i = offset; i < offset + count; i++) {
EXPECT_EQ(ds_queue_pop(s), (void *)i);
}
EXPECT_GE(ds_queue_capacity(s), count);
ds_queue_destroy(&s);
}