60 C c = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
64 c.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout << endl;
66 a.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout << endl;
68 assert(c.all([] (
auto i) { return i >= 0; }));
69 assert(a.all([] (
auto i) { return i >= 0; }));
71 int vals[11];
int k = 0;
72 c.for_each([&
k, &vals] (
int i) { vals[
k++] = i; });
74 c.for_each([&c, vals] (
int i) { assert(c.nth_ne(i) == vals[i]); });
77 a.for_each([&
k, &vals] (
int i) { vals[
k++] = i; });
78 a.for_each([&a, vals] (
int i) { assert(a.nth_ne(i) == vals[i]); });
80 assert(c.find_ptr([] (
int i) { return i == 5; }));
81 assert(a.find_ptr([] (
int i) { return i == 5; }));
82 assert(not c.find_ptr([] (
int i) { return i == 15; }));
83 assert(not a.find_ptr([] (
int i) { return i == 15; }));
84 assert(get<0>(c.find_item([] (
int i) { return i == 5; })));
85 assert(get<0>(c.find_item([] (
int i) { return i == 5; }))
and
86 get<1>(c.find_item([] (
int i) { return i == 5; })) == 5);
87 assert(get<0>(a.find_item([] (
int i) { return i == 5; })));
88 assert(get<0>(a.find_item([] (
int i) { return i == 5; }))
and
89 get<1>(a.find_item([] (
int i) { return i == 5; })) == 5);
96 C c = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
98 c.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout << endl;
99 a.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout << endl;
102 c1.
for_each([] (
int i) { cout <<
" " << i; }); cout << endl;
105 c2.
for_each([] (
int i) { cout <<
" " << i; }); cout << endl;
107 vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
109 C c3(v.begin(), v.end());
110 c3.for_each([] (
int i) { cout <<
" " << i; }); cout << endl;
112 const C c4(v.begin(), v.end());
113 c4.for_each([] (
int i) { cout <<
" " << i; }); cout << endl;
119 C c = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
122 c.for_each([] (
int i) { cout <<
" " << i; }); cout << endl;
123 a.for_each([] (
int i) { cout <<
" " << i; }); cout << endl;
125 assert(c.all([&a] (
int i) { return a.exists([i] (int k)
126 { return k == i; }); }));
127 assert(a.all([&c] (
int i) { return c.exists([i] (int k)
128 { return k == i; }); }));
130 assert(c.exists([] (
int i) { return i == 9; }));
131 assert(a.exists([] (
int i) { return i == 9; }));
133 assert(c.all([&c] (
int i)
134 { return c.exists([i] (int k) { return i == k; }); }));
135 assert(a.all([&a] (
int i)
136 { return a.exists([i] (int k) { return i == k; }); }));
138 C cm = c.maps([] (
int i) {
return 10*i; });
139 assert(cm.all([&c] (
int k)
141 return c.exists([k] (int i) { return 10*i == k; });
144 const C ccm = a.maps([] (
int i) {
return 10*i; });
145 assert(ccm.all([a] (
int k)
147 return a.exists([k] (int i) { return 10*i == k; });
151 auto m = c.template maps<string>([] (
int i) {
return to_string(i); });
155 << c.template foldl<int>(0, [] (
auto a,
auto i) {
return a + i; })
158 << ccm.template foldl<int>(0, [] (
int a,
int i) { return a + i; })
160 <<
"S3 = " << c.
fold(0, [] (
auto a,
auto i) {
return a + i; })
162 <<
"S4 = " << a.fold(0, [] (
auto a,
auto i) { return a + i; })
166 assert(
eq(build_dynlist<int>(0, 1, 2, 3, 4, 5),
167 sort(c.filter([] (
int i) { return i < 6; }))));
168 assert(
eq(build_dynlist<int>(0, 1, 2, 3, 4, 5),
169 sort(a.filter([] (
int i) { return i < 6; }))));
171 c.pfilter([] (
int i) {
return i < 6; }).
for_each([] (
auto p)
173 cout <<
"(" << get<0>(p) <<
"," << get<1>(p) <<
")";
176 a.pfilter([] (
int i) {
return i < 6; }).
for_each([] (
auto p)
178 cout <<
"(" << get<0>(p) <<
"," << get<1>(p) <<
")";
183 auto cmp_tup = [] (std::tuple<size_t,size_t> t1, std::tuple<size_t,size_t> t2)
185 return get<0>(t1) < get<0>(t2);
188 auto l1 =
sort(c.pfilter([] (
int i) { return i < 6; }), cmp_tup);
189 auto l2 =
sort(a.pfilter([] (
int i) { return i < 6; }), cmp_tup);
193 cout <<
"(" << get<0>(p) <<
"," << get<1>(p) <<
")";
198 cout <<
"(" << get<0>(p) <<
"," << get<1>(p) <<
")";
203 auto eq_tup = [] (std::tuple<size_t,size_t> t1, std::tuple<size_t,size_t> t2)
205 return get<0>(t1) == get<0>(t2);
207 assert(
eq(
l1 ,
l2, eq_tup));
209 auto p = c.partition([] (
int i) {
return i < 6; });
210 assert(
eq(
sort(p.first), build_dynlist<int>(0, 1, 2, 3, 4, 5))
and
211 eq(
sort(p.second), build_dynlist<int>(6, 7, 8, 9)));
212 p = a.partition([] (
int i) {
return i < 6; });
213 assert(
eq(
sort(p.first), build_dynlist<int>(0, 1, 2, 3, 4, 5))
and
214 eq(
sort(p.second), build_dynlist<int>(6, 7, 8, 9)));
216 auto t = c.tpartition([] (
int i) {
return i < 6; });
217 assert(
eq(
sort(get<0>(t)), build_dynlist<int>(0, 1, 2, 3, 4, 5))
and
218 eq(
sort(get<1>(t)), build_dynlist<int>(6, 7, 8, 9)));
219 t = a.tpartition([] (
int i) {
return i < 6; });
220 assert(
eq(
sort(get<0>(t)), build_dynlist<int>(0, 1, 2, 3, 4, 5))
and
221 eq(
sort(get<1>(t)), build_dynlist<int>(6, 7, 8, 9)));
223 assert(c.length() == 10);
224 assert(a.length() == 10);
226 c.take(3).for_each([] (
auto i) { cout << i <<
" "; });
228 a.take(3).for_each([] (
auto i) { cout << i <<
" "; });
235 c.take(3).for_each([] (
auto i) { cout << i <<
" "; });
237 cc.take(3).for_each([] (
auto i) { cout << i <<
" "; });
244 cout <<
"All test were passed!" << endl
267 tests<DynList<int>>();
268 tests<DynDlist<int>>();
269 tests<DynSetTree<int>>();
270 tests<OLhashTable<int>>();
271 tests<ODhashTable<int>>();
272 tests<DynSetHash<int>>();
273 tests<ArrayHeap<int>>();
274 tests<DynArray<int>>();
275 tests<DynArrayHeap<int>>();
276 tests<DynBinHeap<int>>();
277 tests<ArrayQueue<int>>();
278 tests<FixedQueue<int>>();
279 tests<ArrayStack<int>>();
280 tests<FixedStack<int>>();
281 tests<DynListStack<int>>();
282 tests<DynListQueue<int>>();
283 tests<DynArray_Set<int>>();
284 tests<Random_Set<int>>();