forked from sylar-yin/sylar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_array.cc
59 lines (50 loc) · 1.28 KB
/
test_array.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
#include "sylar/sylar.h"
#include "sylar/ds/array.h"
static sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();
struct PidVid {
PidVid(uint32_t p = 0, uint32_t v = 0)
:pid(p), vid(v) {}
uint32_t pid;
uint32_t vid;
bool operator<(const PidVid& o) const {
return memcmp(this, &o, sizeof(o)) < 0;
}
};
void gen() {
sylar::ds::Array<int> tmp;
std::vector<int> vs;
for(int i = 0; i < 10000; ++i) {
int v = rand();
tmp.insert(v);
vs.push_back(v);
SYLAR_ASSERT(tmp.isSorted());
}
std::ofstream ofs("./array.data");
tmp.writeTo(ofs);
for(auto& i : vs) {
auto idx = tmp.exists(i);
SYLAR_ASSERT(idx >= 0);
tmp.erase(idx);
SYLAR_ASSERT(tmp.isSorted());
}
SYLAR_ASSERT(tmp.size() == 0);
}
void test() {
for(int i = 0; i < 10000; ++i) {
SYLAR_LOG_INFO(g_logger) << "i=" << i;
std::ifstream ifs("./array.data");
sylar::ds::Array<int> tmp;
if(!tmp.readFrom(ifs)) {
SYLAR_LOG_INFO(g_logger) << "error";
}
SYLAR_ASSERT(tmp.isSorted());
if(i % 100 == 0) {
SYLAR_LOG_INFO(g_logger) << "over..." << (i + 1);
}
}
}
int main(int argc, char** argv) {
gen();
test();
return 0;
}