609 |
30 Aug 06 |
markus |
// $Id$ |
609 |
30 Aug 06 |
markus |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 Peter Johansson |
609 |
30 Aug 06 |
markus |
8 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
10 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
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 |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
15 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
20 |
|
675 |
10 Oct 06 |
jari |
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/>. |
675 |
10 Oct 06 |
jari |
23 |
*/ |
675 |
10 Oct 06 |
jari |
24 |
|
2881 |
18 Nov 12 |
peter |
25 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
26 |
|
1248 |
19 Mar 08 |
peter |
27 |
#include "Suite.h" |
1248 |
19 Mar 08 |
peter |
28 |
|
2209 |
05 Mar 10 |
peter |
29 |
#include "yat/utility/Exception.h" |
1304 |
14 May 08 |
peter |
30 |
#include "yat/utility/Matrix.h" |
676 |
10 Oct 06 |
jari |
31 |
#include "yat/utility/utility.h" |
1491 |
11 Sep 08 |
peter |
32 |
#include "yat/utility/Vector.h" |
1491 |
11 Sep 08 |
peter |
33 |
#include "yat/utility/VectorConstView.h" |
1491 |
11 Sep 08 |
peter |
34 |
#include "yat/utility/sort_index.h" |
1288 |
24 Apr 08 |
peter |
35 |
#include "yat/utility/stl_utility.h" |
675 |
10 Oct 06 |
jari |
36 |
|
2202 |
21 Feb 10 |
peter |
37 |
#include <boost/concept_archetype.hpp> |
3285 |
11 Jul 14 |
peter |
38 |
#include <boost/iterator/iterator_archetypes.hpp> |
2202 |
21 Feb 10 |
peter |
39 |
|
2943 |
04 Jan 13 |
peter |
40 |
#include <cassert> |
2209 |
05 Mar 10 |
peter |
41 |
#include <cerrno> |
609 |
30 Aug 06 |
markus |
42 |
#include <fstream> |
609 |
30 Aug 06 |
markus |
43 |
#include <iostream> |
1966 |
08 May 09 |
peter |
44 |
#include <limits> |
1492 |
12 Sep 08 |
peter |
45 |
#include <list> |
1385 |
22 Jul 08 |
peter |
46 |
#include <map> |
609 |
30 Aug 06 |
markus |
47 |
#include <string> |
1385 |
22 Jul 08 |
peter |
48 |
#include <vector> |
609 |
30 Aug 06 |
markus |
49 |
|
1304 |
14 May 08 |
peter |
50 |
using namespace theplu::yat; |
3507 |
19 Jul 16 |
peter |
51 |
void test_binary_weight(void); |
2209 |
05 Mar 10 |
peter |
52 |
void test_errno_error(test::Suite& suite); |
2209 |
05 Mar 10 |
peter |
53 |
void test_errno_error_func(void); |
2181 |
02 Feb 10 |
peter |
54 |
void test_get_map(test::Suite&); |
2248 |
22 Apr 10 |
peter |
55 |
void test_load(test::Suite&); |
2273 |
15 Jun 10 |
peter |
56 |
void test_load2(test::Suite&); |
1385 |
22 Jul 08 |
peter |
57 |
void test_inverse(test::Suite&); |
1304 |
14 May 08 |
peter |
58 |
|
4102 |
22 Sep 21 |
peter |
59 |
void test_contains(test::Suite& suite); |
2908 |
15 Dec 12 |
peter |
60 |
void test_dirname(test::Suite& suite); |
4102 |
22 Sep 21 |
peter |
61 |
void test_ends_with(test::Suite& suite); |
2908 |
15 Dec 12 |
peter |
62 |
void test_basename(test::Suite& suite); |
2908 |
15 Dec 12 |
peter |
63 |
void test_fnmatch(test::Suite& suite); |
2908 |
15 Dec 12 |
peter |
64 |
bool test_fnmatch(bool, std::string, std::string); |
3803 |
12 May 19 |
peter |
65 |
void test_getcwd(test::Suite& suite); |
3295 |
25 Jul 14 |
peter |
66 |
void test_remove(test::Suite& suite); |
3295 |
25 Jul 14 |
peter |
67 |
void test_rename(test::Suite& suite); |
3098 |
28 Oct 13 |
peter |
68 |
void test_replace(test::Suite& suite); |
4102 |
22 Sep 21 |
peter |
69 |
void test_starts_with(test::Suite& suite); |
3746 |
13 Aug 18 |
peter |
70 |
void test_symlink(test::Suite& suite); |
2908 |
15 Dec 12 |
peter |
71 |
|
1385 |
22 Jul 08 |
peter |
72 |
template<typename InputIterator, typename Key> |
1385 |
22 Jul 08 |
peter |
73 |
void test_inverse_validate(InputIterator first, InputIterator last, |
1385 |
22 Jul 08 |
peter |
74 |
const std::map<Key, std::vector<size_t> >& m, |
1385 |
22 Jul 08 |
peter |
75 |
test::Suite& suite); |
1385 |
22 Jul 08 |
peter |
76 |
template<typename InputIterator, typename Key> |
1385 |
22 Jul 08 |
peter |
77 |
void test_inverse_validate(InputIterator first, |
1385 |
22 Jul 08 |
peter |
78 |
const std::multimap<Key, size_t>& m, |
1385 |
22 Jul 08 |
peter |
79 |
test::Suite& suite); |
1385 |
22 Jul 08 |
peter |
80 |
|
1491 |
11 Sep 08 |
peter |
81 |
void test_sort_index(test::Suite& suite); |
3287 |
12 Jul 14 |
peter |
82 |
void test_sum_weight(test::Suite& suite); |
1966 |
08 May 09 |
peter |
83 |
void test_less_nan(test::Suite& suite); |
2239 |
10 Apr 10 |
peter |
84 |
void test_ptr_compare(test::Suite& suite); |
2274 |
22 Jun 10 |
peter |
85 |
void test_compose_functors(test::Suite& suite); |
2285 |
27 Jun 10 |
peter |
86 |
void test_dereferencer(test::Suite& suite); |
3466 |
10 Feb 16 |
peter |
87 |
void test_ticket842(test::Suite& suite); |
1491 |
11 Sep 08 |
peter |
88 |
|
1248 |
19 Mar 08 |
peter |
89 |
int main(int argc, char* argv[]) |
2673 |
03 Dec 11 |
peter |
90 |
{ |
680 |
11 Oct 06 |
jari |
91 |
using namespace theplu::yat; |
1248 |
19 Mar 08 |
peter |
92 |
test::Suite suite(argc, argv); |
1248 |
19 Mar 08 |
peter |
93 |
suite.err() << "testing utility ... " << std::endl; |
609 |
30 Aug 06 |
markus |
94 |
|
609 |
30 Aug 06 |
markus |
// test float/double |
609 |
30 Aug 06 |
markus |
96 |
std::string s("1.2"); |
1500 |
15 Sep 08 |
peter |
97 |
if (!utility::is<double>(s)){ |
1248 |
19 Mar 08 |
peter |
98 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
99 |
} |
1500 |
15 Sep 08 |
peter |
100 |
else if (!utility::is<float>(s)) { |
1248 |
19 Mar 08 |
peter |
101 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
102 |
} |
1500 |
15 Sep 08 |
peter |
103 |
else if (utility::is<int>(s)) { |
1248 |
19 Mar 08 |
peter |
104 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
105 |
} |
609 |
30 Aug 06 |
markus |
106 |
else if (utility::is_nan(s)) { |
1248 |
19 Mar 08 |
peter |
107 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
108 |
} |
609 |
30 Aug 06 |
markus |
109 |
|
609 |
30 Aug 06 |
markus |
// test int |
609 |
30 Aug 06 |
markus |
111 |
s="23"; |
1500 |
15 Sep 08 |
peter |
112 |
if (!utility::is<double>(s)){ |
1248 |
19 Mar 08 |
peter |
113 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
114 |
} |
1500 |
15 Sep 08 |
peter |
115 |
else if (!utility::is<float>(s)) { |
1248 |
19 Mar 08 |
peter |
116 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
117 |
} |
1500 |
15 Sep 08 |
peter |
118 |
else if (!utility::is<int>(s)) { |
1248 |
19 Mar 08 |
peter |
119 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
120 |
} |
609 |
30 Aug 06 |
markus |
121 |
else if (utility::is_nan(s)) { |
1248 |
19 Mar 08 |
peter |
122 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
123 |
} |
609 |
30 Aug 06 |
markus |
124 |
|
609 |
30 Aug 06 |
markus |
// test nan |
609 |
30 Aug 06 |
markus |
126 |
s=" nAn "; |
1500 |
15 Sep 08 |
peter |
127 |
if (!utility::is<double>(s)){ |
1248 |
19 Mar 08 |
peter |
128 |
suite.add(false); |
1312 |
19 May 08 |
peter |
129 |
suite.err() << "error: " << s << " is a double\n"; |
609 |
30 Aug 06 |
markus |
130 |
} |
1312 |
19 May 08 |
peter |
/* we don't require NaN for float and int |
918 |
30 Sep 07 |
peter |
else if (!utility::is_float(s)) { |
1248 |
19 Mar 08 |
peter |
suite.add(false); |
1312 |
19 May 08 |
peter |
suite.err() << "error: " << s << " is a float\n"; |
609 |
30 Aug 06 |
markus |
135 |
} |
918 |
30 Sep 07 |
peter |
else if (!utility::is_int(s)) { |
1248 |
19 Mar 08 |
peter |
suite.add(false); |
1312 |
19 May 08 |
peter |
suite.err() << "error: " << s << " is a int\n"; |
609 |
30 Aug 06 |
markus |
139 |
} |
1312 |
19 May 08 |
peter |
140 |
*/ |
609 |
30 Aug 06 |
markus |
141 |
else if (!utility::is_nan(s)) { |
1248 |
19 Mar 08 |
peter |
142 |
suite.add(false); |
1312 |
19 May 08 |
peter |
143 |
suite.err() << "error: " << s << " is nan\n"; |
1312 |
19 May 08 |
peter |
144 |
|
609 |
30 Aug 06 |
markus |
145 |
} |
2673 |
03 Dec 11 |
peter |
146 |
|
609 |
30 Aug 06 |
markus |
// testing trailing values |
609 |
30 Aug 06 |
markus |
148 |
s=" 23 23 "; |
1500 |
15 Sep 08 |
peter |
149 |
if (utility::is<double>(s)){ |
1248 |
19 Mar 08 |
peter |
150 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
151 |
} |
1500 |
15 Sep 08 |
peter |
152 |
else if (utility::is<float>(s)) { |
1248 |
19 Mar 08 |
peter |
153 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
154 |
} |
1500 |
15 Sep 08 |
peter |
155 |
else if (utility::is<int>(s)) { |
1248 |
19 Mar 08 |
peter |
156 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
157 |
} |
609 |
30 Aug 06 |
markus |
158 |
else if (utility::is_nan(s)) { |
1248 |
19 Mar 08 |
peter |
159 |
suite.add(false); |
609 |
30 Aug 06 |
markus |
160 |
} |
609 |
30 Aug 06 |
markus |
161 |
|
1195 |
29 Feb 08 |
peter |
162 |
if (utility::convert<double>("1.23")!=1.23) |
1248 |
19 Mar 08 |
peter |
163 |
suite.add(false); |
1195 |
29 Feb 08 |
peter |
164 |
utility::convert<double>("-inf"); |
1195 |
29 Feb 08 |
peter |
165 |
utility::convert<double>("inf"); |
1195 |
29 Feb 08 |
peter |
166 |
utility::convert<double>("NaN"); |
3177 |
15 Mar 14 |
peter |
167 |
utility::convert<double>("-NaN"); |
3177 |
15 Mar 14 |
peter |
168 |
utility::convert<double>(" -NaN"); |
609 |
30 Aug 06 |
markus |
169 |
|
2426 |
13 Feb 11 |
peter |
170 |
suite.add(utility::convert(1.23)=="1.23"); |
2426 |
13 Feb 11 |
peter |
171 |
suite.add(utility::convert(1)=="1"); |
2426 |
13 Feb 11 |
peter |
172 |
|
2673 |
03 Dec 11 |
peter |
173 |
suite.add(utility::is<unsigned int>("1")); |
2673 |
03 Dec 11 |
peter |
174 |
suite.add(!utility::is<unsigned int>(" ")); |
2673 |
03 Dec 11 |
peter |
175 |
suite.add(!utility::is<unsigned int>(" -1")); |
2673 |
03 Dec 11 |
peter |
// test -1 cannot be assigned to unsigned int |
2673 |
03 Dec 11 |
peter |
177 |
try { |
2673 |
03 Dec 11 |
peter |
178 |
unsigned int x = utility::convert<unsigned int>("-1"); |
2673 |
03 Dec 11 |
peter |
179 |
suite.err() << "convert<unsigned>(\"-1\") did not throw\n"; |
2673 |
03 Dec 11 |
peter |
180 |
suite.err() << "x: " << x << "\n"; |
2673 |
03 Dec 11 |
peter |
181 |
suite.add(false); |
2673 |
03 Dec 11 |
peter |
182 |
exit(1); |
2673 |
03 Dec 11 |
peter |
183 |
} |
2673 |
03 Dec 11 |
peter |
184 |
catch (std::runtime_error& e) { |
2673 |
03 Dec 11 |
peter |
185 |
suite.out() << "expected error: " << e.what() << "\n"; |
2673 |
03 Dec 11 |
peter |
186 |
} |
3597 |
22 Jan 17 |
peter |
187 |
double result; |
3597 |
22 Jan 17 |
peter |
188 |
if (!suite.add(utility::convert_try<double>("3.14", result))) |
3597 |
22 Jan 17 |
peter |
189 |
suite.err() << "convert_tr<double>(\"3.14\", ...) failed\n"; |
3597 |
22 Jan 17 |
peter |
190 |
if (!suite.add(!utility::convert_try<double>("3.14xx", result))) |
3597 |
22 Jan 17 |
peter |
191 |
suite.err() << "convert_tr<double>(\"3.14xx\", ...) succeeded\n"; |
2673 |
03 Dec 11 |
peter |
192 |
|
1312 |
19 May 08 |
peter |
193 |
if (!suite.add(utility::is<double>("-inf"))) |
1312 |
19 May 08 |
peter |
194 |
suite.err() << "is<double>(\"-inf\") should return true\n"; |
1312 |
19 May 08 |
peter |
195 |
if (!suite.add(utility::is<double>("inf"))) |
1312 |
19 May 08 |
peter |
196 |
suite.err() << "is<double>(\"inf\") should return true\n"; |
1312 |
19 May 08 |
peter |
197 |
if (!suite.add(utility::is<double>("NaN"))) |
1312 |
19 May 08 |
peter |
198 |
suite.err() << "is<double>(\"NaN\") should return true\n"; |
1312 |
19 May 08 |
peter |
199 |
if (!suite.add(utility::is<double>("1.23"))) |
1312 |
19 May 08 |
peter |
200 |
suite.err() << "is<double>(\"1.23\") should return true\n"; |
1312 |
19 May 08 |
peter |
201 |
if (!suite.add(!utility::is<double>("1.23.2"))) |
1312 |
19 May 08 |
peter |
202 |
suite.err() << "is<double>(\"1.23.2\") should return false\n"; |
1312 |
19 May 08 |
peter |
203 |
if (!suite.add(!utility::is<int>("1.23"))) |
1313 |
19 May 08 |
peter |
204 |
suite.err() << "is<int>(\"1.23\") should return false\n"; |
1313 |
19 May 08 |
peter |
205 |
if (!suite.add(!utility::is<int>(""))) |
1313 |
19 May 08 |
peter |
206 |
suite.err() << "is<int>(\"\") should return false\n"; |
1312 |
19 May 08 |
peter |
207 |
|
1288 |
24 Apr 08 |
peter |
208 |
{ |
1289 |
26 Apr 08 |
peter |
209 |
utility::Log<long double> f; |
1289 |
26 Apr 08 |
peter |
210 |
utility::Log<double> f2(1.3); |
1288 |
24 Apr 08 |
peter |
211 |
f(2.0); |
1289 |
26 Apr 08 |
peter |
212 |
utility::Exp<double> e; |
1288 |
24 Apr 08 |
peter |
213 |
e(3.2); |
1288 |
24 Apr 08 |
peter |
214 |
} |
1288 |
24 Apr 08 |
peter |
215 |
|
2181 |
02 Feb 10 |
peter |
216 |
test_get_map(suite); |
1385 |
22 Jul 08 |
peter |
217 |
test_inverse(suite); |
1491 |
11 Sep 08 |
peter |
218 |
test_sort_index(suite); |
3287 |
12 Jul 14 |
peter |
219 |
test_sum_weight(suite); |
1966 |
08 May 09 |
peter |
220 |
test_less_nan(suite); |
2209 |
05 Mar 10 |
peter |
221 |
test_errno_error(suite); |
2239 |
10 Apr 10 |
peter |
222 |
test_ptr_compare(suite); |
2248 |
22 Apr 10 |
peter |
223 |
test_load(suite); |
2273 |
15 Jun 10 |
peter |
224 |
test_load2(suite); |
1304 |
14 May 08 |
peter |
225 |
|
2274 |
22 Jun 10 |
peter |
226 |
test_compose_functors(suite); |
2274 |
22 Jun 10 |
peter |
227 |
|
2867 |
12 Nov 12 |
peter |
228 |
double x = 8.0; |
2867 |
12 Nov 12 |
peter |
229 |
suite.add(suite.equal(utility::log2(x), 3.0)); |
2867 |
12 Nov 12 |
peter |
230 |
float xf = x; |
2867 |
12 Nov 12 |
peter |
231 |
suite.add(suite.equal(utility::log2(xf), 3.0)); |
2867 |
12 Nov 12 |
peter |
232 |
long double xld = 8.0; |
2867 |
12 Nov 12 |
peter |
233 |
suite.add(suite.equal(utility::log2(xld), 3.0)); |
2867 |
12 Nov 12 |
peter |
234 |
|
3404 |
03 Apr 15 |
peter |
235 |
std::vector<std::string> vec(1, "text"); |
3404 |
03 Apr 15 |
peter |
236 |
utility::clear(vec); |
3404 |
03 Apr 15 |
peter |
237 |
suite.add(vec.size()==0); |
3404 |
03 Apr 15 |
peter |
238 |
|
2908 |
15 Dec 12 |
peter |
239 |
test_basename(suite); |
3507 |
19 Jul 16 |
peter |
240 |
test_binary_weight(); |
2908 |
15 Dec 12 |
peter |
241 |
test_dirname(suite); |
2908 |
15 Dec 12 |
peter |
242 |
test_fnmatch(suite); |
3803 |
12 May 19 |
peter |
243 |
test_getcwd(suite); |
3295 |
25 Jul 14 |
peter |
244 |
test_remove(suite); |
3295 |
25 Jul 14 |
peter |
245 |
test_rename(suite); |
3098 |
28 Oct 13 |
peter |
246 |
test_replace(suite); |
3746 |
13 Aug 18 |
peter |
247 |
test_symlink(suite); |
3466 |
10 Feb 16 |
peter |
248 |
test_ticket842(suite); |
4102 |
22 Sep 21 |
peter |
249 |
test_starts_with(suite); |
4102 |
22 Sep 21 |
peter |
250 |
test_contains(suite); |
4102 |
22 Sep 21 |
peter |
251 |
test_ends_with(suite); |
2908 |
15 Dec 12 |
peter |
252 |
|
1248 |
19 Mar 08 |
peter |
253 |
return suite.return_value(); |
609 |
30 Aug 06 |
markus |
254 |
} |
1304 |
14 May 08 |
peter |
255 |
|
1385 |
22 Jul 08 |
peter |
256 |
|
3507 |
19 Jul 16 |
peter |
257 |
void test_binary_weight(void) |
3507 |
19 Jul 16 |
peter |
258 |
{ |
3507 |
19 Jul 16 |
peter |
// do not run compilation test |
3507 |
19 Jul 16 |
peter |
260 |
return; |
3507 |
19 Jul 16 |
peter |
// this does not work, see ticket #865 |
3507 |
19 Jul 16 |
peter |
// boost::input_iterator_archetype<double> in; |
3507 |
19 Jul 16 |
peter |
263 |
boost::input_iterator_archetype_no_proxy<double> in; |
3507 |
19 Jul 16 |
peter |
264 |
boost::detail::dummy_constructor arg; |
3507 |
19 Jul 16 |
peter |
265 |
boost::output_iterator_archetype<double> out(arg); |
3507 |
19 Jul 16 |
peter |
266 |
utility::binary_weight(in, in, out); |
3507 |
19 Jul 16 |
peter |
267 |
} |
3507 |
19 Jul 16 |
peter |
268 |
|
3507 |
19 Jul 16 |
peter |
269 |
|
2209 |
05 Mar 10 |
peter |
270 |
void test_errno_error_func(void) |
2209 |
05 Mar 10 |
peter |
271 |
{ |
2209 |
05 Mar 10 |
peter |
272 |
errno=1; |
2209 |
05 Mar 10 |
peter |
273 |
throw utility::errno_error(""); |
2209 |
05 Mar 10 |
peter |
274 |
} |
2209 |
05 Mar 10 |
peter |
275 |
|
2209 |
05 Mar 10 |
peter |
276 |
|
2209 |
05 Mar 10 |
peter |
277 |
void test_errno_error(test::Suite& suite) |
2209 |
05 Mar 10 |
peter |
278 |
{ |
2209 |
05 Mar 10 |
peter |
279 |
suite.out() << "testing errno_error\n"; |
2209 |
05 Mar 10 |
peter |
280 |
try { |
2209 |
05 Mar 10 |
peter |
281 |
test_errno_error_func(); |
2209 |
05 Mar 10 |
peter |
282 |
} |
2209 |
05 Mar 10 |
peter |
283 |
catch ( utility::errno_error& e) { |
2209 |
05 Mar 10 |
peter |
284 |
suite.out() << "catching expected exception with what():\n"; |
2209 |
05 Mar 10 |
peter |
285 |
suite.out() << e.what() << "\n"; |
2209 |
05 Mar 10 |
peter |
286 |
return; |
2209 |
05 Mar 10 |
peter |
287 |
} |
2209 |
05 Mar 10 |
peter |
288 |
suite.err() << "error: expected thrown exception\n"; |
2209 |
05 Mar 10 |
peter |
289 |
suite.add(false); |
2209 |
05 Mar 10 |
peter |
290 |
} |
2209 |
05 Mar 10 |
peter |
291 |
|
2209 |
05 Mar 10 |
peter |
292 |
|
2274 |
22 Jun 10 |
peter |
293 |
void test_compose_functors(test::Suite& suite) |
2274 |
22 Jun 10 |
peter |
294 |
{ |
2274 |
22 Jun 10 |
peter |
295 |
typedef utility::abs<double> U1; |
2274 |
22 Jun 10 |
peter |
// we use float here to check conversion from float to double in functors |
2274 |
22 Jun 10 |
peter |
297 |
typedef utility::Exp<float> U2; |
2274 |
22 Jun 10 |
peter |
298 |
typedef std::plus<double> B; |
2274 |
22 Jun 10 |
peter |
299 |
U1 u1; |
2274 |
22 Jun 10 |
peter |
300 |
U2 u2; |
2274 |
22 Jun 10 |
peter |
301 |
B b; |
2274 |
22 Jun 10 |
peter |
302 |
|
2963 |
21 Jan 13 |
peter |
303 |
utility::compose_f_gx_hy<B, U1, U2> binary; |
2963 |
21 Jan 13 |
peter |
304 |
binary = utility::make_compose_f_gx_hy(b, u1, u2); |
2274 |
22 Jun 10 |
peter |
305 |
|
2963 |
21 Jan 13 |
peter |
306 |
utility::compose_f_gxy<U2, B> binary2; |
2963 |
21 Jan 13 |
peter |
307 |
binary2 = utility::make_compose_f_gxy(u2, b); |
2274 |
22 Jun 10 |
peter |
308 |
|
2963 |
21 Jan 13 |
peter |
309 |
utility::compose_f_gx<U1, U2> unary; |
2963 |
21 Jan 13 |
peter |
310 |
unary = utility::make_compose_f_gx(u1, u2); |
3082 |
18 Sep 13 |
peter |
311 |
|
3082 |
18 Sep 13 |
peter |
312 |
utility::compose_f_gx_hx<B, U1, U2> unary2; |
3082 |
18 Sep 13 |
peter |
313 |
unary2 = utility::make_compose_f_gx_hx(b, u1, u2); |
3082 |
18 Sep 13 |
peter |
314 |
if (!suite.add(suite.equal_fix(unary2(-2.0), 2.0 + std::exp(-2.0),1e-8))) |
3082 |
18 Sep 13 |
peter |
315 |
suite.err() << "compose_f_gx_hx failed\n"; |
2274 |
22 Jun 10 |
peter |
316 |
} |
2274 |
22 Jun 10 |
peter |
317 |
|
2274 |
22 Jun 10 |
peter |
318 |
|
2285 |
27 Jun 10 |
peter |
319 |
void test_dereferencer(test::Suite& suite) |
2285 |
27 Jun 10 |
peter |
320 |
{ |
2285 |
27 Jun 10 |
peter |
321 |
using utility::Dereferencer; |
2285 |
27 Jun 10 |
peter |
322 |
Dereferencer<double*> deref; |
2285 |
27 Jun 10 |
peter |
323 |
double x = 0; |
2285 |
27 Jun 10 |
peter |
324 |
double* px = &x; |
2285 |
27 Jun 10 |
peter |
325 |
deref(px) = 1.662; |
2285 |
27 Jun 10 |
peter |
326 |
if (!suite.add(x==1.662)) { |
2285 |
27 Jun 10 |
peter |
327 |
suite.out() << "test_dereferencer failed: x: " << x << "\n"; |
2285 |
27 Jun 10 |
peter |
328 |
} |
2285 |
27 Jun 10 |
peter |
329 |
} |
2274 |
22 Jun 10 |
peter |
330 |
|
2285 |
27 Jun 10 |
peter |
331 |
|
2181 |
02 Feb 10 |
peter |
332 |
void test_get_map(test::Suite& suite) |
2181 |
02 Feb 10 |
peter |
333 |
{ |
2181 |
02 Feb 10 |
peter |
334 |
std::map<std::string, int> m; |
2181 |
02 Feb 10 |
peter |
335 |
m["one"] = 1; |
2181 |
02 Feb 10 |
peter |
336 |
m["two"] = 2; |
2181 |
02 Feb 10 |
peter |
337 |
const std::map<std::string, int> m2(m); |
2181 |
02 Feb 10 |
peter |
338 |
int i = utility::get(m2, static_cast<std::string>("one")); |
3322 |
06 Oct 14 |
peter |
339 |
test::avoid_compiler_warning(i); // avoid compiler warning |
2181 |
02 Feb 10 |
peter |
340 |
try { |
2181 |
02 Feb 10 |
peter |
341 |
utility::get(m2, static_cast<std::string>("three")); |
2181 |
02 Feb 10 |
peter |
342 |
suite.add(false); |
2181 |
02 Feb 10 |
peter |
343 |
} |
2181 |
02 Feb 10 |
peter |
344 |
catch (std::runtime_error& e) { |
2673 |
03 Dec 11 |
peter |
345 |
suite.out() << "expected exception thrown with what() = " |
2181 |
02 Feb 10 |
peter |
346 |
<< e.what() << "\n"; |
2181 |
02 Feb 10 |
peter |
347 |
} |
3254 |
09 Jun 14 |
peter |
// test ticket #799 |
3254 |
09 Jun 14 |
peter |
349 |
if (!suite.add(utility::get(m, "one")==1)) |
3254 |
09 Jun 14 |
peter |
350 |
suite.err() << "get(m, \"one\")!=1\n"; |
3254 |
09 Jun 14 |
peter |
351 |
|
3253 |
07 Jun 14 |
peter |
// don't run compiler test code |
3253 |
07 Jun 14 |
peter |
353 |
if (false) { |
3253 |
07 Jun 14 |
peter |
354 |
typedef boost::default_constructible_archetype< |
3253 |
07 Jun 14 |
peter |
355 |
boost::sgi_assignable_archetype<> > key_type; |
3253 |
07 Jun 14 |
peter |
356 |
|
3253 |
07 Jun 14 |
peter |
357 |
typedef boost::default_constructible_archetype< |
3253 |
07 Jun 14 |
peter |
358 |
boost::sgi_assignable_archetype< |
3253 |
07 Jun 14 |
peter |
359 |
boost::null_archetype<std::string> > > value_type; |
3253 |
07 Jun 14 |
peter |
360 |
|
3253 |
07 Jun 14 |
peter |
361 |
typedef boost::default_constructible_archetype< |
3253 |
07 Jun 14 |
peter |
362 |
boost::binary_function_archetype<key_type, key_type, bool> > Compare; |
3253 |
07 Jun 14 |
peter |
363 |
|
3253 |
07 Jun 14 |
peter |
364 |
std::map<key_type, value_type, Compare> m3; |
3254 |
09 Jun 14 |
peter |
365 |
|
3254 |
09 Jun 14 |
peter |
// create an object that is convertible to key_type |
3254 |
09 Jun 14 |
peter |
367 |
boost::detail::dummy_constructor x; |
3254 |
09 Jun 14 |
peter |
368 |
boost::convertible_to_archetype<key_type> my_key(x); |
3253 |
07 Jun 14 |
peter |
369 |
utility::get(m3, my_key); |
3253 |
07 Jun 14 |
peter |
370 |
} |
2181 |
02 Feb 10 |
peter |
371 |
} |
2181 |
02 Feb 10 |
peter |
372 |
|
1966 |
08 May 09 |
peter |
373 |
void test_less_nan(test::Suite& suite) |
1966 |
08 May 09 |
peter |
374 |
{ |
2273 |
15 Jun 10 |
peter |
375 |
suite.out() << "test less_nan\n"; |
1966 |
08 May 09 |
peter |
376 |
bool prior_ok=suite.ok(); |
1966 |
08 May 09 |
peter |
377 |
utility::less_nan<double> f; |
1966 |
08 May 09 |
peter |
378 |
suite.add(f(2.7,3.14)); |
1966 |
08 May 09 |
peter |
379 |
suite.add(!f(2.7,-3.14)); |
1966 |
08 May 09 |
peter |
380 |
suite.add(!f(2.7,2.7)); |
1966 |
08 May 09 |
peter |
381 |
suite.add(f(3.14, std::numeric_limits<double>::quiet_NaN())); |
1966 |
08 May 09 |
peter |
382 |
suite.add(!f(std::numeric_limits<double>::quiet_NaN(), 2.7)); |
1966 |
08 May 09 |
peter |
383 |
suite.add(!f(std::numeric_limits<double>::quiet_NaN(), |
1966 |
08 May 09 |
peter |
384 |
std::numeric_limits<double>::quiet_NaN())); |
1970 |
11 May 09 |
peter |
385 |
utility::less_nan<utility::DataWeight> fw; |
1972 |
12 May 09 |
peter |
386 |
suite.add(fw(utility::DataWeight(2), utility::DataWeight(3))); |
1970 |
11 May 09 |
peter |
387 |
|
1966 |
08 May 09 |
peter |
388 |
bool post_ok=suite.ok(); |
1966 |
08 May 09 |
peter |
389 |
if (!post_ok && prior_ok) |
1966 |
08 May 09 |
peter |
390 |
suite.err() << "test_less_nan failed\n"; |
1966 |
08 May 09 |
peter |
391 |
} |
1966 |
08 May 09 |
peter |
392 |
|
1966 |
08 May 09 |
peter |
393 |
|
2248 |
22 Apr 10 |
peter |
394 |
void test_load(test::Suite& suite) |
2248 |
22 Apr 10 |
peter |
395 |
{ |
2248 |
22 Apr 10 |
peter |
396 |
std::istringstream iss(std::string("1.69 3.14")); |
2248 |
22 Apr 10 |
peter |
397 |
std::vector<double> double_vec; |
2248 |
22 Apr 10 |
peter |
398 |
utility::load(iss, double_vec); |
2248 |
22 Apr 10 |
peter |
399 |
suite.add(double_vec.size()==2); |
2248 |
22 Apr 10 |
peter |
400 |
|
2248 |
22 Apr 10 |
peter |
401 |
std::istringstream iss2(std::string("1 2")); |
2248 |
22 Apr 10 |
peter |
402 |
std::vector<double> uint_vec; |
2248 |
22 Apr 10 |
peter |
403 |
utility::load(iss2, uint_vec); |
2248 |
22 Apr 10 |
peter |
404 |
suite.add(uint_vec.size()==2); |
2248 |
22 Apr 10 |
peter |
405 |
|
2248 |
22 Apr 10 |
peter |
406 |
std::istringstream iss3(std::string("1.69 3.14")); |
2248 |
22 Apr 10 |
peter |
407 |
std::vector<std::string> str_vec; |
2248 |
22 Apr 10 |
peter |
408 |
utility::load(iss3, str_vec); |
2248 |
22 Apr 10 |
peter |
409 |
if (str_vec.size()==2) { |
2248 |
22 Apr 10 |
peter |
410 |
if (str_vec[1]!="3.14") { |
2248 |
22 Apr 10 |
peter |
411 |
suite.out() << "error: load<string>:" << "\n" |
2248 |
22 Apr 10 |
peter |
412 |
<< " str_vec[1] = " << str_vec[1] << "\n" |
2248 |
22 Apr 10 |
peter |
413 |
<< " expected: 3.14n"; |
2248 |
22 Apr 10 |
peter |
414 |
suite.add(false); |
2248 |
22 Apr 10 |
peter |
415 |
} |
2248 |
22 Apr 10 |
peter |
416 |
} |
2248 |
22 Apr 10 |
peter |
417 |
else { |
2248 |
22 Apr 10 |
peter |
418 |
suite.out() << "str_vec.size() is not 2\n"; |
2248 |
22 Apr 10 |
peter |
419 |
suite.add(false); |
2248 |
22 Apr 10 |
peter |
420 |
} |
2248 |
22 Apr 10 |
peter |
421 |
} |
2248 |
22 Apr 10 |
peter |
422 |
|
2248 |
22 Apr 10 |
peter |
423 |
|
2273 |
15 Jun 10 |
peter |
424 |
void test_load2(test::Suite& suite) |
2273 |
15 Jun 10 |
peter |
425 |
{ |
2273 |
15 Jun 10 |
peter |
426 |
suite.out() << "test load<double>(matrix)\n"; |
2273 |
15 Jun 10 |
peter |
427 |
std::string str("1.69 3.14\n1.23 1.22\n"); |
2273 |
15 Jun 10 |
peter |
428 |
std::istringstream iss(str); |
2273 |
15 Jun 10 |
peter |
429 |
std::vector<std::vector<double> > double_m; |
2673 |
03 Dec 11 |
peter |
430 |
utility::load(iss, double_m, '\0', '\n'); |
2273 |
15 Jun 10 |
peter |
431 |
suite.add(double_m.size()==2); |
2273 |
15 Jun 10 |
peter |
432 |
|
2273 |
15 Jun 10 |
peter |
433 |
suite.out() << "test load<std::string>(matrix)\n"; |
2273 |
15 Jun 10 |
peter |
434 |
suite.out() << str; |
2273 |
15 Jun 10 |
peter |
435 |
std::istringstream iss2(str); |
2273 |
15 Jun 10 |
peter |
436 |
std::vector<std::vector<std::string> > str_m; |
2673 |
03 Dec 11 |
peter |
437 |
utility::load(iss2, str_m, '\0', '\n'); |
2273 |
15 Jun 10 |
peter |
438 |
std::cout << str_m.size() << std::endl; |
2273 |
15 Jun 10 |
peter |
439 |
for (size_t i=0; i<str_m.size(); ++i) |
2273 |
15 Jun 10 |
peter |
440 |
for (size_t j=0; j<str_m[i].size(); ++j) |
2273 |
15 Jun 10 |
peter |
441 |
suite.out() << str_m[i][j] << "\n"; |
2273 |
15 Jun 10 |
peter |
442 |
suite.add(str_m.size()==2); |
2273 |
15 Jun 10 |
peter |
443 |
} |
2273 |
15 Jun 10 |
peter |
444 |
|
2273 |
15 Jun 10 |
peter |
445 |
|
1385 |
22 Jul 08 |
peter |
446 |
void test_inverse(test::Suite& suite) |
1385 |
22 Jul 08 |
peter |
447 |
{ |
1385 |
22 Jul 08 |
peter |
448 |
suite.err() << "Testing inverse\n"; |
1385 |
22 Jul 08 |
peter |
449 |
std::vector<std::string> vec; |
1385 |
22 Jul 08 |
peter |
450 |
vec.push_back("No"); |
1385 |
22 Jul 08 |
peter |
451 |
vec.push_back("one"); |
1385 |
22 Jul 08 |
peter |
452 |
vec.push_back("shall"); |
1385 |
22 Jul 08 |
peter |
453 |
vec.push_back("be"); |
1385 |
22 Jul 08 |
peter |
454 |
vec.push_back("subjected"); |
1385 |
22 Jul 08 |
peter |
455 |
std::map<std::string, std::vector<size_t> > map; |
1385 |
22 Jul 08 |
peter |
456 |
utility::inverse(vec.begin(), vec.end(), map); |
1385 |
22 Jul 08 |
peter |
457 |
test_inverse_validate(vec.begin(), vec.end(), map, suite); |
1385 |
22 Jul 08 |
peter |
458 |
utility::inverse(vec.begin()+1, vec.end(), map); |
1385 |
22 Jul 08 |
peter |
459 |
test_inverse_validate(vec.begin()+1, vec.end(), map, suite); |
1385 |
22 Jul 08 |
peter |
460 |
const std::vector<std::string> vec2(vec); |
1385 |
22 Jul 08 |
peter |
461 |
utility::inverse(vec2.begin(), vec2.end(), map); |
1385 |
22 Jul 08 |
peter |
462 |
test_inverse_validate(vec2.begin(), vec2.end(), map, suite); |
1385 |
22 Jul 08 |
peter |
463 |
std::multimap<std::string, size_t> mmap; |
1385 |
22 Jul 08 |
peter |
464 |
utility::inverse(vec.begin(), vec.end(), mmap); |
1385 |
22 Jul 08 |
peter |
465 |
test_inverse_validate(vec.begin(), mmap, suite); |
1385 |
22 Jul 08 |
peter |
466 |
utility::inverse(vec.begin()+1, vec.end(), mmap); |
1385 |
22 Jul 08 |
peter |
467 |
test_inverse_validate(vec.begin()+1, mmap, suite); |
2202 |
21 Feb 10 |
peter |
// do not run compile tests |
2202 |
21 Feb 10 |
peter |
469 |
if (false) { |
2202 |
21 Feb 10 |
peter |
470 |
std::map<std::string, std::vector<size_t> > m; |
2202 |
21 Feb 10 |
peter |
471 |
boost::input_iterator_archetype<std::string> start; |
2202 |
21 Feb 10 |
peter |
472 |
boost::input_iterator_archetype<std::string> end; |
2202 |
21 Feb 10 |
peter |
473 |
utility::inverse(start, end, m); |
2202 |
21 Feb 10 |
peter |
474 |
std::map<std::string, std::vector<size_t>, std::greater<std::string> > m2; |
2202 |
21 Feb 10 |
peter |
475 |
utility::inverse(start, end, m2); |
2202 |
21 Feb 10 |
peter |
476 |
std::multimap<std::string, size_t> m3; |
2202 |
21 Feb 10 |
peter |
477 |
utility::inverse(start, end, m3); |
2202 |
21 Feb 10 |
peter |
478 |
std::multimap<std::string, size_t, std::greater<std::string> > m4; |
2202 |
21 Feb 10 |
peter |
479 |
utility::inverse(start, end, m4); |
2857 |
27 Sep 12 |
peter |
480 |
|
2857 |
27 Sep 12 |
peter |
481 |
std::map<std::string, size_t> unique_map; |
2857 |
27 Sep 12 |
peter |
482 |
utility::inverse(start, end, unique_map); |
2202 |
21 Feb 10 |
peter |
483 |
} |
1385 |
22 Jul 08 |
peter |
484 |
} |
1385 |
22 Jul 08 |
peter |
485 |
|
1385 |
22 Jul 08 |
peter |
486 |
|
1385 |
22 Jul 08 |
peter |
487 |
template<typename InputIterator, typename Key> |
1385 |
22 Jul 08 |
peter |
488 |
void test_inverse_validate(InputIterator first, InputIterator last, |
1385 |
22 Jul 08 |
peter |
489 |
const std::map<Key, std::vector<size_t> >& m, |
1385 |
22 Jul 08 |
peter |
490 |
test::Suite& suite) |
1385 |
22 Jul 08 |
peter |
491 |
{ |
1385 |
22 Jul 08 |
peter |
492 |
typedef typename std::map<Key, std::vector<size_t> >::const_iterator Iter; |
1385 |
22 Jul 08 |
peter |
493 |
for ( InputIterator iter=first; iter != last; ++iter) { |
1385 |
22 Jul 08 |
peter |
494 |
Iter map_iter = m.find(*iter); |
1385 |
22 Jul 08 |
peter |
495 |
if (!suite.add(map_iter!=m.end())) { |
1385 |
22 Jul 08 |
peter |
496 |
suite.err() << "test_inverse_validate() failed\n"; |
1385 |
22 Jul 08 |
peter |
497 |
suite.err() << " could not find: " << *first << " in map m\n"; |
1385 |
22 Jul 08 |
peter |
498 |
} |
1385 |
22 Jul 08 |
peter |
499 |
for (size_t i=0; i<map_iter->second.size(); ++i) |
1385 |
22 Jul 08 |
peter |
500 |
if (!suite.add(map_iter->second[i] == |
1385 |
22 Jul 08 |
peter |
501 |
static_cast<size_t>(distance(first, iter))) ) { |
1385 |
22 Jul 08 |
peter |
502 |
suite.err() << "test_inverse_validate() failed\n"; |
2673 |
03 Dec 11 |
peter |
503 |
suite.err() << " comparing: " << map_iter->second[i] |
2673 |
03 Dec 11 |
peter |
504 |
<< " and " << distance(first, iter) |
1385 |
22 Jul 08 |
peter |
505 |
<< " expected them to be equal\n"; |
1385 |
22 Jul 08 |
peter |
506 |
} |
1385 |
22 Jul 08 |
peter |
507 |
} |
1385 |
22 Jul 08 |
peter |
508 |
} |
1385 |
22 Jul 08 |
peter |
509 |
|
1385 |
22 Jul 08 |
peter |
510 |
|
1385 |
22 Jul 08 |
peter |
511 |
template<typename InputIterator, typename Key> |
1385 |
22 Jul 08 |
peter |
512 |
void test_inverse_validate(InputIterator first, |
1385 |
22 Jul 08 |
peter |
513 |
const std::multimap<Key, size_t>& m, |
1385 |
22 Jul 08 |
peter |
514 |
test::Suite& suite) |
1385 |
22 Jul 08 |
peter |
515 |
{ |
1385 |
22 Jul 08 |
peter |
516 |
for (typename std::multimap<Key, size_t>::const_iterator iter=m.begin(); |
1385 |
22 Jul 08 |
peter |
517 |
iter!=m.end(); ++iter) { |
1385 |
22 Jul 08 |
peter |
518 |
suite.add(*(first + iter->second) == iter->first); |
1385 |
22 Jul 08 |
peter |
519 |
} |
2673 |
03 Dec 11 |
peter |
520 |
|
1385 |
22 Jul 08 |
peter |
521 |
} |
1491 |
11 Sep 08 |
peter |
522 |
|
3490 |
22 May 16 |
peter |
523 |
|
3490 |
22 May 16 |
peter |
524 |
template<typename Access, typename Traversal> |
3490 |
22 May 16 |
peter |
525 |
void test_sort_index2(Access access, Traversal traversal) |
3490 |
22 May 16 |
peter |
526 |
{ |
3490 |
22 May 16 |
peter |
527 |
typedef boost::default_constructible_archetype< |
3490 |
22 May 16 |
peter |
528 |
boost::sgi_assignable_archetype< |
3490 |
22 May 16 |
peter |
529 |
boost::less_than_comparable_archetype<> > > Value; |
3490 |
22 May 16 |
peter |
530 |
boost::iterator_archetype<Value, Access, Traversal> iterator; |
3490 |
22 May 16 |
peter |
531 |
std::vector<size_t> index; |
3490 |
22 May 16 |
peter |
532 |
utility::sort_index(iterator, iterator, index); |
3490 |
22 May 16 |
peter |
533 |
|
3490 |
22 May 16 |
peter |
534 |
typedef boost::default_constructible_archetype< |
3490 |
22 May 16 |
peter |
535 |
boost::sgi_assignable_archetype<> > Value2; |
3490 |
22 May 16 |
peter |
536 |
boost::iterator_archetype<Value2, Access, Traversal> iterator2; |
3490 |
22 May 16 |
peter |
537 |
typedef boost::default_constructible_archetype< |
3490 |
22 May 16 |
peter |
538 |
boost::binary_predicate_archetype<Value2, Value2> |
3490 |
22 May 16 |
peter |
539 |
> Compare; |
3490 |
22 May 16 |
peter |
540 |
Compare comp; |
3490 |
22 May 16 |
peter |
541 |
utility::sort_index(iterator2, iterator2, index, comp); |
3490 |
22 May 16 |
peter |
542 |
} |
3490 |
22 May 16 |
peter |
543 |
|
3490 |
22 May 16 |
peter |
544 |
|
3490 |
22 May 16 |
peter |
545 |
template<typename Access> |
3490 |
22 May 16 |
peter |
546 |
void test_sort_index2(Access access) |
3490 |
22 May 16 |
peter |
547 |
{ |
3490 |
22 May 16 |
peter |
// cannot create iterator_archetype w incrementable_traversal_tag |
3490 |
22 May 16 |
peter |
//test_sort_index2(access, boost::incrementable_traversal_tag()); |
3490 |
22 May 16 |
peter |
550 |
test_sort_index2(access, boost::forward_traversal_tag()); |
3490 |
22 May 16 |
peter |
551 |
test_sort_index2(access, boost::bidirectional_traversal_tag()); |
3490 |
22 May 16 |
peter |
552 |
test_sort_index2(access, boost::random_access_traversal_tag()); |
3490 |
22 May 16 |
peter |
553 |
} |
3490 |
22 May 16 |
peter |
554 |
|
3490 |
22 May 16 |
peter |
555 |
|
3490 |
22 May 16 |
peter |
556 |
void test_sort_index2(void) |
3490 |
22 May 16 |
peter |
557 |
{ |
3490 |
22 May 16 |
peter |
558 |
using namespace boost::iterator_archetypes; |
3490 |
22 May 16 |
peter |
559 |
|
3490 |
22 May 16 |
peter |
560 |
test_sort_index2(readable_iterator_t()); |
3490 |
22 May 16 |
peter |
561 |
test_sort_index2(readable_writable_iterator_t()); |
3490 |
22 May 16 |
peter |
562 |
test_sort_index2(writable_lvalue_iterator_t()); |
3490 |
22 May 16 |
peter |
563 |
} |
3490 |
22 May 16 |
peter |
564 |
|
3490 |
22 May 16 |
peter |
565 |
|
1491 |
11 Sep 08 |
peter |
566 |
void test_sort_index(test::Suite& suite) |
1491 |
11 Sep 08 |
peter |
567 |
{ |
1491 |
11 Sep 08 |
peter |
568 |
suite.err() << "testing sort_index" << std::endl; |
1491 |
11 Sep 08 |
peter |
569 |
utility::Vector a(10); |
1491 |
11 Sep 08 |
peter |
570 |
for (size_t i=0; i<a.size(); ++i) |
1491 |
11 Sep 08 |
peter |
571 |
a(i) = std::pow(i-4.2,2); |
1491 |
11 Sep 08 |
peter |
572 |
std::vector<size_t> vec; |
1491 |
11 Sep 08 |
peter |
573 |
utility::sort_index(vec, a); |
1491 |
11 Sep 08 |
peter |
574 |
|
1491 |
11 Sep 08 |
peter |
575 |
std::vector<size_t> vec2; |
1491 |
11 Sep 08 |
peter |
576 |
utility::sort_index(a.begin(), a.end(), vec2); |
1491 |
11 Sep 08 |
peter |
577 |
if (vec.size()==vec2.size()) { |
1491 |
11 Sep 08 |
peter |
578 |
if (!suite.equal_range(vec.begin(), vec.end(), vec2.begin())) { |
1491 |
11 Sep 08 |
peter |
579 |
suite.add(false); |
1491 |
11 Sep 08 |
peter |
580 |
} |
1491 |
11 Sep 08 |
peter |
581 |
} |
1491 |
11 Sep 08 |
peter |
582 |
else { |
1491 |
11 Sep 08 |
peter |
583 |
suite.add(false); |
2673 |
03 Dec 11 |
peter |
584 |
suite.err() << "size mismatch: vec.size()=" << vec.size() |
2673 |
03 Dec 11 |
peter |
585 |
<< "vec2.size()=" << vec2.size() << "\n"; |
1491 |
11 Sep 08 |
peter |
586 |
} |
1491 |
11 Sep 08 |
peter |
587 |
const utility::VectorConstView b(a, 0, 5, 2); |
1491 |
11 Sep 08 |
peter |
588 |
|
1491 |
11 Sep 08 |
peter |
589 |
std::vector<size_t> vec3; |
1491 |
11 Sep 08 |
peter |
590 |
utility::sort_index(vec3, b); |
1491 |
11 Sep 08 |
peter |
591 |
std::vector<size_t> vec4; |
1491 |
11 Sep 08 |
peter |
592 |
utility::sort_index(b.begin(), b.end(), vec4); |
1491 |
11 Sep 08 |
peter |
593 |
if (vec3.size()!=vec4.size()) { |
1491 |
11 Sep 08 |
peter |
594 |
suite.add(false); |
2673 |
03 Dec 11 |
peter |
595 |
suite.err() << "size mismatch: vec3.size()=" << vec3.size() |
2673 |
03 Dec 11 |
peter |
596 |
<< " vec4.size()=" << vec4.size() << "\n"; |
1491 |
11 Sep 08 |
peter |
597 |
} |
1491 |
11 Sep 08 |
peter |
598 |
else { |
1491 |
11 Sep 08 |
peter |
599 |
if (!suite.equal_range(vec3.begin(), vec3.end(), vec4.begin())){ |
1491 |
11 Sep 08 |
peter |
600 |
suite.add(false); |
1491 |
11 Sep 08 |
peter |
601 |
} |
1491 |
11 Sep 08 |
peter |
602 |
} |
1492 |
12 Sep 08 |
peter |
603 |
|
1492 |
12 Sep 08 |
peter |
604 |
std::list<double> list; |
1492 |
12 Sep 08 |
peter |
605 |
for (size_t i=0; i<a.size(); ++i) |
1492 |
12 Sep 08 |
peter |
606 |
list.push_back(a(i)); |
1492 |
12 Sep 08 |
peter |
607 |
std::vector<size_t> vec5; |
1492 |
12 Sep 08 |
peter |
608 |
utility::sort_index(list.begin(), list.end(), vec5); |
1492 |
12 Sep 08 |
peter |
609 |
if (vec.size()!=vec5.size()) { |
1492 |
12 Sep 08 |
peter |
610 |
suite.add(false); |
2673 |
03 Dec 11 |
peter |
611 |
suite.err() << "size mismatch: vec.size()=" << vec.size() |
2673 |
03 Dec 11 |
peter |
612 |
<< " vec5.size()=" << vec5.size() << "\n"; |
1492 |
12 Sep 08 |
peter |
613 |
} |
1492 |
12 Sep 08 |
peter |
614 |
else { |
1492 |
12 Sep 08 |
peter |
615 |
if (!suite.equal_range(vec.begin(), vec.end(), vec5.begin())){ |
1492 |
12 Sep 08 |
peter |
616 |
suite.add(false); |
1492 |
12 Sep 08 |
peter |
617 |
} |
1492 |
12 Sep 08 |
peter |
618 |
} |
1492 |
12 Sep 08 |
peter |
619 |
|
3490 |
22 May 16 |
peter |
620 |
test_sort_index2(); |
1491 |
11 Sep 08 |
peter |
621 |
} |
2239 |
10 Apr 10 |
peter |
622 |
|
3287 |
12 Jul 14 |
peter |
623 |
|
3287 |
12 Jul 14 |
peter |
624 |
void test_sum_weight(test::Suite& suite) |
3287 |
12 Jul 14 |
peter |
625 |
{ |
3287 |
12 Jul 14 |
peter |
// do not run compile test |
3287 |
12 Jul 14 |
peter |
627 |
if (false) { |
3287 |
12 Jul 14 |
peter |
628 |
boost::input_iterator_archetype<double> iter; |
3287 |
12 Jul 14 |
peter |
629 |
utility::sum_weight(iter, iter); |
3287 |
12 Jul 14 |
peter |
630 |
boost::input_iterator_archetype_no_proxy<utility::DataWeight> iter2; |
3287 |
12 Jul 14 |
peter |
631 |
utility::sum_weight(iter2, iter2); |
3287 |
12 Jul 14 |
peter |
632 |
} |
3287 |
12 Jul 14 |
peter |
633 |
} |
3287 |
12 Jul 14 |
peter |
634 |
|
3287 |
12 Jul 14 |
peter |
635 |
|
2239 |
10 Apr 10 |
peter |
636 |
void test_ptr_compare(test::Suite& suite) |
2239 |
10 Apr 10 |
peter |
637 |
{ |
2286 |
27 Jun 10 |
peter |
638 |
using utility::make_ptr_compare; |
2239 |
10 Apr 10 |
peter |
639 |
std::vector<double*> vec(10); |
2239 |
10 Apr 10 |
peter |
640 |
std::greater<double> d_greater; |
2239 |
10 Apr 10 |
peter |
641 |
for (size_t i=0; i<vec.size(); ++i) |
2239 |
10 Apr 10 |
peter |
642 |
vec[i] = new double(i); |
2286 |
27 Jun 10 |
peter |
643 |
std::sort(vec.begin(), vec.end(), make_ptr_compare(*vec.begin(), d_greater)); |
2239 |
10 Apr 10 |
peter |
644 |
for (size_t i=1; i<vec.size(); ++i) { |
2239 |
10 Apr 10 |
peter |
645 |
suite.add( *vec[i-1] > *vec[i]); |
2239 |
10 Apr 10 |
peter |
646 |
} |
2286 |
27 Jun 10 |
peter |
647 |
std::sort(vec.begin(), vec.end(), make_ptr_compare(*vec.begin())); |
2286 |
27 Jun 10 |
peter |
648 |
for (size_t i=1; i<vec.size(); ++i) { |
2286 |
27 Jun 10 |
peter |
649 |
suite.add( *vec[i-1] < *vec[i]); |
2286 |
27 Jun 10 |
peter |
650 |
} |
2239 |
10 Apr 10 |
peter |
651 |
for (size_t i=0; i<vec.size(); ++i) |
2239 |
10 Apr 10 |
peter |
652 |
delete vec[i]; |
2239 |
10 Apr 10 |
peter |
653 |
|
2239 |
10 Apr 10 |
peter |
654 |
} |
2908 |
15 Dec 12 |
peter |
655 |
|
2908 |
15 Dec 12 |
peter |
656 |
|
2908 |
15 Dec 12 |
peter |
657 |
void test_fnmatch(test::Suite& suite) |
2908 |
15 Dec 12 |
peter |
658 |
{ |
2908 |
15 Dec 12 |
peter |
659 |
bool ok=true; |
2908 |
15 Dec 12 |
peter |
660 |
ok &= test_fnmatch(true,"peter", "peter"); |
2908 |
15 Dec 12 |
peter |
661 |
ok &= test_fnmatch(false,"peter", "peterj"); |
2908 |
15 Dec 12 |
peter |
662 |
|
2908 |
15 Dec 12 |
peter |
663 |
ok &= test_fnmatch(true,"*", "peterj"); |
2908 |
15 Dec 12 |
peter |
664 |
ok &= test_fnmatch(true,"p*", "peterj"); |
2908 |
15 Dec 12 |
peter |
665 |
ok &= test_fnmatch(true, "p*", "peter"); |
2908 |
15 Dec 12 |
peter |
666 |
ok &= test_fnmatch(false, "p*j", "peter"); |
2908 |
15 Dec 12 |
peter |
667 |
ok &= test_fnmatch(true, "p*j", "peterj"); |
2908 |
15 Dec 12 |
peter |
668 |
ok &= test_fnmatch(true, "*peter", "peter"); |
2908 |
15 Dec 12 |
peter |
669 |
|
2908 |
15 Dec 12 |
peter |
670 |
ok &= test_fnmatch(true, "p?ter", "peter"); |
2908 |
15 Dec 12 |
peter |
671 |
ok &= test_fnmatch(false, "p?er", "peter"); |
2908 |
15 Dec 12 |
peter |
672 |
ok &= test_fnmatch(false, "p?eter", "peter"); |
2908 |
15 Dec 12 |
peter |
673 |
|
2908 |
15 Dec 12 |
peter |
674 |
ok &= test_fnmatch(true, "filename", "filename"); |
2908 |
15 Dec 12 |
peter |
675 |
ok &= test_fnmatch(true, "*name", "filename"); |
2908 |
15 Dec 12 |
peter |
676 |
ok &= test_fnmatch(true, "[fa]il?name", "filename"); |
2908 |
15 Dec 12 |
peter |
677 |
ok &= test_fnmatch(true, "[fa]*il?name", "ffilename"); |
2908 |
15 Dec 12 |
peter |
678 |
|
2908 |
15 Dec 12 |
peter |
679 |
ok &= test_fnmatch(true, "[fa]*il?name", "fafafailename"); |
2908 |
15 Dec 12 |
peter |
680 |
ok &= test_fnmatch(false, "[fa]?il?name", "ilename"); |
2908 |
15 Dec 12 |
peter |
681 |
ok &= test_fnmatch(false, "?[fa]il?name", "ilename"); |
2908 |
15 Dec 12 |
peter |
682 |
ok &= test_fnmatch(true, "[fa]il?name", "filename"); |
2908 |
15 Dec 12 |
peter |
683 |
ok &= test_fnmatch(false, "[fa]?il?name", "fafafailename"); |
2908 |
15 Dec 12 |
peter |
684 |
|
2908 |
15 Dec 12 |
peter |
685 |
ok &= test_fnmatch(true, "*name", "/path/to/filename"); |
2908 |
15 Dec 12 |
peter |
686 |
ok &= test_fnmatch(true, "*name", "file.name"); |
2908 |
15 Dec 12 |
peter |
687 |
ok &= test_fnmatch(true, "*.txt", ".file.txt"); |
2908 |
15 Dec 12 |
peter |
688 |
suite.add(ok); |
2908 |
15 Dec 12 |
peter |
689 |
} |
2908 |
15 Dec 12 |
peter |
690 |
|
2908 |
15 Dec 12 |
peter |
691 |
|
2908 |
15 Dec 12 |
peter |
692 |
void test_dirname(test::Suite& suite) |
2908 |
15 Dec 12 |
peter |
693 |
{ |
2908 |
15 Dec 12 |
peter |
694 |
std::vector<std::string> path; |
2908 |
15 Dec 12 |
peter |
695 |
path.push_back("/usr/lib"); |
2908 |
15 Dec 12 |
peter |
696 |
path.push_back("/usr/"); |
2908 |
15 Dec 12 |
peter |
697 |
path.push_back("usr"); |
2908 |
15 Dec 12 |
peter |
698 |
path.push_back("/"); |
2908 |
15 Dec 12 |
peter |
699 |
path.push_back("."); |
2908 |
15 Dec 12 |
peter |
700 |
path.push_back(".."); |
3698 |
25 Sep 17 |
peter |
701 |
path.push_back(""); |
2908 |
15 Dec 12 |
peter |
702 |
std::vector<std::string> dir; |
2908 |
15 Dec 12 |
peter |
703 |
dir.push_back("/usr"); |
2908 |
15 Dec 12 |
peter |
704 |
dir.push_back("/"); |
2908 |
15 Dec 12 |
peter |
705 |
dir.push_back("."); |
2908 |
15 Dec 12 |
peter |
706 |
dir.push_back("/"); |
2908 |
15 Dec 12 |
peter |
707 |
dir.push_back("."); |
2908 |
15 Dec 12 |
peter |
708 |
dir.push_back("."); |
3698 |
25 Sep 17 |
peter |
709 |
dir.push_back("."); |
2908 |
15 Dec 12 |
peter |
710 |
assert(dir.size()==path.size()); |
2908 |
15 Dec 12 |
peter |
711 |
using utility::dirname; |
2908 |
15 Dec 12 |
peter |
712 |
for (size_t i=0; i<dir.size(); ++i) { |
2908 |
15 Dec 12 |
peter |
713 |
if (dir[i] != dirname(path[i])) { |
2908 |
15 Dec 12 |
peter |
714 |
suite.add(false); |
2908 |
15 Dec 12 |
peter |
715 |
suite.out() << "error:\n"; |
2908 |
15 Dec 12 |
peter |
716 |
suite.out() << "path: " << path[i] << "\n"; |
2908 |
15 Dec 12 |
peter |
717 |
suite.out() << "directory_name: " << dirname(path[i]) << "\n"; |
2908 |
15 Dec 12 |
peter |
718 |
suite.out() << "expected: " << dir[i] << "\n"; |
2908 |
15 Dec 12 |
peter |
719 |
} |
2908 |
15 Dec 12 |
peter |
720 |
} |
2908 |
15 Dec 12 |
peter |
721 |
} |
2908 |
15 Dec 12 |
peter |
722 |
|
2908 |
15 Dec 12 |
peter |
723 |
|
2908 |
15 Dec 12 |
peter |
724 |
void test_basename(test::Suite& suite) |
2908 |
15 Dec 12 |
peter |
725 |
{ |
2908 |
15 Dec 12 |
peter |
726 |
std::vector<std::string> path; |
2908 |
15 Dec 12 |
peter |
727 |
path.push_back("/usr/lib"); |
2908 |
15 Dec 12 |
peter |
728 |
path.push_back("/usr/"); |
2908 |
15 Dec 12 |
peter |
729 |
path.push_back("usr"); |
2908 |
15 Dec 12 |
peter |
730 |
path.push_back("/"); |
2908 |
15 Dec 12 |
peter |
731 |
path.push_back("."); |
2908 |
15 Dec 12 |
peter |
732 |
path.push_back(".."); |
3698 |
25 Sep 17 |
peter |
733 |
path.push_back(""); |
2908 |
15 Dec 12 |
peter |
734 |
std::vector<std::string> file; |
2908 |
15 Dec 12 |
peter |
735 |
file.push_back("lib"); |
2908 |
15 Dec 12 |
peter |
736 |
file.push_back("usr"); |
2908 |
15 Dec 12 |
peter |
737 |
file.push_back("usr"); |
2908 |
15 Dec 12 |
peter |
738 |
file.push_back("/"); |
2908 |
15 Dec 12 |
peter |
739 |
file.push_back("."); |
2908 |
15 Dec 12 |
peter |
740 |
file.push_back(".."); |
3698 |
25 Sep 17 |
peter |
741 |
file.push_back("."); |
2908 |
15 Dec 12 |
peter |
742 |
assert(file.size()==path.size()); |
2908 |
15 Dec 12 |
peter |
743 |
using utility::basename; |
2908 |
15 Dec 12 |
peter |
744 |
for (size_t i=0; i<file.size(); ++i) { |
2908 |
15 Dec 12 |
peter |
745 |
if (file[i] != basename(path[i])) { |
2908 |
15 Dec 12 |
peter |
746 |
suite.add(false); |
2908 |
15 Dec 12 |
peter |
747 |
suite.out() << "error:\n"; |
2908 |
15 Dec 12 |
peter |
748 |
suite.out() << "path: " << path[i] << "\n"; |
2908 |
15 Dec 12 |
peter |
749 |
suite.out() << "basename: " << basename(path[i]) << "\n"; |
2908 |
15 Dec 12 |
peter |
750 |
suite.out() << "expected: " << file[i] << "\n"; |
2908 |
15 Dec 12 |
peter |
751 |
} |
2908 |
15 Dec 12 |
peter |
752 |
} |
2908 |
15 Dec 12 |
peter |
753 |
} |
2908 |
15 Dec 12 |
peter |
754 |
|
2908 |
15 Dec 12 |
peter |
755 |
|
2908 |
15 Dec 12 |
peter |
756 |
bool test_fnmatch(bool answ, std::string a, std::string b) |
2908 |
15 Dec 12 |
peter |
757 |
{ |
2908 |
15 Dec 12 |
peter |
758 |
using namespace utility; |
2908 |
15 Dec 12 |
peter |
759 |
bool res = fnmatch(a, b); |
2908 |
15 Dec 12 |
peter |
// check that fnmatch and regexp agree |
2908 |
15 Dec 12 |
peter |
761 |
if (res == answ) |
2908 |
15 Dec 12 |
peter |
762 |
return true; |
2908 |
15 Dec 12 |
peter |
763 |
if (res!=answ) |
2908 |
15 Dec 12 |
peter |
764 |
std::cerr << "fnmatch(" << a << ", " << b << ") results " |
2908 |
15 Dec 12 |
peter |
765 |
<< res |
2908 |
15 Dec 12 |
peter |
766 |
<< ". Expects " << answ << std::endl; |
2908 |
15 Dec 12 |
peter |
767 |
return false; |
2908 |
15 Dec 12 |
peter |
768 |
} |
3098 |
28 Oct 13 |
peter |
769 |
|
3098 |
28 Oct 13 |
peter |
770 |
|
3803 |
12 May 19 |
peter |
771 |
void test_getcwd(test::Suite& suite) |
3803 |
12 May 19 |
peter |
772 |
{ |
3803 |
12 May 19 |
peter |
773 |
std::string cwd = utility::getcwd(); |
3803 |
12 May 19 |
peter |
774 |
suite.out() << "cwd: " << cwd << "\n"; |
3803 |
12 May 19 |
peter |
775 |
if (cwd.find("/test/testSubDir/") == std::string::npos) { |
3803 |
12 May 19 |
peter |
776 |
suite.add(false); |
3803 |
12 May 19 |
peter |
777 |
suite.err() << "error: cwd: expect path to contain 'test/testSubDir/'\n"; |
3803 |
12 May 19 |
peter |
778 |
} |
3803 |
12 May 19 |
peter |
779 |
} |
3803 |
12 May 19 |
peter |
780 |
|
3803 |
12 May 19 |
peter |
781 |
|
3295 |
25 Jul 14 |
peter |
782 |
void test_remove(test::Suite& suite) |
3295 |
25 Jul 14 |
peter |
783 |
{ |
3295 |
25 Jul 14 |
peter |
// at least test linking |
3295 |
25 Jul 14 |
peter |
785 |
if (false) |
3295 |
25 Jul 14 |
peter |
786 |
utility::remove("foo"); |
3295 |
25 Jul 14 |
peter |
787 |
} |
3295 |
25 Jul 14 |
peter |
788 |
|
3295 |
25 Jul 14 |
peter |
789 |
|
3295 |
25 Jul 14 |
peter |
790 |
void test_rename(test::Suite& suite) |
3295 |
25 Jul 14 |
peter |
791 |
{ |
3295 |
25 Jul 14 |
peter |
// at least test linking |
3295 |
25 Jul 14 |
peter |
793 |
if (false) |
3295 |
25 Jul 14 |
peter |
794 |
utility::rename("foo", "bar"); |
3295 |
25 Jul 14 |
peter |
795 |
} |
3295 |
25 Jul 14 |
peter |
796 |
|
3295 |
25 Jul 14 |
peter |
797 |
|
3098 |
28 Oct 13 |
peter |
798 |
void test_replace(test::Suite& suite) |
3098 |
28 Oct 13 |
peter |
799 |
{ |
3098 |
28 Oct 13 |
peter |
800 |
std::string s = "Some magic string!!!"; |
3098 |
28 Oct 13 |
peter |
801 |
utility::replace(s, "magic", "arbitrary"); |
3098 |
28 Oct 13 |
peter |
802 |
if (!suite.add(s=="Some arbitrary string!!!")) |
3098 |
28 Oct 13 |
peter |
803 |
suite.err() << "error: " << s << "\n"; |
3098 |
28 Oct 13 |
peter |
804 |
} |
3466 |
10 Feb 16 |
peter |
805 |
|
3466 |
10 Feb 16 |
peter |
806 |
|
3746 |
13 Aug 18 |
peter |
807 |
void test_symlink(test::Suite& suite) |
3746 |
13 Aug 18 |
peter |
808 |
{ |
3746 |
13 Aug 18 |
peter |
// at least test function links |
3746 |
13 Aug 18 |
peter |
810 |
if (false) |
3746 |
13 Aug 18 |
peter |
811 |
utility::symlink("/from/to/path", "my/symlink"); |
3746 |
13 Aug 18 |
peter |
812 |
} |
3746 |
13 Aug 18 |
peter |
813 |
|
3746 |
13 Aug 18 |
peter |
814 |
|
3466 |
10 Feb 16 |
peter |
815 |
void test_ticket842(test::Suite& suite) |
3466 |
10 Feb 16 |
peter |
816 |
{ |
3466 |
10 Feb 16 |
peter |
817 |
suite.out() << "test_ticket842\n"; |
3466 |
10 Feb 16 |
peter |
818 |
std::vector<std::pair<std::string, int> > data; |
3466 |
10 Feb 16 |
peter |
819 |
data.push_back(std::make_pair("Orange", 2)); |
3466 |
10 Feb 16 |
peter |
820 |
data.push_back(std::make_pair("Orange", 1)); |
3466 |
10 Feb 16 |
peter |
821 |
data.push_back(std::make_pair("Apple", 10)); |
3466 |
10 Feb 16 |
peter |
822 |
|
3466 |
10 Feb 16 |
peter |
823 |
typedef utility::PairFirst<const std::pair<std::string, int> > PF; |
3466 |
10 Feb 16 |
peter |
824 |
typedef std::less<std::string> strLess; |
3466 |
10 Feb 16 |
peter |
825 |
utility::compose_f_gx_hy<strLess, PF, PF> compare; |
3466 |
10 Feb 16 |
peter |
// stable sort should shuffle 'Apple' first, and then keep the order |
3466 |
10 Feb 16 |
peter |
// of the equaivalent 'Orange' elements, i.e., <Orange, 2> should stay |
3466 |
10 Feb 16 |
peter |
// before <Orange, 1>. |
3466 |
10 Feb 16 |
peter |
829 |
std::stable_sort(data.begin(), data.end(), compare); |
3466 |
10 Feb 16 |
peter |
830 |
if (!suite.add(data[0].first == "Apple")) |
3466 |
10 Feb 16 |
peter |
831 |
suite.err() << "incorrect data[0].first: " << data[0].first << "\n"; |
3466 |
10 Feb 16 |
peter |
832 |
if (!suite.add(data[1].first == "Orange")) |
3466 |
10 Feb 16 |
peter |
833 |
suite.err() << "incorrect data[1].first: " << data[1].first << "\n"; |
3466 |
10 Feb 16 |
peter |
834 |
if (!suite.add(data[1].second == 2)) |
3466 |
10 Feb 16 |
peter |
835 |
suite.err() << "incorrect data[1].second: " << data[1].second << "\n"; |
3466 |
10 Feb 16 |
peter |
836 |
} |
4102 |
22 Sep 21 |
peter |
837 |
|
4102 |
22 Sep 21 |
peter |
838 |
|
4102 |
22 Sep 21 |
peter |
839 |
void test_starts_with(test::Suite& suite) |
4102 |
22 Sep 21 |
peter |
840 |
{ |
4102 |
22 Sep 21 |
peter |
841 |
std::string name("Jane Doe"); |
4102 |
22 Sep 21 |
peter |
842 |
if (!utility::starts_with(name, "Jane")) { |
4102 |
22 Sep 21 |
peter |
843 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
844 |
suite.err() << "error: 'Jane Doe' does not start with 'Jane'\n"; |
4102 |
22 Sep 21 |
peter |
845 |
} |
4102 |
22 Sep 21 |
peter |
846 |
if (!utility::starts_with(name, 'J')) { |
4102 |
22 Sep 21 |
peter |
847 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
848 |
suite.err() << "error: starts_with(x,x) failed\n"; |
4102 |
22 Sep 21 |
peter |
849 |
} |
4102 |
22 Sep 21 |
peter |
850 |
if (!utility::starts_with(name, name)) { |
4102 |
22 Sep 21 |
peter |
851 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
852 |
suite.err() << "error: starts_with(x,x) failed\n"; |
4102 |
22 Sep 21 |
peter |
853 |
} |
4102 |
22 Sep 21 |
peter |
854 |
} |
4102 |
22 Sep 21 |
peter |
855 |
|
4102 |
22 Sep 21 |
peter |
856 |
|
4102 |
22 Sep 21 |
peter |
857 |
void test_contains(test::Suite& suite) |
4102 |
22 Sep 21 |
peter |
858 |
{ |
4102 |
22 Sep 21 |
peter |
859 |
std::string name("Jane Doe"); |
4102 |
22 Sep 21 |
peter |
860 |
if (!utility::contains(name, "ne")) { |
4102 |
22 Sep 21 |
peter |
861 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
862 |
suite.err() << "error: " << name << " does not contain \"ne\"\n"; |
4102 |
22 Sep 21 |
peter |
863 |
} |
4102 |
22 Sep 21 |
peter |
864 |
if (!utility::contains(name, name)) { |
4102 |
22 Sep 21 |
peter |
865 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
866 |
suite.err() << "error: contains(x,x) failed\n"; |
4102 |
22 Sep 21 |
peter |
867 |
} |
4102 |
22 Sep 21 |
peter |
868 |
if (!utility::contains(name, 'D')) { |
4102 |
22 Sep 21 |
peter |
869 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
870 |
suite.err() << "error: contains(string,char) failed\n"; |
4102 |
22 Sep 21 |
peter |
871 |
} |
4102 |
22 Sep 21 |
peter |
872 |
} |
4102 |
22 Sep 21 |
peter |
873 |
|
4102 |
22 Sep 21 |
peter |
874 |
|
4102 |
22 Sep 21 |
peter |
875 |
void test_ends_with(test::Suite& suite) |
4102 |
22 Sep 21 |
peter |
876 |
{ |
4102 |
22 Sep 21 |
peter |
877 |
std::string name("Jane Doe"); |
4102 |
22 Sep 21 |
peter |
878 |
if (!utility::ends_with(name, name)) { |
4102 |
22 Sep 21 |
peter |
879 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
880 |
suite.err() << "error: ends_with(x,x) failed\n"; |
4102 |
22 Sep 21 |
peter |
881 |
} |
4102 |
22 Sep 21 |
peter |
882 |
if (!utility::ends_with(name, 'e')) { |
4102 |
22 Sep 21 |
peter |
883 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
884 |
suite.err() << "error: ends_with(x,x) failed\n"; |
4102 |
22 Sep 21 |
peter |
885 |
} |
4102 |
22 Sep 21 |
peter |
886 |
if (!utility::ends_with(name, "Doe")) { |
4102 |
22 Sep 21 |
peter |
887 |
suite.add(false); |
4102 |
22 Sep 21 |
peter |
888 |
suite.err() << "error: 'Jane Doe' does not end with 'Doe'\n"; |
4102 |
22 Sep 21 |
peter |
889 |
} |
4102 |
22 Sep 21 |
peter |
890 |
} |