Skip to content
Snippets Groups Projects
RebinHistogramTest.h 1.77 KiB
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()
  {
  	xin.resize(size1);
  	yin.resize(size1-1);
  	ein.resize(size1-1);
  	xout.resize(size2);
  	yout.resize(size2-1);
  	eout.resize(size2-1);
  	{
  		xin[i]=(double)(i);
  		yin[i]=1.0;
  		ein[i]=1.0;
  	}
  	xin[size1-1]=size1-1;
  	VectorHelper::rebinHistogram(xin,yin,ein,xout,yout,eout,false);
  	{
  		TS_ASSERT_DELTA(yout[i],0.5,1e-7);
  		TS_ASSERT_DELTA(eout[i],1.0/sqrt(2.0),1e-7);
  	}
  	std::vector<double> returnX(xin), returnY(size1-1), returnE(size1-1);
  	VectorHelper::rebinHistogram(xout,yout,eout,returnX,returnY,returnE,false);
  	{
  	  TS_ASSERT_DELTA(returnY[i],yin[i],1e-7);
  	  TS_ASSERT_DELTA(returnE[i],ein[i],1e-7);
  	}