4059 |
20 Apr 21 |
peter |
// $Id$ |
4059 |
20 Apr 21 |
peter |
2 |
|
4059 |
20 Apr 21 |
peter |
3 |
/* |
4059 |
20 Apr 21 |
peter |
Copyright (C) 2021 Peter Johansson |
4059 |
20 Apr 21 |
peter |
5 |
|
4059 |
20 Apr 21 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
4059 |
20 Apr 21 |
peter |
7 |
|
4059 |
20 Apr 21 |
peter |
The yat library is free software; you can redistribute it and/or |
4059 |
20 Apr 21 |
peter |
modify it under the terms of the GNU General Public License as |
4059 |
20 Apr 21 |
peter |
published by the Free Software Foundation; either version 3 of the |
4059 |
20 Apr 21 |
peter |
License, or (at your option) any later version. |
4059 |
20 Apr 21 |
peter |
12 |
|
4059 |
20 Apr 21 |
peter |
The yat library is distributed in the hope that it will be useful, |
4059 |
20 Apr 21 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4059 |
20 Apr 21 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4059 |
20 Apr 21 |
peter |
General Public License for more details. |
4059 |
20 Apr 21 |
peter |
17 |
|
4059 |
20 Apr 21 |
peter |
You should have received a copy of the GNU General Public License |
4059 |
20 Apr 21 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
4059 |
20 Apr 21 |
peter |
20 |
*/ |
4059 |
20 Apr 21 |
peter |
21 |
|
4059 |
20 Apr 21 |
peter |
22 |
#include <config.h> |
4059 |
20 Apr 21 |
peter |
23 |
|
4059 |
20 Apr 21 |
peter |
24 |
#include "Suite.h" |
4059 |
20 Apr 21 |
peter |
25 |
|
4059 |
20 Apr 21 |
peter |
26 |
#include <yat/utility/round.h> |
4059 |
20 Apr 21 |
peter |
27 |
#include <yat/utility/Vector.h> |
4059 |
20 Apr 21 |
peter |
28 |
|
4059 |
20 Apr 21 |
peter |
29 |
#include <boost/concept_archetype.hpp> |
4059 |
20 Apr 21 |
peter |
30 |
#include <boost/iterator/iterator_archetypes.hpp> |
4059 |
20 Apr 21 |
peter |
31 |
|
4059 |
20 Apr 21 |
peter |
32 |
#include <cmath> |
4059 |
20 Apr 21 |
peter |
33 |
|
4059 |
20 Apr 21 |
peter |
34 |
using namespace theplu::yat; |
4059 |
20 Apr 21 |
peter |
35 |
|
4059 |
20 Apr 21 |
peter |
36 |
int main(int argc,char* argv[]) |
4059 |
20 Apr 21 |
peter |
37 |
{ |
4059 |
20 Apr 21 |
peter |
38 |
test::Suite suite(argc, argv); |
4059 |
20 Apr 21 |
peter |
39 |
suite.err() << "testing round" << std::endl; |
4059 |
20 Apr 21 |
peter |
40 |
|
4059 |
20 Apr 21 |
peter |
41 |
utility::Vector vec(120); |
4059 |
20 Apr 21 |
peter |
42 |
std::generate(vec.begin(), vec.end(), test::Generator()); |
4059 |
20 Apr 21 |
peter |
43 |
vec *= 100.0/sum(vec); |
4059 |
20 Apr 21 |
peter |
44 |
|
4059 |
20 Apr 21 |
peter |
45 |
const utility::Vector& const_vec(vec); |
4059 |
20 Apr 21 |
peter |
46 |
utility::round(const_vec.begin(), const_vec.end(), vec.begin()); |
4059 |
20 Apr 21 |
peter |
47 |
if (!suite.add(suite.equal(sum(vec), 100.0))) { |
4059 |
20 Apr 21 |
peter |
48 |
suite.err() << "count: sum incorrect\n"; |
4059 |
20 Apr 21 |
peter |
49 |
} |
4059 |
20 Apr 21 |
peter |
50 |
|
4059 |
20 Apr 21 |
peter |
51 |
for (size_t i=0; i<vec.size(); ++i) { |
4059 |
20 Apr 21 |
peter |
52 |
if (suite.equal(vec(i), std::round(vec(i)))==false) { |
4059 |
20 Apr 21 |
peter |
53 |
suite.add(false); |
4059 |
20 Apr 21 |
peter |
54 |
suite.err() << "incorrect element " << i << ": " << vec(i) << "\n"; |
4059 |
20 Apr 21 |
peter |
55 |
} |
4059 |
20 Apr 21 |
peter |
56 |
} |
4059 |
20 Apr 21 |
peter |
57 |
|
4059 |
20 Apr 21 |
peter |
// don't run compilation test |
4059 |
20 Apr 21 |
peter |
59 |
if (false) { |
4059 |
20 Apr 21 |
peter |
60 |
boost::input_iterator_archetype<double> input; |
4059 |
20 Apr 21 |
peter |
61 |
boost::mutable_forward_iterator_archetype<double> output; |
4059 |
20 Apr 21 |
peter |
62 |
utility::round(input, input, output); |
4059 |
20 Apr 21 |
peter |
63 |
} |
4059 |
20 Apr 21 |
peter |
64 |
|
4059 |
20 Apr 21 |
peter |
65 |
return suite.return_value(); |
4059 |
20 Apr 21 |
peter |
66 |
} |