mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-06 07:21:31 +01:00
switch to git no-history version
This commit is contained in:
108
src/Math/testing/AccumulatorTest.cpp
Normal file
108
src/Math/testing/AccumulatorTest.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Math/Accumulator.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
#include <TRandom.h>
|
||||
|
||||
|
||||
//#include <boost/accumulators/framework/accumulator_set.hpp>
|
||||
//#include <boost/accumulators/statistics/count.hpp>
|
||||
//#include <boost/accumulators/accumulators.hpp>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int test_ABTrim() {
|
||||
|
||||
Accumulator_ABTrim<float> acc;
|
||||
|
||||
acc.SetABTrim(1,1);
|
||||
|
||||
Vector<float> v;
|
||||
v << 1,5,5,5,300;
|
||||
|
||||
for(Vector<float>::Iterator itr=v.begin(); itr<v.end(); itr++)
|
||||
acc += *itr;
|
||||
|
||||
std::cout << "Accumulating Trim(1,1) vector: "
|
||||
<< v << " ... out = " << acc() << "\n";
|
||||
|
||||
return( acc() == 15.0 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
int test_Mean() {
|
||||
Accumulator_Mean<float> mean;
|
||||
TRandom rnd;
|
||||
const int c = 10000000;
|
||||
Vector<float> v;
|
||||
v.reserve(c);
|
||||
for(int i=0;i<c;++i) v.push_back( rnd.Gaus(2000,5) );
|
||||
|
||||
float m = 0;
|
||||
for(int i=0;i<c;++i) m += v[i];
|
||||
m /= c;
|
||||
std::cout << "simple mean: " << m << "\n";
|
||||
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
mean.AddPass();
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
mean.AddPass();
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
mean.AddPass();
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
mean.AddPass();
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
mean.AddPass();
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
mean.AddPass();
|
||||
for(int i=0;i<c;++i) mean(v[i]);
|
||||
std::cout << "mean pass: " << mean() << "\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void) {
|
||||
BEGIN_TESTING(Accumulator);
|
||||
|
||||
//TEST1( test_ABTrim() );
|
||||
test_Mean();
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
Reference in New Issue
Block a user