880 |
21 Sep 07 |
peter |
// $Id$ |
880 |
21 Sep 07 |
peter |
2 |
|
880 |
21 Sep 07 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2009, 2010, 2012, 2013, 2014, 2015, 2016, 2022 Peter Johansson |
880 |
21 Sep 07 |
peter |
7 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
880 |
21 Sep 07 |
peter |
9 |
|
880 |
21 Sep 07 |
peter |
The yat library is free software; you can redistribute it and/or |
880 |
21 Sep 07 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
880 |
21 Sep 07 |
peter |
License, or (at your option) any later version. |
880 |
21 Sep 07 |
peter |
14 |
|
880 |
21 Sep 07 |
peter |
The yat library is distributed in the hope that it will be useful, |
880 |
21 Sep 07 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
880 |
21 Sep 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
880 |
21 Sep 07 |
peter |
General Public License for more details. |
880 |
21 Sep 07 |
peter |
19 |
|
880 |
21 Sep 07 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
880 |
21 Sep 07 |
peter |
22 |
*/ |
880 |
21 Sep 07 |
peter |
23 |
|
2881 |
18 Nov 12 |
peter |
24 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
25 |
|
1237 |
15 Mar 08 |
peter |
26 |
#include "Suite.h" |
1237 |
15 Mar 08 |
peter |
27 |
|
880 |
21 Sep 07 |
peter |
28 |
#include "yat/classifier/DataLookup1D.h" |
880 |
21 Sep 07 |
peter |
29 |
|
898 |
26 Sep 07 |
markus |
30 |
#include "yat/classifier/DataLookupWeighted1D.h" |
2289 |
28 Jun 10 |
peter |
31 |
#include "yat/classifier/KernelLookup.h" |
1788 |
09 Feb 09 |
peter |
32 |
#include "yat/classifier/MatrixLookup.h" |
898 |
26 Sep 07 |
markus |
33 |
#include "yat/classifier/MatrixLookupWeighted.h" |
1111 |
20 Feb 08 |
markus |
34 |
#include "yat/utility/Container2DIterator.h" |
1537 |
26 Sep 08 |
peter |
35 |
#include "yat/utility/DataWeight.h" |
2159 |
19 Jan 10 |
peter |
36 |
#include "yat/utility/DataWeightProxy.h" |
1365 |
10 Jul 08 |
peter |
37 |
#include "yat/utility/DataIterator.h" |
1121 |
22 Feb 08 |
peter |
38 |
#include "yat/utility/Matrix.h" |
1382 |
17 Jul 08 |
peter |
39 |
#include "yat/utility/MatrixWeighted.h" |
1399 |
06 Aug 08 |
peter |
40 |
#include "yat/utility/stl_utility.h" |
1120 |
21 Feb 08 |
peter |
41 |
#include "yat/utility/Vector.h" |
1490 |
11 Sep 08 |
peter |
42 |
#include "yat/utility/VectorView.h" |
1490 |
11 Sep 08 |
peter |
43 |
#include "yat/utility/VectorConstView.h" |
3534 |
21 Dec 16 |
peter |
44 |
#include "yat/utility/WeightedIteratorArchetype.h" |
1527 |
24 Sep 08 |
peter |
45 |
#include "yat/utility/WeightedIterator.h" |
1376 |
16 Jul 08 |
peter |
46 |
#include "yat/utility/WeightIterator.h" |
880 |
21 Sep 07 |
peter |
47 |
|
2202 |
21 Feb 10 |
peter |
48 |
#include <boost/concept_archetype.hpp> |
3374 |
11 Feb 15 |
peter |
49 |
#include <boost/iterator/iterator_traits.hpp> |
1399 |
06 Aug 08 |
peter |
50 |
#include <boost/iterator/transform_iterator.hpp> |
3375 |
11 Feb 15 |
peter |
51 |
#include <boost/static_assert.hpp> |
3375 |
11 Feb 15 |
peter |
52 |
#include <boost/type_traits.hpp> |
1399 |
06 Aug 08 |
peter |
53 |
|
880 |
21 Sep 07 |
peter |
54 |
#include <algorithm> |
880 |
21 Sep 07 |
peter |
55 |
#include <fstream> |
1477 |
04 Sep 08 |
peter |
56 |
#include <iterator> |
2068 |
17 Sep 09 |
peter |
57 |
#include <map> |
2068 |
17 Sep 09 |
peter |
58 |
#include <set> |
1399 |
06 Aug 08 |
peter |
59 |
#include <string> |
1365 |
10 Jul 08 |
peter |
60 |
#include <vector> |
1365 |
10 Jul 08 |
peter |
61 |
|
880 |
21 Sep 07 |
peter |
62 |
using namespace theplu::yat; |
880 |
21 Sep 07 |
peter |
63 |
|
1399 |
06 Aug 08 |
peter |
64 |
void old_main(test::Suite&); |
1477 |
04 Sep 08 |
peter |
65 |
|
1477 |
04 Sep 08 |
peter |
66 |
template<typename Iterator> |
1477 |
04 Sep 08 |
peter |
67 |
void is_weighted(Iterator, test::Suite&); |
1477 |
04 Sep 08 |
peter |
68 |
|
4200 |
19 Aug 22 |
peter |
69 |
bool is_weighted(utility::unweighted_iterator_tag x) { return false; } |
1477 |
04 Sep 08 |
peter |
70 |
bool is_weighted(utility::weighted_iterator_tag x) { return true; } |
1477 |
04 Sep 08 |
peter |
71 |
|
1399 |
06 Aug 08 |
peter |
72 |
void test_boost_util(test::Suite&); |
2068 |
17 Sep 09 |
peter |
73 |
void test_pair_second_iterator(test::Suite&); |
1399 |
06 Aug 08 |
peter |
74 |
|
2277 |
25 Jun 10 |
peter |
75 |
void test_data_iterator(test::Suite& suite); |
2282 |
26 Jun 10 |
peter |
76 |
void test_weight_iterator(test::Suite& suite); |
3322 |
06 Oct 14 |
peter |
77 |
void test_weighted_iterator_traits(test::Suite& suite); |
2151 |
17 Jan 10 |
peter |
78 |
void test_iterator_traits(test::Suite& suite); |
4135 |
21 Jan 22 |
peter |
79 |
void test_container2d_iterator(test::Suite& suite); |
1490 |
11 Sep 08 |
peter |
80 |
void test_stride_iterator(test::Suite& suite); |
1527 |
24 Sep 08 |
peter |
81 |
void test_weighted_iterator(test::Suite& suite); |
1788 |
09 Feb 09 |
peter |
82 |
void test_matrix_lookup_iterator(test::Suite& suite); |
1490 |
11 Sep 08 |
peter |
83 |
|
1237 |
15 Mar 08 |
peter |
84 |
int main(int argc, char* argv[]) |
3283 |
08 Jul 14 |
peter |
85 |
{ |
1237 |
15 Mar 08 |
peter |
86 |
test::Suite suite(argc, argv); |
1237 |
15 Mar 08 |
peter |
87 |
suite.err() << "testing iterator" << std::endl; |
880 |
21 Sep 07 |
peter |
88 |
|
1490 |
11 Sep 08 |
peter |
89 |
test_stride_iterator(suite); |
4135 |
21 Jan 22 |
peter |
90 |
test_container2d_iterator(suite); |
1399 |
06 Aug 08 |
peter |
91 |
old_main(suite); |
2070 |
23 Sep 09 |
peter |
92 |
suite.out() << "testing boost_util\n"; |
1399 |
06 Aug 08 |
peter |
93 |
test_boost_util(suite); |
2202 |
21 Feb 10 |
peter |
94 |
suite.out() << "testing iterator_traits\n"; |
2151 |
17 Jan 10 |
peter |
95 |
test_iterator_traits(suite); |
2070 |
23 Sep 09 |
peter |
96 |
suite.out() << "testing pair_second_iterator\n"; |
2068 |
17 Sep 09 |
peter |
97 |
test_pair_second_iterator(suite); |
2070 |
23 Sep 09 |
peter |
98 |
suite.out() << "testing weighted iterator\n"; |
1527 |
24 Sep 08 |
peter |
99 |
test_weighted_iterator(suite); |
2277 |
25 Jun 10 |
peter |
100 |
test_data_iterator(suite); |
2282 |
26 Jun 10 |
peter |
101 |
test_weight_iterator(suite); |
3322 |
06 Oct 14 |
peter |
102 |
test_weighted_iterator_traits(suite); |
1399 |
06 Aug 08 |
peter |
103 |
return suite.return_value(); |
1399 |
06 Aug 08 |
peter |
104 |
} |
3283 |
08 Jul 14 |
peter |
105 |
|
1477 |
04 Sep 08 |
peter |
106 |
template<typename Iterator> |
1477 |
04 Sep 08 |
peter |
107 |
void is_weighted(Iterator i, test::Suite& suite) |
1477 |
04 Sep 08 |
peter |
108 |
{ |
1477 |
04 Sep 08 |
peter |
109 |
suite.err() << "testing that iterator is unweighted... "; |
1477 |
04 Sep 08 |
peter |
110 |
typename utility::weighted_iterator_traits<Iterator>::type tag; |
1477 |
04 Sep 08 |
peter |
111 |
if (is_weighted(tag)) |
1477 |
04 Sep 08 |
peter |
112 |
suite.err() << "ok.\n"; |
1477 |
04 Sep 08 |
peter |
113 |
else { |
1477 |
04 Sep 08 |
peter |
114 |
suite.err() << "failed.\n"; |
1477 |
04 Sep 08 |
peter |
115 |
suite.add(false); |
1477 |
04 Sep 08 |
peter |
116 |
} |
1477 |
04 Sep 08 |
peter |
117 |
} |
1399 |
06 Aug 08 |
peter |
118 |
|
1477 |
04 Sep 08 |
peter |
119 |
|
1399 |
06 Aug 08 |
peter |
120 |
void old_main(test::Suite& suite) |
1399 |
06 Aug 08 |
peter |
121 |
{ |
1477 |
04 Sep 08 |
peter |
122 |
suite.err() << "testing utility::Vector::iterator" << std::endl; |
1120 |
21 Feb 08 |
peter |
123 |
utility::Vector vec(12); |
880 |
21 Sep 07 |
peter |
124 |
classifier::DataLookup1D lookup(vec); |
1120 |
21 Feb 08 |
peter |
125 |
utility::Vector::iterator begin=vec.begin(); |
1877 |
21 Mar 09 |
peter |
126 |
suite.test_random_access_iterator(begin); |
881 |
22 Sep 07 |
peter |
// test iterator to const_iterator conversion |
1120 |
21 Feb 08 |
peter |
128 |
utility::Vector::const_iterator ci = vec.begin(); |
1877 |
21 Mar 09 |
peter |
129 |
suite.test_random_access_iterator(ci); |
881 |
22 Sep 07 |
peter |
130 |
ci = begin; |
883 |
22 Sep 07 |
peter |
131 |
if (begin!=ci) |
1237 |
15 Mar 08 |
peter |
132 |
suite.add(false); |
1038 |
05 Feb 08 |
peter |
133 |
|
1490 |
11 Sep 08 |
peter |
134 |
suite.err() << "sorting..."; |
1120 |
21 Feb 08 |
peter |
135 |
utility::Vector::iterator end=vec.end(); |
880 |
21 Sep 07 |
peter |
136 |
std::sort(begin, end); |
1490 |
11 Sep 08 |
peter |
137 |
suite.err() << " sorting done\n"; |
1062 |
10 Feb 08 |
peter |
138 |
|
1237 |
15 Mar 08 |
peter |
139 |
suite.err() << "testing classifier::DataLookup1D::const_iterator" << std::endl; |
880 |
21 Sep 07 |
peter |
140 |
classifier::DataLookup1D::const_iterator lbegin=lookup.begin(); |
880 |
21 Sep 07 |
peter |
141 |
classifier::DataLookup1D::const_iterator lend=lookup.end(); |
1877 |
21 Mar 09 |
peter |
142 |
suite.test_random_access_iterator(lbegin); |
3283 |
08 Jul 14 |
peter |
143 |
|
1237 |
15 Mar 08 |
peter |
144 |
suite.err() << "copy from DataLookup1D to Vector" << std::endl; |
880 |
21 Sep 07 |
peter |
145 |
std::copy(lbegin, lend, begin); |
1237 |
15 Mar 08 |
peter |
146 |
suite.err() << "copy from Vector to Vector" << std::endl; |
880 |
21 Sep 07 |
peter |
147 |
std::copy(begin, end, begin); |
1237 |
15 Mar 08 |
peter |
148 |
suite.err() << "sort Vector" << std::endl; |
880 |
21 Sep 07 |
peter |
149 |
std::sort(begin, end); |
880 |
21 Sep 07 |
peter |
150 |
|
898 |
26 Sep 07 |
markus |
// test std algorithm on IteratorWeighted |
1585 |
15 Oct 08 |
peter |
152 |
utility::MatrixWeighted m_w(1, 3, 1, 1); |
1585 |
15 Oct 08 |
peter |
153 |
m_w(0,1).data()=2.0; |
1585 |
15 Oct 08 |
peter |
154 |
classifier::MatrixLookupWeighted mw(m_w); |
898 |
26 Sep 07 |
markus |
155 |
classifier::DataLookupWeighted1D aw(mw,0,true); |
1552 |
06 Oct 08 |
peter |
156 |
size_t nof1=std::count(aw.begin(),aw.end(),utility::DataWeight(1.0, 1.0)); |
898 |
26 Sep 07 |
markus |
157 |
if(nof1!=2) { |
1237 |
15 Mar 08 |
peter |
158 |
suite.err() << "std algoritm with IteratorWeighted failed" << std::endl; |
1237 |
15 Mar 08 |
peter |
159 |
suite.add(false); |
898 |
26 Sep 07 |
markus |
160 |
} |
1138 |
24 Feb 08 |
peter |
161 |
if (aw.begin()!=mw.begin_row(0)) |
1237 |
15 Mar 08 |
peter |
162 |
suite.add(false); |
1138 |
24 Feb 08 |
peter |
163 |
if (aw.end()!=mw.end_row(0)) |
1237 |
15 Mar 08 |
peter |
164 |
suite.add(false); |
1138 |
24 Feb 08 |
peter |
165 |
classifier::DataLookupWeighted1D aw2(mw,0,false); |
1138 |
24 Feb 08 |
peter |
166 |
if (aw2.begin()!=mw.begin_column(0)) |
1237 |
15 Mar 08 |
peter |
167 |
suite.add(false); |
1138 |
24 Feb 08 |
peter |
168 |
if (aw2.end()!=mw.end_column(0)) |
1237 |
15 Mar 08 |
peter |
169 |
suite.add(false); |
898 |
26 Sep 07 |
markus |
170 |
|
4200 |
19 Aug 22 |
peter |
171 |
utility::DataIterator<classifier::DataLookupWeighted1D::const_iterator> |
1363 |
08 Jul 08 |
peter |
172 |
data_iter(aw2.begin()); |
2070 |
23 Sep 09 |
peter |
173 |
suite.out() << "testing data_iter\n"; |
3273 |
04 Jul 14 |
peter |
174 |
test::test_readable_iterator(data_iter); |
3273 |
04 Jul 14 |
peter |
175 |
test::test_random_access_traversal_iterator(data_iter); |
2070 |
23 Sep 09 |
peter |
176 |
suite.out() << "testing weight_iter\n"; |
3273 |
04 Jul 14 |
peter |
177 |
test::test_readable_iterator(weight_iterator(aw2.begin())); |
3273 |
04 Jul 14 |
peter |
178 |
test::test_random_access_traversal_iterator(weight_iterator(aw2.begin())); |
1365 |
10 Jul 08 |
peter |
179 |
suite.add(*data_iter == 1.0); |
1404 |
07 Aug 08 |
peter |
180 |
suite.add(*data_iterator(aw2.begin()) == 1.0); |
1365 |
10 Jul 08 |
peter |
181 |
std::vector<double> stl_vec(1,0); |
3283 |
08 Jul 14 |
peter |
182 |
utility::DataIterator<std::vector<double>::iterator> |
1365 |
10 Jul 08 |
peter |
183 |
data_iter2(stl_vec.begin()); |
1365 |
10 Jul 08 |
peter |
184 |
suite.add(*data_iter2 == 0.0); |
1376 |
16 Jul 08 |
peter |
185 |
*data_iter2 = 3.14; |
1376 |
16 Jul 08 |
peter |
186 |
suite.add(*data_iter2 == 3.14); |
3283 |
08 Jul 14 |
peter |
187 |
utility::WeightIterator<std::vector<double>::iterator> |
1376 |
16 Jul 08 |
peter |
188 |
data_iter3(stl_vec.begin()); |
1376 |
16 Jul 08 |
peter |
189 |
suite.add(*data_iter3 == 1.0); |
1363 |
08 Jul 08 |
peter |
190 |
|
1377 |
16 Jul 08 |
peter |
// testing constness conversion |
2070 |
23 Sep 09 |
peter |
192 |
suite.out() << "testing const conversion\n"; |
1377 |
16 Jul 08 |
peter |
193 |
std::vector<double>::const_iterator c_iter(stl_vec.begin()); |
1377 |
16 Jul 08 |
peter |
194 |
std::vector<double>::iterator iter(stl_vec.begin()); |
1377 |
16 Jul 08 |
peter |
195 |
suite.add(iter==c_iter); |
3283 |
08 Jul 14 |
peter |
196 |
utility::DataIterator<std::vector<double>::const_iterator> |
1377 |
16 Jul 08 |
peter |
197 |
data_iter4(c_iter); |
3283 |
08 Jul 14 |
peter |
198 |
utility::DataIterator<std::vector<double>::iterator> |
1377 |
16 Jul 08 |
peter |
199 |
data_iter5(iter); |
1377 |
16 Jul 08 |
peter |
200 |
suite.add(data_iter2 == data_iter5); |
1377 |
16 Jul 08 |
peter |
201 |
suite.add(data_iter4 == data_iter5); |
1386 |
22 Jul 08 |
peter |
202 |
utility::StrideIterator<std::vector<double>::const_iterator> stride_ci(c_iter); |
1386 |
22 Jul 08 |
peter |
203 |
utility::StrideIterator<std::vector<double>::iterator> stride_i(iter); |
1386 |
22 Jul 08 |
peter |
204 |
suite.add(stride_ci==stride_i); |
1386 |
22 Jul 08 |
peter |
205 |
suite.add(stride_i==stride_ci); |
1377 |
16 Jul 08 |
peter |
206 |
|
1382 |
17 Jul 08 |
peter |
207 |
utility::MatrixWeighted x_weighted(3,4); |
1382 |
17 Jul 08 |
peter |
208 |
x_weighted.begin(); |
1382 |
17 Jul 08 |
peter |
209 |
*x_weighted.begin(); |
1382 |
17 Jul 08 |
peter |
210 |
utility::DataWeight element = *x_weighted.begin(); |
1382 |
17 Jul 08 |
peter |
211 |
*(x_weighted.begin()+1) = element; |
1404 |
07 Aug 08 |
peter |
212 |
double element_data = *data_iterator(x_weighted.begin()); |
1386 |
22 Jul 08 |
peter |
213 |
suite.add(element_data==x_weighted.begin()->data()); |
1382 |
17 Jul 08 |
peter |
214 |
|
1585 |
15 Oct 08 |
peter |
215 |
utility::Matrix m(mw.rows(), mw.columns()); |
1146 |
25 Feb 08 |
peter |
216 |
classifier::MatrixLookup ml(m); |
1146 |
25 Feb 08 |
peter |
217 |
classifier::DataLookup1D dl1(ml,0,true); |
1146 |
25 Feb 08 |
peter |
218 |
if (dl1.begin()!=ml.begin_row(0)) |
1237 |
15 Mar 08 |
peter |
219 |
suite.add(false); |
1146 |
25 Feb 08 |
peter |
220 |
if (dl1.end()!=ml.end_row(0)) |
1237 |
15 Mar 08 |
peter |
221 |
suite.add(false); |
1146 |
25 Feb 08 |
peter |
222 |
classifier::DataLookup1D dl2(ml,0,false); |
1146 |
25 Feb 08 |
peter |
223 |
if (dl2.begin()!=ml.begin_column(0)) |
1237 |
15 Mar 08 |
peter |
224 |
suite.add(false); |
1146 |
25 Feb 08 |
peter |
225 |
if (dl2.end()!=ml.end_column(0)) |
1237 |
15 Mar 08 |
peter |
226 |
suite.add(false); |
1146 |
25 Feb 08 |
peter |
227 |
|
880 |
21 Sep 07 |
peter |
228 |
} |
1399 |
06 Aug 08 |
peter |
229 |
|
3507 |
19 Jul 16 |
peter |
230 |
|
1399 |
06 Aug 08 |
peter |
231 |
void test_boost_util(test::Suite& suite) |
1399 |
06 Aug 08 |
peter |
232 |
{ |
1399 |
06 Aug 08 |
peter |
233 |
bool ok_cached=suite.ok(); |
1399 |
06 Aug 08 |
peter |
234 |
utility::PairFirst<std::pair<std::string, int> > pf; |
1399 |
06 Aug 08 |
peter |
235 |
std::pair<std::string, int> p("July", 31); |
1399 |
06 Aug 08 |
peter |
236 |
std::string str=pf(p); |
1399 |
06 Aug 08 |
peter |
237 |
suite.add(str=="July"); |
1399 |
06 Aug 08 |
peter |
238 |
pf(p)="juli"; |
1399 |
06 Aug 08 |
peter |
239 |
suite.add(pf(p)=="juli"); |
1399 |
06 Aug 08 |
peter |
240 |
|
1399 |
06 Aug 08 |
peter |
241 |
typedef utility::PairFirst<std::pair<const std::string, int> > PF2; |
1399 |
06 Aug 08 |
peter |
242 |
PF2 pf2; |
1399 |
06 Aug 08 |
peter |
243 |
std::pair<const std::string, int> p2("July", 31); |
1399 |
06 Aug 08 |
peter |
244 |
suite.add(pf2(p2)=="July"); |
1399 |
06 Aug 08 |
peter |
245 |
|
1399 |
06 Aug 08 |
peter |
246 |
utility::PairFirst<const std::pair<std::string, int> > pf3; |
1399 |
06 Aug 08 |
peter |
247 |
std::pair<std::string, int> p3("July", 31); |
1399 |
06 Aug 08 |
peter |
248 |
suite.add(pf3(p3)=="July"); |
1399 |
06 Aug 08 |
peter |
249 |
|
1399 |
06 Aug 08 |
peter |
250 |
utility::PairFirst<std::pair<std::string, const int> > pf4; |
1399 |
06 Aug 08 |
peter |
251 |
std::pair<std::string, const int> p4("July", 31); |
1399 |
06 Aug 08 |
peter |
252 |
suite.add(pf4(p4)=="July"); |
1399 |
06 Aug 08 |
peter |
253 |
pf4(p4)="juli"; |
1399 |
06 Aug 08 |
peter |
254 |
suite.add(pf4(p4)=="juli"); |
1399 |
06 Aug 08 |
peter |
255 |
|
1399 |
06 Aug 08 |
peter |
256 |
utility::PairFirst<std::pair<const std::string, const int> > pf5; |
1399 |
06 Aug 08 |
peter |
257 |
std::pair<const std::string, const int> p5("July", 31); |
1399 |
06 Aug 08 |
peter |
258 |
suite.add(pf5(p5)=="July"); |
1399 |
06 Aug 08 |
peter |
259 |
|
1399 |
06 Aug 08 |
peter |
260 |
typedef std::map<std::string, int> Map; |
1399 |
06 Aug 08 |
peter |
261 |
Map m; |
1399 |
06 Aug 08 |
peter |
262 |
m["July"]=31; |
1399 |
06 Aug 08 |
peter |
263 |
m["September"]=30; |
1399 |
06 Aug 08 |
peter |
264 |
m["June"]=30; |
1399 |
06 Aug 08 |
peter |
265 |
m["April"]=30; |
1399 |
06 Aug 08 |
peter |
266 |
|
1399 |
06 Aug 08 |
peter |
267 |
boost::transform_iterator<PF2, Map::iterator> first_iterator(m.begin(), pf2); |
1399 |
06 Aug 08 |
peter |
268 |
boost::transform_iterator<PF2, Map::iterator> first_iterator_end(m.end(), pf2); |
1399 |
06 Aug 08 |
peter |
269 |
std::vector<std::string> vec(m.size()); |
1399 |
06 Aug 08 |
peter |
270 |
std::copy(first_iterator, first_iterator_end, vec.begin()); |
1400 |
07 Aug 08 |
peter |
271 |
std::vector<std::string> correct; |
1400 |
07 Aug 08 |
peter |
272 |
correct.push_back("April"); |
1400 |
07 Aug 08 |
peter |
273 |
correct.push_back("July"); |
1400 |
07 Aug 08 |
peter |
274 |
correct.push_back("June"); |
1400 |
07 Aug 08 |
peter |
275 |
correct.push_back("September"); |
1400 |
07 Aug 08 |
peter |
276 |
for (size_t i=0; i<vec.size(); ++i) |
1400 |
07 Aug 08 |
peter |
277 |
if (!suite.add(vec[i]==correct[i])) |
3283 |
08 Jul 14 |
peter |
278 |
suite.err() << "Error: vec[" << i << "] = " << vec[i] |
1400 |
07 Aug 08 |
peter |
279 |
<< " expected " << correct[i] << "\n"; |
1399 |
06 Aug 08 |
peter |
280 |
|
1399 |
06 Aug 08 |
peter |
281 |
std::vector<std::string> vec2(m.size()); |
3283 |
08 Jul 14 |
peter |
282 |
std::copy(utility::pair_first_iterator(m.begin()), |
1399 |
06 Aug 08 |
peter |
283 |
utility::pair_first_iterator(m.end()), |
1399 |
06 Aug 08 |
peter |
284 |
vec2.begin()); |
1399 |
06 Aug 08 |
peter |
285 |
suite.add(vec2==vec); |
3283 |
08 Jul 14 |
peter |
286 |
|
1403 |
07 Aug 08 |
peter |
287 |
std::vector<int> days; |
1403 |
07 Aug 08 |
peter |
288 |
days.resize(m.size()); |
3283 |
08 Jul 14 |
peter |
289 |
std::copy(utility::pair_second_iterator(m.begin()), |
1403 |
07 Aug 08 |
peter |
290 |
utility::pair_second_iterator(m.end()), |
1403 |
07 Aug 08 |
peter |
291 |
days.begin()); |
1403 |
07 Aug 08 |
peter |
292 |
std::vector<int> days_correct; |
1403 |
07 Aug 08 |
peter |
293 |
days_correct.push_back(30); |
1403 |
07 Aug 08 |
peter |
294 |
days_correct.push_back(31); |
1403 |
07 Aug 08 |
peter |
295 |
days_correct.push_back(30); |
1403 |
07 Aug 08 |
peter |
296 |
days_correct.push_back(30); |
1403 |
07 Aug 08 |
peter |
297 |
for (size_t i=0; i<days.size(); ++i) |
1403 |
07 Aug 08 |
peter |
298 |
if (!suite.add(days[i]==days_correct[i])) |
3283 |
08 Jul 14 |
peter |
299 |
suite.err() << "Error: days[" << i << "] = " << days[i] |
1403 |
07 Aug 08 |
peter |
300 |
<< " expected " << days_correct[i] << "\n"; |
1403 |
07 Aug 08 |
peter |
301 |
days = std::vector<int>(days.size(), 0); |
1403 |
07 Aug 08 |
peter |
302 |
std::copy(days.begin(), days.end(), utility::pair_second_iterator(m.begin())); |
1403 |
07 Aug 08 |
peter |
303 |
for (std::map<std::string, int>::const_iterator i=m.begin(); i!=m.end(); ++i) |
1403 |
07 Aug 08 |
peter |
304 |
if (!suite.add(i->second==0) ) |
3283 |
08 Jul 14 |
peter |
305 |
suite.err() << "Error: m[" << i->first << "] = " << i->second |
1403 |
07 Aug 08 |
peter |
306 |
<< " expected 0\n"; |
1399 |
06 Aug 08 |
peter |
307 |
|
1399 |
06 Aug 08 |
peter |
308 |
if (ok_cached && !suite.ok()) |
1399 |
06 Aug 08 |
peter |
309 |
suite.err() << "test_bool_util failed" << std::endl; |
1399 |
06 Aug 08 |
peter |
310 |
} |
1477 |
04 Sep 08 |
peter |
311 |
|
2151 |
17 Jan 10 |
peter |
312 |
|
2277 |
25 Jun 10 |
peter |
313 |
void test_data_iterator(test::Suite& suite) |
2277 |
25 Jun 10 |
peter |
314 |
{ |
2277 |
25 Jun 10 |
peter |
// do not run compile test |
2277 |
25 Jun 10 |
peter |
316 |
return; |
2277 |
25 Jun 10 |
peter |
317 |
|
2277 |
25 Jun 10 |
peter |
318 |
using utility::DataIterator; |
2277 |
25 Jun 10 |
peter |
319 |
using boost::input_iterator_archetype; |
2277 |
25 Jun 10 |
peter |
320 |
input_iterator_archetype<double> input_it; |
2277 |
25 Jun 10 |
peter |
321 |
using boost::mutable_forward_iterator_archetype; |
2277 |
25 Jun 10 |
peter |
322 |
mutable_forward_iterator_archetype<double> forward_it; |
3280 |
08 Jul 14 |
peter |
323 |
|
2277 |
25 Jun 10 |
peter |
324 |
using utility::data_iterator; |
2277 |
25 Jun 10 |
peter |
325 |
std::copy(data_iterator(input_it), |
2277 |
25 Jun 10 |
peter |
326 |
data_iterator(input_it), |
2277 |
25 Jun 10 |
peter |
327 |
data_iterator(forward_it)); |
2277 |
25 Jun 10 |
peter |
328 |
|
2282 |
26 Jun 10 |
peter |
329 |
boost::input_iterator_archetype_no_proxy<utility::DataWeight> input_it_w; |
2277 |
25 Jun 10 |
peter |
330 |
mutable_forward_iterator_archetype<utility::DataWeight> forward_it_w; |
2277 |
25 Jun 10 |
peter |
331 |
std::copy(data_iterator(input_it_w), |
2277 |
25 Jun 10 |
peter |
332 |
data_iterator(input_it_w), |
2277 |
25 Jun 10 |
peter |
333 |
data_iterator(forward_it_w)); |
2282 |
26 Jun 10 |
peter |
334 |
|
2277 |
25 Jun 10 |
peter |
335 |
} |
2277 |
25 Jun 10 |
peter |
336 |
|
2277 |
25 Jun 10 |
peter |
337 |
|
2282 |
26 Jun 10 |
peter |
338 |
void test_weight_iterator(test::Suite& suite) |
2282 |
26 Jun 10 |
peter |
339 |
{ |
2282 |
26 Jun 10 |
peter |
// do not run compile test |
2282 |
26 Jun 10 |
peter |
341 |
return; |
2282 |
26 Jun 10 |
peter |
342 |
|
2282 |
26 Jun 10 |
peter |
343 |
using utility::WeightIterator; |
2282 |
26 Jun 10 |
peter |
344 |
using boost::input_iterator_archetype; |
2282 |
26 Jun 10 |
peter |
345 |
input_iterator_archetype<double> input_it; |
2282 |
26 Jun 10 |
peter |
346 |
using boost::mutable_forward_iterator_archetype; |
3280 |
08 Jul 14 |
peter |
347 |
|
2282 |
26 Jun 10 |
peter |
// we are using weighted here because unweighted WeightIterator is |
2282 |
26 Jun 10 |
peter |
// always const (not mutable) |
2282 |
26 Jun 10 |
peter |
350 |
mutable_forward_iterator_archetype<utility::DataWeight> forward_it_w; |
2282 |
26 Jun 10 |
peter |
351 |
|
2282 |
26 Jun 10 |
peter |
352 |
using utility::weight_iterator; |
2282 |
26 Jun 10 |
peter |
353 |
std::copy(weight_iterator(input_it), |
2282 |
26 Jun 10 |
peter |
354 |
weight_iterator(input_it), |
2282 |
26 Jun 10 |
peter |
355 |
weight_iterator(forward_it_w)); |
2282 |
26 Jun 10 |
peter |
356 |
|
2282 |
26 Jun 10 |
peter |
357 |
boost::input_iterator_archetype_no_proxy<utility::DataWeight> input_it_w; |
2282 |
26 Jun 10 |
peter |
358 |
std::copy(weight_iterator(input_it_w), |
2282 |
26 Jun 10 |
peter |
359 |
weight_iterator(input_it_w), |
2282 |
26 Jun 10 |
peter |
360 |
weight_iterator(forward_it_w)); |
2282 |
26 Jun 10 |
peter |
361 |
} |
2282 |
26 Jun 10 |
peter |
362 |
|
2282 |
26 Jun 10 |
peter |
363 |
|
3322 |
06 Oct 14 |
peter |
364 |
void test_weighted_iterator_traits(test::Suite& suite) |
3322 |
06 Oct 14 |
peter |
365 |
{ |
3322 |
06 Oct 14 |
peter |
366 |
typedef boost::iterator_archetypes::readable_iterator_t Access; |
3379 |
13 Feb 15 |
peter |
367 |
typedef boost::single_pass_traversal_tag Traversal; |
3322 |
06 Oct 14 |
peter |
368 |
if (false) { |
3534 |
21 Dec 16 |
peter |
369 |
typedef utility::WeightedIteratorArchetype<Access, Traversal> I; |
3374 |
11 Feb 15 |
peter |
// test that boost trait class works |
3374 |
11 Feb 15 |
peter |
371 |
typedef boost::iterator_value<I>::type value_type; |
3375 |
11 Feb 15 |
peter |
// test that value type is DataWeight |
3375 |
11 Feb 15 |
peter |
373 |
using utility::DataWeight; |
3375 |
11 Feb 15 |
peter |
374 |
BOOST_STATIC_ASSERT((boost::is_same<value_type, DataWeight>::type::value)); |
3322 |
06 Oct 14 |
peter |
375 |
theplu::yat::utility::weighted_iterator_traits<I>::type tag; |
3322 |
06 Oct 14 |
peter |
376 |
test::avoid_compiler_warning(tag); |
3322 |
06 Oct 14 |
peter |
377 |
} |
3322 |
06 Oct 14 |
peter |
378 |
if (false) { |
3322 |
06 Oct 14 |
peter |
379 |
typedef double Value; |
3322 |
06 Oct 14 |
peter |
380 |
typedef boost::iterator_archetype<Value, Access, Traversal> I; |
3374 |
11 Feb 15 |
peter |
// test that boost trait class works |
3374 |
11 Feb 15 |
peter |
382 |
typedef boost::iterator_value<I>::type value_type; |
3375 |
11 Feb 15 |
peter |
// test that value type is double |
3375 |
11 Feb 15 |
peter |
384 |
BOOST_STATIC_ASSERT((boost::is_same<value_type, double>::type::value)); |
3322 |
06 Oct 14 |
peter |
385 |
theplu::yat::utility::weighted_iterator_traits<I>::type tag; |
3322 |
06 Oct 14 |
peter |
386 |
test::avoid_compiler_warning(tag); |
3322 |
06 Oct 14 |
peter |
387 |
} |
3322 |
06 Oct 14 |
peter |
388 |
} |
3322 |
06 Oct 14 |
peter |
389 |
|
3322 |
06 Oct 14 |
peter |
390 |
|
2151 |
17 Jan 10 |
peter |
391 |
void test_iterator_traits(test::Suite& suite) |
2151 |
17 Jan 10 |
peter |
392 |
{ |
2202 |
21 Feb 10 |
peter |
393 |
typedef std::vector<utility::DataWeight>::iterator Iter; |
2202 |
21 Feb 10 |
peter |
394 |
suite.add(utility::detail::iter_has_mutable_weight<Iter>::value); |
2202 |
21 Feb 10 |
peter |
395 |
typedef std::vector<utility::DataWeight>::const_iterator Iter2; |
2202 |
21 Feb 10 |
peter |
396 |
suite.add(!utility::detail::iter_has_mutable_weight<Iter2>::value); |
2202 |
21 Feb 10 |
peter |
397 |
|
2151 |
17 Jan 10 |
peter |
398 |
typedef std::vector<utility::DataWeight> WeightVector; |
2151 |
17 Jan 10 |
peter |
399 |
WeightVector vec(1); |
2202 |
21 Feb 10 |
peter |
400 |
utility::iterator_traits<WeightVector::iterator> traits; |
2151 |
17 Jan 10 |
peter |
401 |
double w = traits.weight(vec.begin()); |
2202 |
21 Feb 10 |
peter |
402 |
traits.weight(vec.begin()) = w; |
2151 |
17 Jan 10 |
peter |
403 |
suite.add(suite.equal(w, 1.0)); |
2202 |
21 Feb 10 |
peter |
404 |
|
2202 |
21 Feb 10 |
peter |
405 |
utility::iterator_traits<WeightVector::const_iterator> c_traits; |
2202 |
21 Feb 10 |
peter |
406 |
w = c_traits.weight(vec.begin()); |
2202 |
21 Feb 10 |
peter |
407 |
suite.add(suite.equal(w, 1.0)); |
2202 |
21 Feb 10 |
peter |
408 |
|
2159 |
19 Jan 10 |
peter |
409 |
utility::iterator_traits<utility::DataWeight*>().weight(&vec[0]); |
2159 |
19 Jan 10 |
peter |
410 |
|
2159 |
19 Jan 10 |
peter |
411 |
double* trivial_iter = new double(1.0); |
4200 |
19 Aug 22 |
peter |
412 |
utility::DataWeightProxy<double*, double*> dwp(trivial_iter,trivial_iter); |
2159 |
19 Jan 10 |
peter |
413 |
typedef utility::DataWeightProxy<double*, double*> Proxy; |
2202 |
21 Feb 10 |
peter |
414 |
utility::iterator_traits<Proxy*> traits2; |
2202 |
21 Feb 10 |
peter |
415 |
w = traits2.weight(&dwp); |
2159 |
19 Jan 10 |
peter |
416 |
delete trivial_iter; |
2282 |
26 Jun 10 |
peter |
417 |
|
2282 |
26 Jun 10 |
peter |
// do not run compile test |
3322 |
06 Oct 14 |
peter |
419 |
if (false) { |
3322 |
06 Oct 14 |
peter |
420 |
using utility::DataWeight; |
3322 |
06 Oct 14 |
peter |
421 |
using utility::iterator_traits; |
3322 |
06 Oct 14 |
peter |
422 |
|
3322 |
06 Oct 14 |
peter |
// test unweighted iterator |
3322 |
06 Oct 14 |
peter |
424 |
typedef boost::iterator_archetypes::readable_iterator_t Access; |
3379 |
13 Feb 15 |
peter |
425 |
typedef boost::single_pass_traversal_tag Traversal; |
3322 |
06 Oct 14 |
peter |
// test unweighted iterator |
3322 |
06 Oct 14 |
peter |
427 |
{ |
3322 |
06 Oct 14 |
peter |
428 |
typedef double Value; |
3322 |
06 Oct 14 |
peter |
429 |
typedef boost::input_iterator_archetype<Value> I; |
3322 |
06 Oct 14 |
peter |
430 |
I iter; |
3322 |
06 Oct 14 |
peter |
431 |
iterator_traits<I> traits; |
3322 |
06 Oct 14 |
peter |
432 |
double x = traits.data(iter); |
3322 |
06 Oct 14 |
peter |
433 |
x = traits.weight(iter); |
3322 |
06 Oct 14 |
peter |
434 |
test::avoid_compiler_warning(x); |
3322 |
06 Oct 14 |
peter |
435 |
} |
3322 |
06 Oct 14 |
peter |
// test weighted iterator |
3322 |
06 Oct 14 |
peter |
437 |
{ |
3534 |
21 Dec 16 |
peter |
438 |
typedef utility::WeightedIteratorArchetype<Access, Traversal> I; |
3534 |
21 Dec 16 |
peter |
439 |
utility::WeightedIteratorArchetype_ctor_arg arg; |
3322 |
06 Oct 14 |
peter |
440 |
I iter(arg); |
3322 |
06 Oct 14 |
peter |
441 |
iterator_traits<I> traits; |
3322 |
06 Oct 14 |
peter |
442 |
double x = traits.data(iter); |
3322 |
06 Oct 14 |
peter |
443 |
test::avoid_compiler_warning(x); |
3322 |
06 Oct 14 |
peter |
444 |
double w = traits.weight(iter); |
3322 |
06 Oct 14 |
peter |
445 |
test::avoid_compiler_warning(w); |
3322 |
06 Oct 14 |
peter |
446 |
} |
3322 |
06 Oct 14 |
peter |
// test with mutable weighted |
3322 |
06 Oct 14 |
peter |
448 |
{ |
3322 |
06 Oct 14 |
peter |
449 |
typedef |
3322 |
06 Oct 14 |
peter |
450 |
boost::iterator_archetypes::readable_writable_iterator_t MutableAccess; |
3534 |
21 Dec 16 |
peter |
451 |
typedef utility::WeightedIteratorArchetype<MutableAccess, Traversal> I; |
3534 |
21 Dec 16 |
peter |
452 |
utility::WeightedIteratorArchetype_ctor_arg arg; |
3322 |
06 Oct 14 |
peter |
453 |
I iter(arg); |
3322 |
06 Oct 14 |
peter |
454 |
iterator_traits<I> traits; |
3322 |
06 Oct 14 |
peter |
455 |
double x = traits.data(iter); |
3322 |
06 Oct 14 |
peter |
456 |
test::avoid_compiler_warning(x); |
3322 |
06 Oct 14 |
peter |
457 |
double w = traits.weight(iter); |
3322 |
06 Oct 14 |
peter |
458 |
test::avoid_compiler_warning(w); |
3322 |
06 Oct 14 |
peter |
// test that return types are non-const |
3322 |
06 Oct 14 |
peter |
460 |
traits.data(iter) = 0.5; |
3322 |
06 Oct 14 |
peter |
461 |
traits.weight(iter) = 0.5; |
3322 |
06 Oct 14 |
peter |
462 |
} |
3322 |
06 Oct 14 |
peter |
463 |
} |
2151 |
17 Jan 10 |
peter |
464 |
} |
2151 |
17 Jan 10 |
peter |
465 |
|
2151 |
17 Jan 10 |
peter |
466 |
|
4135 |
21 Jan 22 |
peter |
467 |
void test_container2d_iterator(test::Suite& suite) |
4135 |
21 Jan 22 |
peter |
468 |
{ |
4135 |
21 Jan 22 |
peter |
469 |
using utility::Container2DIterator; |
4135 |
21 Jan 22 |
peter |
470 |
if (false) { |
4135 |
21 Jan 22 |
peter |
471 |
using utility::MatrixBase; |
4135 |
21 Jan 22 |
peter |
472 |
using utility::MatrixMutable; |
4135 |
21 Jan 22 |
peter |
473 |
typedef Container2DIterator<MatrixMutable, double> iterator; |
4136 |
21 Jan 22 |
peter |
474 |
typedef Container2DIterator<const MatrixBase, const double> const_iterator; |
4135 |
21 Jan 22 |
peter |
475 |
utility::Matrix m(2,2); |
4135 |
21 Jan 22 |
peter |
476 |
iterator it(m, 0, 0); |
4135 |
21 Jan 22 |
peter |
477 |
const_iterator cit(m, 0, 0); |
4135 |
21 Jan 22 |
peter |
478 |
cit = it; |
4135 |
21 Jan 22 |
peter |
479 |
bool b = (cit < it); |
4135 |
21 Jan 22 |
peter |
480 |
b = (it < cit); |
4135 |
21 Jan 22 |
peter |
481 |
test::avoid_compiler_warning(b); |
4135 |
21 Jan 22 |
peter |
482 |
} |
4135 |
21 Jan 22 |
peter |
483 |
} |
4135 |
21 Jan 22 |
peter |
484 |
|
4135 |
21 Jan 22 |
peter |
485 |
|
1490 |
11 Sep 08 |
peter |
486 |
void test_stride_iterator(test::Suite& suite) |
1490 |
11 Sep 08 |
peter |
487 |
{ |
1490 |
11 Sep 08 |
peter |
488 |
suite.err() << "testing StrideIterator" << std::endl; |
1490 |
11 Sep 08 |
peter |
489 |
using utility::Vector; |
1490 |
11 Sep 08 |
peter |
490 |
Vector a(10); |
1490 |
11 Sep 08 |
peter |
// stride 2 |
1490 |
11 Sep 08 |
peter |
492 |
utility::VectorConstView b(a, 0, 5, 2); |
1490 |
11 Sep 08 |
peter |
493 |
if (!suite.add(b.end()-b.begin()==5)) |
3283 |
08 Jul 14 |
peter |
494 |
suite.err() << "ERROR: StrideIterator::operator- returned: " |
3283 |
08 Jul 14 |
peter |
495 |
<< b.end()-b.begin() |
1490 |
11 Sep 08 |
peter |
496 |
<< " expected 5\n"; |
1490 |
11 Sep 08 |
peter |
497 |
utility::VectorView c(a, 0, 3, 2); |
1490 |
11 Sep 08 |
peter |
498 |
Vector::iterator begin = c.begin(); |
1490 |
11 Sep 08 |
peter |
499 |
Vector::iterator end = c.end(); |
1490 |
11 Sep 08 |
peter |
500 |
Vector::const_iterator cbegin = begin; |
1490 |
11 Sep 08 |
peter |
501 |
Vector::const_iterator cend = end; |
1490 |
11 Sep 08 |
peter |
502 |
|
1490 |
11 Sep 08 |
peter |
503 |
if (!suite.add(c.size()==3)) |
1490 |
11 Sep 08 |
peter |
504 |
suite.err() << "c.size() incorrect" << std::endl; |
1490 |
11 Sep 08 |
peter |
505 |
if (!suite.add(cend-cbegin == 3)) |
3283 |
08 Jul 14 |
peter |
506 |
suite.err() << "cend-cbegin failed\n"; |
2183 |
05 Feb 10 |
peter |
507 |
|
2183 |
05 Feb 10 |
peter |
508 |
typedef utility::Vector::iterator iterator; |
2183 |
05 Feb 10 |
peter |
509 |
typedef std::reverse_iterator<iterator> reverse_iterator; |
2183 |
05 Feb 10 |
peter |
510 |
|
2183 |
05 Feb 10 |
peter |
511 |
reverse_iterator rbegin(c.end()); |
2183 |
05 Feb 10 |
peter |
512 |
reverse_iterator rend(c.begin()); |
2183 |
05 Feb 10 |
peter |
// some pointless usage of the iterators |
2183 |
05 Feb 10 |
peter |
514 |
std::copy(rbegin, rend, rbegin); |
2183 |
05 Feb 10 |
peter |
515 |
|
2202 |
21 Feb 10 |
peter |
// do not run compile test |
2202 |
21 Feb 10 |
peter |
517 |
if (false) { |
2202 |
21 Feb 10 |
peter |
518 |
using utility::StrideIterator; |
2202 |
21 Feb 10 |
peter |
519 |
StrideIterator<boost::random_access_iterator_archetype<double> > iter; |
2202 |
21 Feb 10 |
peter |
520 |
suite.test_random_access_iterator(iter); |
2202 |
21 Feb 10 |
peter |
521 |
double x = *iter; |
2202 |
21 Feb 10 |
peter |
522 |
x *= 2; // avoid compiler warning |
2289 |
28 Jun 10 |
peter |
523 |
|
3393 |
17 Mar 15 |
peter |
// ticket #623 is about iterator below did not pass boost concept |
3393 |
17 Mar 15 |
peter |
// check as a random access iterator. |
4200 |
19 Aug 22 |
peter |
526 |
typedef utility::Container2DIterator<const classifier::KernelLookup, |
2289 |
28 Jun 10 |
peter |
527 |
double, const double> c2dIter; |
3393 |
17 Mar 15 |
peter |
// The workaround in #623 is dirty as it circumvent the fact that |
3393 |
17 Mar 15 |
peter |
// random access iterators are required to return lvalue from |
3393 |
17 Mar 15 |
peter |
// operator*. This is further explained in // |
3393 |
17 Mar 15 |
peter |
// http://www.boost.org/doc/libs/1_57_0/libs/iterator/doc/index.html |
3393 |
17 Mar 15 |
peter |
// and ticket #803. So here we replace the check for C++98 style |
3393 |
17 Mar 15 |
peter |
// random access iterator with boost style readable and |
3393 |
17 Mar 15 |
peter |
// random_access_traversal. |
3393 |
17 Mar 15 |
peter |
//BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<c2dIter>)); |
3393 |
17 Mar 15 |
peter |
536 |
BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<c2dIter>)); |
3393 |
17 Mar 15 |
peter |
537 |
BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<c2dIter>)); |
2289 |
28 Jun 10 |
peter |
538 |
|
2289 |
28 Jun 10 |
peter |
539 |
typedef StrideIterator<c2dIter> StrideIter; |
3393 |
17 Mar 15 |
peter |
540 |
BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<StrideIter>)); |
3393 |
17 Mar 15 |
peter |
541 |
BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<StrideIter>)); |
3393 |
17 Mar 15 |
peter |
542 |
|
3393 |
17 Mar 15 |
peter |
// the minimal requirement for BASE is that BASE is random access traversal |
3499 |
25 May 16 |
peter |
//typedef int value_type; |
3499 |
25 May 16 |
peter |
545 |
typedef boost::sgi_assignable_archetype<> value_type; |
3393 |
17 Mar 15 |
peter |
546 |
typedef boost::iterator_archetypes::readable_iterator_t access_type; |
3393 |
17 Mar 15 |
peter |
547 |
typedef boost::random_access_traversal_tag traversal; |
3393 |
17 Mar 15 |
peter |
548 |
typedef boost::iterator_archetype<value_type, access_type, traversal> Base; |
3393 |
17 Mar 15 |
peter |
549 |
StrideIterator<Base> si; |
3499 |
25 May 16 |
peter |
550 |
test::test_readable_iterator(si); |
3499 |
25 May 16 |
peter |
551 |
test::test_random_access_traversal_iterator(si); |
3499 |
25 May 16 |
peter |
552 |
|
3499 |
25 May 16 |
peter |
553 |
typedef boost::iterator_archetypes::readable_writable_iterator_t access_type2; |
3499 |
25 May 16 |
peter |
554 |
typedef boost::iterator_archetype<value_type, access_type2,traversal> Base2; |
3499 |
25 May 16 |
peter |
555 |
StrideIterator<Base2> si2; |
3499 |
25 May 16 |
peter |
556 |
test::test_readable_iterator(si2); |
3499 |
25 May 16 |
peter |
557 |
test::test_writable_iterator(si2); |
3499 |
25 May 16 |
peter |
558 |
test::test_random_access_traversal_iterator(si2); |
3499 |
25 May 16 |
peter |
559 |
typedef boost::iterator_archetypes::writable_lvalue_iterator_t access_type3; |
3499 |
25 May 16 |
peter |
560 |
typedef boost::iterator_archetype<value_type, access_type3,traversal> Base3; |
3499 |
25 May 16 |
peter |
561 |
StrideIterator<Base3> si3; |
3499 |
25 May 16 |
peter |
562 |
test::test_readable_iterator(si3); |
3499 |
25 May 16 |
peter |
563 |
test::test_lvalue_iterator(si3); |
3499 |
25 May 16 |
peter |
564 |
test::test_random_access_traversal_iterator(si3); |
2202 |
21 Feb 10 |
peter |
565 |
} |
1477 |
04 Sep 08 |
peter |
566 |
} |
1527 |
24 Sep 08 |
peter |
567 |
|
1527 |
24 Sep 08 |
peter |
568 |
void test_weighted_iterator(test::Suite& suite) |
1527 |
24 Sep 08 |
peter |
569 |
{ |
1527 |
24 Sep 08 |
peter |
570 |
std::vector<double> vec(3,1); |
1527 |
24 Sep 08 |
peter |
571 |
typedef std::vector<double>::iterator Iter; |
1537 |
26 Sep 08 |
peter |
572 |
typedef utility::WeightedIterator<Iter, Iter> WIter; |
1537 |
26 Sep 08 |
peter |
573 |
WIter iter(vec.begin(), vec.begin()); |
3459 |
21 Jan 16 |
peter |
//test::test_mutable_iterator(iter); |
1527 |
24 Sep 08 |
peter |
575 |
|
1537 |
26 Sep 08 |
peter |
576 |
utility::DataWeight tmp = *iter; |
1537 |
26 Sep 08 |
peter |
577 |
|
3459 |
21 Jan 16 |
peter |
578 |
suite.test_input_iterator(iter); |
3459 |
21 Jan 16 |
peter |
579 |
suite.test_output_iterator(iter); |
1538 |
27 Sep 08 |
peter |
580 |
std::vector<double> data(vec.size()); |
1538 |
27 Sep 08 |
peter |
581 |
std::vector<double> weight(vec.size()); |
1538 |
27 Sep 08 |
peter |
582 |
WIter iter2(data.begin(), weight.begin()); |
1538 |
27 Sep 08 |
peter |
583 |
utility::DataWeight tmp2(6.89, 0.79); |
1538 |
27 Sep 08 |
peter |
584 |
*iter2 = tmp2; |
1538 |
27 Sep 08 |
peter |
585 |
if (!suite.add(tmp2==*iter2)) |
1538 |
27 Sep 08 |
peter |
586 |
suite.err() << "error: tmp2==*iter2" << std::endl; |
1538 |
27 Sep 08 |
peter |
587 |
utility::DataWeight tmp3(*iter2); |
1538 |
27 Sep 08 |
peter |
588 |
suite.add(suite.equal(tmp3.data(), tmp2.data())); |
1538 |
27 Sep 08 |
peter |
589 |
suite.add(suite.equal(tmp3.weight(), tmp2.weight())); |
1538 |
27 Sep 08 |
peter |
590 |
*iter2 = *iter; |
1538 |
27 Sep 08 |
peter |
591 |
if (!suite.add(*iter2 == *iter)) |
1538 |
27 Sep 08 |
peter |
592 |
suite.err() << "error: *iter2 == *iter\n"; |
1538 |
27 Sep 08 |
peter |
593 |
tmp = *iter2; |
1538 |
27 Sep 08 |
peter |
594 |
suite.add(suite.equal(tmp.data(), 1)); |
1538 |
27 Sep 08 |
peter |
595 |
std::copy(iter, iter+3, iter2); |
1538 |
27 Sep 08 |
peter |
596 |
suite.add(suite.equal(vec.front(), 1)); |
1538 |
27 Sep 08 |
peter |
597 |
suite.add(suite.equal(data.front(), 1)); |
1538 |
27 Sep 08 |
peter |
598 |
|
1538 |
27 Sep 08 |
peter |
599 |
suite.err() << " testing const conversion\n"; |
1538 |
27 Sep 08 |
peter |
600 |
typedef std::vector<double>::const_iterator const_Iter; |
1538 |
27 Sep 08 |
peter |
601 |
typedef utility::WeightedIterator<const_Iter, const_Iter> const_WIter; |
1538 |
27 Sep 08 |
peter |
602 |
const_WIter const_iter(vec.begin(), vec.begin()); |
3459 |
21 Jan 16 |
peter |
603 |
test::test_const_iterator(const_iter); |
1538 |
27 Sep 08 |
peter |
604 |
const_iter = iter; |
3283 |
08 Jul 14 |
peter |
605 |
|
1538 |
27 Sep 08 |
peter |
606 |
suite.err() << " testing assignment between different iterators\n"; |
1538 |
27 Sep 08 |
peter |
607 |
const std::vector<double> const_vec(10, 10.7); |
1538 |
27 Sep 08 |
peter |
608 |
const_WIter const_iter2(const_vec.begin(), const_vec.begin()); |
1538 |
27 Sep 08 |
peter |
609 |
utility::DataWeight tmp4; |
1538 |
27 Sep 08 |
peter |
610 |
tmp4 = *const_iter2; |
1538 |
27 Sep 08 |
peter |
611 |
*iter = *const_iter2; |
1538 |
27 Sep 08 |
peter |
612 |
suite.add(*iter==*const_iter2); |
1538 |
27 Sep 08 |
peter |
613 |
*iter = *const_iter; |
1538 |
27 Sep 08 |
peter |
614 |
suite.add(*iter==*const_iter); |
1538 |
27 Sep 08 |
peter |
615 |
|
1538 |
27 Sep 08 |
peter |
616 |
double x=101; |
1538 |
27 Sep 08 |
peter |
617 |
utility::WeightedIterator<double*, double*> iter_p(&x, &x); |
1538 |
27 Sep 08 |
peter |
618 |
*iter_p = *iter; |
3283 |
08 Jul 14 |
peter |
619 |
suite.add(*iter_p==*iter); |
3059 |
01 Jul 13 |
peter |
620 |
|
3059 |
01 Jul 13 |
peter |
621 |
(*iter_p).data() = 99; |
3059 |
01 Jul 13 |
peter |
622 |
suite.add(suite.equal(99, (*iter_p).data())); |
3059 |
01 Jul 13 |
peter |
623 |
(*iter_p).weight() = 98; |
3059 |
01 Jul 13 |
peter |
624 |
suite.add(suite.equal(98, (*iter_p).weight())); |
3459 |
21 Jan 16 |
peter |
625 |
|
3459 |
21 Jan 16 |
peter |
// avoid running compiler tests |
3459 |
21 Jan 16 |
peter |
627 |
if (false) { |
3459 |
21 Jan 16 |
peter |
628 |
using utility::WeightedIterator; |
3459 |
21 Jan 16 |
peter |
629 |
|
3459 |
21 Jan 16 |
peter |
// const iterators |
3459 |
21 Jan 16 |
peter |
631 |
{ |
3459 |
21 Jan 16 |
peter |
632 |
typedef boost::input_iterator_archetype<double> input_iterator; |
3459 |
21 Jan 16 |
peter |
633 |
WeightedIterator<input_iterator, input_iterator> it1; |
3459 |
21 Jan 16 |
peter |
634 |
test::test_const_iterator(it1); |
3459 |
21 Jan 16 |
peter |
635 |
|
3459 |
21 Jan 16 |
peter |
636 |
typedef boost::forward_iterator_archetype<double> forward_iterator; |
3459 |
21 Jan 16 |
peter |
637 |
WeightedIterator<forward_iterator, forward_iterator> it2; |
3459 |
21 Jan 16 |
peter |
638 |
test::test_const_iterator(it2); |
3459 |
21 Jan 16 |
peter |
639 |
test::test_forward_traversal_iterator(it2); |
3459 |
21 Jan 16 |
peter |
640 |
|
3459 |
21 Jan 16 |
peter |
641 |
typedef boost::bidirectional_iterator_archetype<double> |
3459 |
21 Jan 16 |
peter |
642 |
bidirectional_iterator; |
3459 |
21 Jan 16 |
peter |
643 |
WeightedIterator<bidirectional_iterator, bidirectional_iterator> it3; |
3459 |
21 Jan 16 |
peter |
644 |
test::test_const_iterator(it3); |
3459 |
21 Jan 16 |
peter |
645 |
test::test_bidirectional_traversal_iterator(it3); |
3459 |
21 Jan 16 |
peter |
646 |
|
3459 |
21 Jan 16 |
peter |
647 |
typedef boost::random_access_iterator_archetype<double> |
3459 |
21 Jan 16 |
peter |
648 |
random_access_iterator; |
3459 |
21 Jan 16 |
peter |
649 |
WeightedIterator<random_access_iterator, random_access_iterator> it4; |
3459 |
21 Jan 16 |
peter |
650 |
test::test_const_iterator(it4); |
3459 |
21 Jan 16 |
peter |
651 |
test::test_random_access_traversal_iterator(it4); |
3459 |
21 Jan 16 |
peter |
652 |
} |
3459 |
21 Jan 16 |
peter |
653 |
|
3459 |
21 Jan 16 |
peter |
// mutable iterators |
3459 |
21 Jan 16 |
peter |
655 |
{ |
3459 |
21 Jan 16 |
peter |
656 |
typedef boost::mutable_forward_iterator_archetype<double> forward_iterator; |
3459 |
21 Jan 16 |
peter |
657 |
WeightedIterator<forward_iterator, forward_iterator> it2; |
3459 |
21 Jan 16 |
peter |
658 |
test::test_mutable_iterator(it2); |
3459 |
21 Jan 16 |
peter |
659 |
test::test_forward_traversal_iterator(it2); |
3459 |
21 Jan 16 |
peter |
660 |
|
3459 |
21 Jan 16 |
peter |
661 |
typedef boost::mutable_bidirectional_iterator_archetype<double> |
3459 |
21 Jan 16 |
peter |
662 |
bidirectional_iterator; |
3459 |
21 Jan 16 |
peter |
663 |
WeightedIterator<bidirectional_iterator, bidirectional_iterator> it3; |
3459 |
21 Jan 16 |
peter |
664 |
test::test_mutable_iterator(it3); |
3459 |
21 Jan 16 |
peter |
665 |
test::test_bidirectional_traversal_iterator(it3); |
3459 |
21 Jan 16 |
peter |
666 |
|
3459 |
21 Jan 16 |
peter |
667 |
typedef boost::mutable_random_access_iterator_archetype<double> |
3459 |
21 Jan 16 |
peter |
668 |
random_access_iterator; |
3459 |
21 Jan 16 |
peter |
669 |
WeightedIterator<random_access_iterator, random_access_iterator> it4; |
3459 |
21 Jan 16 |
peter |
670 |
test::test_mutable_iterator(it4); |
3459 |
21 Jan 16 |
peter |
671 |
test::test_random_access_traversal_iterator(it4); |
3459 |
21 Jan 16 |
peter |
672 |
|
3459 |
21 Jan 16 |
peter |
// mixed |
3459 |
21 Jan 16 |
peter |
674 |
WeightedIterator<random_access_iterator, forward_iterator> it5; |
3459 |
21 Jan 16 |
peter |
675 |
test::test_mutable_iterator(it5); |
3459 |
21 Jan 16 |
peter |
676 |
test::test_forward_traversal_iterator(it5); |
3459 |
21 Jan 16 |
peter |
677 |
} |
3459 |
21 Jan 16 |
peter |
678 |
} |
1527 |
24 Sep 08 |
peter |
679 |
} |
1788 |
09 Feb 09 |
peter |
680 |
|
3459 |
21 Jan 16 |
peter |
681 |
|
1788 |
09 Feb 09 |
peter |
682 |
void test_matrix_lookup_iterator(test::Suite& suite) |
1788 |
09 Feb 09 |
peter |
683 |
{ |
1788 |
09 Feb 09 |
peter |
684 |
classifier::MatrixLookup ml(10, 10); |
1877 |
21 Mar 09 |
peter |
685 |
suite.test_random_access_iterator(ml.begin()); |
1788 |
09 Feb 09 |
peter |
686 |
std::vector<double> vec(ml.rows()*ml.columns()); |
1788 |
09 Feb 09 |
peter |
687 |
std::copy(ml.begin(), ml.end(), vec.begin()); |
1788 |
09 Feb 09 |
peter |
688 |
} |
1788 |
09 Feb 09 |
peter |
689 |
|
2068 |
17 Sep 09 |
peter |
690 |
void test_pair_second_iterator(test::Suite& suite) |
2068 |
17 Sep 09 |
peter |
691 |
{ |
2068 |
17 Sep 09 |
peter |
692 |
typedef std::map<std::string, std::string> C; |
2068 |
17 Sep 09 |
peter |
693 |
C person2color; |
2068 |
17 Sep 09 |
peter |
694 |
person2color["me"] = "yellow"; |
2068 |
17 Sep 09 |
peter |
695 |
person2color["you"] = "orange"; |
2068 |
17 Sep 09 |
peter |
696 |
|
2068 |
17 Sep 09 |
peter |
697 |
C::const_iterator cbegin = person2color.begin(); |
2068 |
17 Sep 09 |
peter |
698 |
C::const_iterator cend = person2color.end(); |
2068 |
17 Sep 09 |
peter |
699 |
|
2068 |
17 Sep 09 |
peter |
700 |
std::set<std::string> colors; |
3283 |
08 Jul 14 |
peter |
701 |
colors.insert(utility::pair_second_iterator(cbegin), |
2068 |
17 Sep 09 |
peter |
702 |
utility::pair_second_iterator(cend)); |
2068 |
17 Sep 09 |
peter |
703 |
|
2068 |
17 Sep 09 |
peter |
704 |
suite.test_bidirectional_iterator(utility::pair_second_iterator(cbegin)); |
2068 |
17 Sep 09 |
peter |
705 |
suite.test_bidirectional_iterator(utility::pair_first_iterator(cbegin)); |
2068 |
17 Sep 09 |
peter |
706 |
} |