1 /*
2 * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4 * For use in publications, see ACKNOWLEDGE.TXT
5 */
6
7 #include "alps/accumulators.hpp"
8 #include "gtest/gtest.h"
9
10 #include "accumulator_generator.hpp"
11
12 using namespace alps::accumulators::testing;
13
14 /// Google Test Fixture: argument is Accumulator<Type>
15 template <typename A>
16 class AccumulatorPrintTest : public ::testing::Test {
17 public:
18 typedef AccResultGenerator<A,1000> acc_gen_type;
19 typedef typename acc_gen_type::value_type value_type;
20 acc_gen_type acc_gen;
21 };
22
23 using namespace alps::accumulators;
24
25 typedef std::vector<double> v_double;
26
27 /*
28 for acc in Mean NoBinning LogBinning FullBinning; do
29 for type in float double 'long double' v_double; do
30 echo "${acc}Accumulator<$type>,"
31 done; echo; done
32 */
33
34
35 typedef ::testing::Types<
36 MeanAccumulator<float>,
37 MeanAccumulator<double>,
38 MeanAccumulator<long double>,
39 MeanAccumulator<v_double>,
40
41 NoBinningAccumulator<float>,
42 NoBinningAccumulator<double>,
43 NoBinningAccumulator<long double>,
44 NoBinningAccumulator<v_double>,
45
46 LogBinningAccumulator<float>,
47 LogBinningAccumulator<double>,
48 LogBinningAccumulator<long double>,
49 LogBinningAccumulator<v_double>,
50
51 FullBinningAccumulator<float>,
52 FullBinningAccumulator<double>,
53 FullBinningAccumulator<long double>,
54 FullBinningAccumulator<v_double>
55 > test_types;
56
57 TYPED_TEST_CASE(AccumulatorPrintTest,test_types);
58
TYPED_TEST(AccumulatorPrintTest,print)59 TYPED_TEST(AccumulatorPrintTest, print)
60 {
61 const accumulator_wrapper& a=this->acc_gen.accumulator();
62 const result_wrapper& r=this->acc_gen.result();
63
64 std::cout << "Expected: " << this->acc_gen.expected_mean() << "+/-" << this->acc_gen.expected_err()
65 << "\nAccumulator: " << a
66 << "\nResult: " << r
67 << std::endl;
68 // std::cout << "\nFull print accumulator:\n" << a.fullprint
69 // << "\nFull print result:\n" << r.fullprint
70 // << std::endl;
71 }
72
73 /// Google Test Fixture: argument is data Type
74 template <typename T>
75 class AccumulatorCorrelatedPrintTest : public ::testing::Test {
76 public:
77 typedef acc_correlated_gen<T,5000,15> acc_gen_type;
78 typedef T data_type;
79 acc_gen_type acc_gen;
80 };
81
82 typedef ::testing::Types< float, double, long double> test_types2;
83 TYPED_TEST_CASE(AccumulatorCorrelatedPrintTest,test_types2);
84
TYPED_TEST(AccumulatorCorrelatedPrintTest,print)85 TYPED_TEST(AccumulatorCorrelatedPrintTest, print)
86 {
87 typedef typename TestFixture::data_type data_type;
88 const accumulator_set& a=this->acc_gen.accumulators();
89 const result_set& r=this->acc_gen.results();
90
91 const char* names[]={"mean","nobin","logbin","fullbin"};
92 const int nnames=sizeof(names)/sizeof(*names);
93 std::cout << "Uncorrelated: " << this->acc_gen.expected_mean() << "+/-" << this->acc_gen.expected_uncorr_err() << "\n";
94 for (int i=0; i<nnames; ++i) {
95 std::string nm=names[i];
96 std::cout << nm << " Accumulator: "
97 << a[nm].mean<data_type>();
98 if (i!=0) {
99 std::cout << "+/-" << a[nm].error<data_type>();
100 }
101 std::cout <<"\nRaw print:" << a[nm]<<"\n";
102 std::cout <<"\nShort print:" << short_print(a[nm]) <<"\n";
103 std::cout <<"\nFull print:" << full_print(a[nm]) <<"\n";
104
105 std::cout << nm << " Result: "
106 << r[nm].mean<data_type>();
107 if (i!=0) {
108 std::cout << "+/-" << r[nm].error<data_type>();
109 }
110 std::cout << "\nRaw print:" << r[nm]<<"\n";
111 std::cout << "\nShort print:" << short_print(r[nm])<<"\n";
112 std::cout << "\nFull print:" << full_print(r[nm])<<"\n";
113 }
114 }
115