Newer
Older
#ifndef REBINHISTOGRAM_TEST_H_
#define REBINHISTOGRAM_TEST_H_
#include <cxxtest/TestSuite.h>
#include <vector>
#include "MantidKernel/VectorHelper.h"
using namespace Mantid::Kernel;
/// @author Laurent C Chapon, ISIS Facility, Rutherford Appleton Laboratory
/// 13/03/2009
/// This is testing the validity of the rebinHistogram function in vectorHelper Class
class RebinHistogramTest : public CxxTest::TestSuite
{
public:
/// Size of vectors
int size1, size2;
/// Some vectors
std::vector<double> xin,yin,ein,xout,yout,eout;
RebinHistogramTest(){}
/// Create a new X vector where the steps are half the size of the old one.
/// Perform rebin and check the values
/// Y data should now contains half the intensity
/// E data should contains the
/// Perform another rebin in the opposite direction and check that the data are identical to initial values
void TestRebinSmallerSteps()
{
Russell Taylor
committed
size1=12;size2=23;
xin.resize(size1);
yin.resize(size1-1);
ein.resize(size1-1);
xout.resize(size2);
yout.resize(size2-1);
eout.resize(size2-1);
Peterson, Peter
committed
for (std::size_t i=0;i<size1-1;i++)
{
xin[i]=(double)(i);
yin[i]=1.0;
ein[i]=1.0;
}
xin[size1-1]=size1-1;
Peterson, Peter
committed
for (std::size_t i=0;i<size2;i++)
VectorHelper::rebinHistogram(xin,yin,ein,xout,yout,eout,false);
Peterson, Peter
committed
for (std::size_t i=0;i<size2-1;i++)
{
TS_ASSERT_DELTA(yout[i],0.5,1e-7);
TS_ASSERT_DELTA(eout[i],1.0/sqrt(2.0),1e-7);
}
Russell Taylor
committed
std::vector<double> returnX(xin), returnY(size1-1), returnE(size1-1);
Russell Taylor
committed
VectorHelper::rebinHistogram(xout,yout,eout,returnX,returnY,returnE,false);
Peterson, Peter
committed
for (std::size_t i=0;i<size1-1;i++)
Russell Taylor
committed
{
TS_ASSERT_DELTA(returnY[i],yin[i],1e-7);
TS_ASSERT_DELTA(returnE[i],ein[i],1e-7);
}
}
};
#endif //REBINHISTOGRAM_TEST_H_/