forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_innerlist.cpp
84 lines (60 loc) · 1.75 KB
/
test_innerlist.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
82
83
84
#include "solid/utility/innerlist.hpp"
#include <vector>
#include "solid/system/cassert.hpp"
#include <iostream>
using namespace std;
using namespace solid;
enum{
InnerListOrder = 0,
InnerListPending,
InnerListSending,
InnerListCache,
InnerListCount //do not change
};
enum{
InnerLinkOrder = 0,
InnerLinkStatus,
InnerLinkCount
};
struct Node: InnerNode<InnerLinkCount>{
Node(const std::string &_rstr):str(_rstr){}
std::string str;
};
typedef std::vector<Node> NodeVectorT;
typedef InnerList<NodeVectorT, InnerLinkOrder> InnerOrderListT;
int test_innerlist(int argc, char *argv[]){
NodeVectorT node_vec;
InnerOrderListT order_list(node_vec);
SOLID_ASSERT(order_list.empty());
node_vec.push_back(Node("a"));
node_vec.push_back(Node("b"));
node_vec.push_back(Node("c"));
node_vec.push_back(Node("d"));
node_vec.push_back(Node("e"));
order_list.pushBack(4);
SOLID_ASSERT(order_list.size() == 1);
order_list.pushBack(3);
SOLID_ASSERT(order_list.size() == 2);
order_list.pushBack(2);
SOLID_ASSERT(order_list.size() == 3);
order_list.pushBack(1);
SOLID_ASSERT(order_list.size() == 4);
order_list.pushBack(0);
SOLID_ASSERT(order_list.size() == 5);
cout<<"order_list("<<order_list.size()<<"): ";
auto visit_fnc = [](const size_t _index, Node const &_rnode){cout<<_rnode.str<<' ';};
order_list.forEach(visit_fnc);
cout<<endl;
cout<<"front = "<<order_list.front().str<<endl;
order_list.erase(3);
SOLID_ASSERT(order_list.size() == 4);
cout<<"after erase(3) order_list("<<order_list.size()<<"): ";
order_list.forEach(visit_fnc);
cout<<endl;
order_list.popFront();
SOLID_ASSERT(order_list.size() == 3);
cout<<"after popFront order_list("<<order_list.size()<<"): ";
order_list.forEach(visit_fnc);
cout<<endl;
return 0;
}