Skip to content

Commit

Permalink
Refs #4713 test for SaveHKL
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Feb 1, 2012
1 parent 41b77ee commit aa6f8df
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Crystal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set ( TEST_FILES
test/PeakIntegrationTest.h
test/PeakIntensityVsRadiusTest.h
test/PredictPeaksTest.h
test/SaveHKLTest.h
test/SaveIsawPeaksTest.h
test/SaveIsawUBTest.h
test/SavePeaksFileTest.h
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/Crystal/src/SaveHKL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ namespace Crystal

// Sequence and run number
int seqNum = 1;
int firstrun = peaks[0].getRunNumber();
int firstrun = 0;
if(peaks.size()>0) firstrun = peaks[0].getRunNumber();

std::fstream out;
bool append = getProperty("AppendFile");
Expand Down
91 changes: 91 additions & 0 deletions Code/Mantid/Framework/Crystal/test/SaveHKLTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#ifndef MANTID_CRYSTAL_SAVEHKLTEST_H_
#define MANTID_CRYSTAL_SAVEHKLTEST_H_

#include "MantidCrystal/SaveHKL.h"
#include "MantidDataObjects/Peak.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/IDTypes.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include <Poco/File.h>

using namespace Mantid;
using namespace Mantid::Crystal;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;

class SaveHKLTest : public CxxTest::TestSuite
{
public:

void test_Init()
{
SaveHKL alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}

void do_test(int numRuns, size_t numBanks, size_t numPeaksPerBank)
{
Instrument_sptr inst = ComponentCreationHelper::createTestInstrumentRectangular(4, 10, 1.0);
PeaksWorkspace_sptr ws(new PeaksWorkspace());
ws->setInstrument(inst);

for (int run=1000; run<numRuns+1000; run++)
for (size_t b=1; b<=numBanks; b++)
for (size_t i=0; i<numPeaksPerBank; i++)
{
V3D hkl(static_cast<double>(i), static_cast<double>(i), static_cast<double>(i));
DblMatrix gon(3,3, true);
Peak p(inst, static_cast<detid_t>(b*100 + i+1+i*10), static_cast<double>(i)*1.0+0.5, hkl, gon);
p.setRunNumber(run);
p.setBankName("bank1");
p.setIntensity( static_cast<double>(i)+0.1);
p.setSigmaIntensity( sqrt(static_cast<double>(i)));
p.setBinCount( static_cast<double>(i) );
ws->addPeak(p);
}

std::string outfile = "./SaveHKLTest.hkl";
SaveHKL alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setProperty("InputWorkspace", ws) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Filename", outfile) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("LinearScatteringCoef", 0.357) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("LinearAbsorptionCoef", 0.011) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("Radius", 0.1) );
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );

// Get the file
outfile = alg.getPropertyValue("Filename");
TS_ASSERT( Poco::File(outfile).exists() );
if (Poco::File(outfile).exists())
Poco::File(outfile).remove();
}

/// Test with an empty PeaksWorkspace
void test_empty()
{
do_test(0,0,0);
}

/// Test with a few peaks
void test_exec()
{
do_test(2, 4,4);
}


};


#endif /* MANTID_CRYSTAL_SAVEHKLTEST_H_ */

0 comments on commit aa6f8df

Please sign in to comment.