2032 |
19 Aug 09 |
peter |
// $Id$ |
2032 |
19 Aug 09 |
peter |
2 |
|
2032 |
19 Aug 09 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010, 2012 Peter Johansson |
2032 |
19 Aug 09 |
peter |
5 |
|
2032 |
19 Aug 09 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2032 |
19 Aug 09 |
peter |
7 |
|
2032 |
19 Aug 09 |
peter |
The yat library is free software; you can redistribute it and/or |
2032 |
19 Aug 09 |
peter |
modify it under the terms of the GNU General Public License as |
2032 |
19 Aug 09 |
peter |
published by the Free Software Foundation; either version 3 of the |
2032 |
19 Aug 09 |
peter |
License, or (at your option) any later version. |
2032 |
19 Aug 09 |
peter |
12 |
|
2032 |
19 Aug 09 |
peter |
The yat library is distributed in the hope that it will be useful, |
2032 |
19 Aug 09 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2032 |
19 Aug 09 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2032 |
19 Aug 09 |
peter |
General Public License for more details. |
2032 |
19 Aug 09 |
peter |
17 |
|
2032 |
19 Aug 09 |
peter |
You should have received a copy of the GNU General Public License |
2032 |
19 Aug 09 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2032 |
19 Aug 09 |
peter |
20 |
*/ |
2032 |
19 Aug 09 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2032 |
19 Aug 09 |
peter |
24 |
#include "Suite.h" |
2032 |
19 Aug 09 |
peter |
25 |
|
2032 |
19 Aug 09 |
peter |
26 |
#include "yat/statistics/Histogram.h" |
2202 |
21 Feb 10 |
peter |
27 |
#include "yat/utility/DataWeight.h" |
2032 |
19 Aug 09 |
peter |
28 |
|
2202 |
21 Feb 10 |
peter |
29 |
#include <boost/concept_archetype.hpp> |
2202 |
21 Feb 10 |
peter |
30 |
|
2032 |
19 Aug 09 |
peter |
31 |
#include <iostream> |
2032 |
19 Aug 09 |
peter |
32 |
|
2333 |
15 Oct 10 |
peter |
33 |
using namespace theplu::yat::statistics; |
2333 |
15 Oct 10 |
peter |
34 |
using namespace theplu::yat; |
2333 |
15 Oct 10 |
peter |
35 |
|
2333 |
15 Oct 10 |
peter |
36 |
void test_stream_constructor(test::Suite&); |
2333 |
15 Oct 10 |
peter |
37 |
|
2032 |
19 Aug 09 |
peter |
38 |
int main(int argc, char* argv[]) |
2032 |
19 Aug 09 |
peter |
39 |
{ |
2032 |
19 Aug 09 |
peter |
40 |
theplu::yat::test::Suite suite(argc, argv); |
2032 |
19 Aug 09 |
peter |
41 |
suite.err() << "testing histogram" << std::endl; |
2032 |
19 Aug 09 |
peter |
42 |
|
2032 |
19 Aug 09 |
peter |
43 |
Histogram a(0,10,10); |
2032 |
19 Aug 09 |
peter |
44 |
Histogram b(0,10,10); |
2032 |
19 Aug 09 |
peter |
45 |
for (double x=0.01; x<10; x*=1.1) { |
2032 |
19 Aug 09 |
peter |
46 |
a.add(x); |
2032 |
19 Aug 09 |
peter |
47 |
b.add(2*x); |
2032 |
19 Aug 09 |
peter |
48 |
} |
2032 |
19 Aug 09 |
peter |
49 |
Histogram c(a); |
2032 |
19 Aug 09 |
peter |
50 |
c+=b; |
4200 |
19 Aug 22 |
peter |
51 |
|
2032 |
19 Aug 09 |
peter |
52 |
for (size_t i=0; i<10; ++i) { |
2032 |
19 Aug 09 |
peter |
53 |
suite.add(a.observation_value(i) == c.observation_value(i)); |
2032 |
19 Aug 09 |
peter |
54 |
suite.add(c[i] == (a[i]+b[i])); |
2032 |
19 Aug 09 |
peter |
55 |
} |
2202 |
21 Feb 10 |
peter |
// do not run compiler test |
2202 |
21 Feb 10 |
peter |
57 |
if (false) { |
2202 |
21 Feb 10 |
peter |
58 |
Histogram hist; |
4200 |
19 Aug 22 |
peter |
59 |
add(hist, boost::forward_iterator_archetype<double>(), |
2202 |
21 Feb 10 |
peter |
60 |
boost::forward_iterator_archetype<double>()); |
2202 |
21 Feb 10 |
peter |
61 |
using utility::DataWeight; |
4200 |
19 Aug 22 |
peter |
62 |
add(hist, boost::forward_iterator_archetype<DataWeight>(), |
2202 |
21 Feb 10 |
peter |
63 |
boost::forward_iterator_archetype<DataWeight>()); |
2202 |
21 Feb 10 |
peter |
64 |
} |
2333 |
15 Oct 10 |
peter |
65 |
test_stream_constructor(suite); |
2032 |
19 Aug 09 |
peter |
66 |
|
2032 |
19 Aug 09 |
peter |
67 |
return suite.return_value(); |
2032 |
19 Aug 09 |
peter |
68 |
} |
2333 |
15 Oct 10 |
peter |
69 |
|
2333 |
15 Oct 10 |
peter |
70 |
void test_stream_constructor(test::Suite& suite) |
2333 |
15 Oct 10 |
peter |
71 |
{ |
2333 |
15 Oct 10 |
peter |
72 |
Histogram hist(0, 10, 10); |
2333 |
15 Oct 10 |
peter |
73 |
hist.add(3,2); |
2333 |
15 Oct 10 |
peter |
74 |
hist.add(1,3.14); |
2333 |
15 Oct 10 |
peter |
75 |
hist.add(20); |
2333 |
15 Oct 10 |
peter |
76 |
std::ostringstream oss; |
2333 |
15 Oct 10 |
peter |
77 |
oss << hist; |
2333 |
15 Oct 10 |
peter |
78 |
std::istringstream iss(oss.str()); |
2333 |
15 Oct 10 |
peter |
79 |
Histogram hist2(iss); |
2333 |
15 Oct 10 |
peter |
80 |
std::ostringstream oss2; |
2333 |
15 Oct 10 |
peter |
81 |
oss2 << hist2; |
2333 |
15 Oct 10 |
peter |
82 |
if (oss.str() != oss2.str()) { |
2333 |
15 Oct 10 |
peter |
83 |
suite.add(false); |
4200 |
19 Aug 22 |
peter |
84 |
suite.err() << "output:\n" << oss.str() |
2333 |
15 Oct 10 |
peter |
85 |
<< "not equal to\n" << oss2.str(); |
4200 |
19 Aug 22 |
peter |
86 |
|
2333 |
15 Oct 10 |
peter |
87 |
} |
2333 |
15 Oct 10 |
peter |
88 |
} |