-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarray_test2.cc
70 lines (56 loc) · 1.32 KB
/
darray_test2.cc
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
#include <type_traits>
#include <zda/darray.hpp>
#include <gtest/gtest.h>
using namespace zda;
struct A {
A(int x_) { x = x_; }
int x;
};
static_assert(!std::is_trivial<A>::value, "");
#define PREPARE_ARR \
Darray<int> arr; \
for (int i = 0; i < 100; ++i) { \
arr.Add(i); \
}
TEST(darray_test, add)
{
Darray<int> arr;
for (int i = 0; i < 100; ++i) {
arr.Add(i);
EXPECT_EQ(arr.GetBack(), i);
}
int i = 0;
for (auto e : arr) {
EXPECT_EQ(e, i);
EXPECT_EQ(arr[i], i);
++i;
}
EXPECT_EQ(arr.size(), 100);
EXPECT_EQ(arr.capacity(), 128);
}
TEST(darray_test, add2)
{
Darray<A> arr;
for (int i = 0; i < 100; ++i) {
arr.Add(i);
EXPECT_EQ(arr.GetBack().x, i);
}
int i = 0;
for (auto e : arr) {
EXPECT_EQ(e.x, i);
EXPECT_EQ(arr[i].x, i);
++i;
}
EXPECT_EQ(arr.size(), 100);
EXPECT_EQ(arr.capacity(), 128);
}
TEST(darray_test, remove)
{
PREPARE_ARR
int i = 99;
while (!arr.IsEmpty()) {
EXPECT_EQ(arr.GetBack(), i);
arr.Remove();
--i;
}
}