Skip to content

Commit

Permalink
refs #7358 Fix the test failures
Browse files Browse the repository at this point in the history
Specifically, one of the ouput properies was not being set.
Unit tests checks of the output properties have been added.
The failure of the example was due to a change made by Pete in a previous ticket, but I've update the help text.
  • Loading branch information
NickDraper committed Jun 28, 2013
1 parent ab0ebab commit 1065a8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Neutron scattering lengths and cross sections of the elements and their isotopes
=====Setting the sample by a more complex formula=====
SetSampleMaterial(InputWorkspace='IRS26173',ChemicalFormula='Al2-O3', UnitCellVolume='253.54', ZParameter='6')
=====Setting the sample by specific values (all three must be specified)=====
SetSampleMaterial(InputWorkspace='IRS26173',AttenuationXSection=2.56,ScatteringXSection=11.62,SampleNumberDensity=0.0849106)
=====Setting the sample by specific values=====
SetSampleMaterial(InputWorkspace='IRS26173',AtomicNumber=26,AttenuationXSection=2.56,ScatteringXSection=11.62,SampleNumberDensity=0.0849106)
=====Extracting the set values out by python=====
sam = ws.sample()
Expand Down Expand Up @@ -312,7 +312,8 @@ namespace DataHandling
<< " Incoherent " << mat->incohScatterXSection() << " barns\n"
<< " Total " << mat->totalScatterXSection() << " barns\n"
<< " Absorption " << mat->absorbXSection() << " barns\n";
setProperty("IncoherentXSectionResult", mat->incohScatterXSection()); // in barns
setProperty("CoherentXSectionResult", mat->cohScatterXSection()); // in barns
setProperty("IncoherentXSectionResult", mat->incohScatterXSection()); // in barns
setProperty("TotalXSectionResult",mat->totalScatterXSection()); // in barns
setProperty("AbsorptionXSectionResult",mat->absorbXSection()); // in barns
setProperty("ReferenceWavelength",NeutronAtom::ReferenceLambda); // in Angstroms
Expand Down
27 changes: 23 additions & 4 deletions Code/Mantid/Framework/DataHandling/test/SetSampleMaterialTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SetSampleMaterialTest : public CxxTest::TestSuite

void testExec()
{
std::string wsName = "SetSampleMaterialTestWS";
std::string wsName = "SetSampleMaterialTestWS";
IAlgorithm* setmat = Mantid::API::FrameworkManager::Instance().createAlgorithm("SetSampleMaterial");
if ( !setmat->isInitialized() ) setmat->initialize();

Expand All @@ -52,7 +52,7 @@ class SetSampleMaterialTest : public CxxTest::TestSuite
// Register the workspace in the data service
AnalysisDataService::Instance().add(wsName, testWS);

TS_ASSERT_THROWS_NOTHING( setmat->setPropertyValue("InputWorkspace", wsName) );
TS_ASSERT_THROWS_NOTHING( setmat->setPropertyValue("InputWorkspace", wsName) );
TS_ASSERT_THROWS_NOTHING( setmat->setPropertyValue("ChemicalFormula","Al2-O3") );
TS_ASSERT_THROWS_NOTHING( setmat->setPropertyValue("SampleNumberDensity","0.0236649") );
TS_ASSERT_THROWS_NOTHING( setmat->setPropertyValue("ScatteringXSection","15.7048") );
Expand All @@ -66,7 +66,9 @@ class SetSampleMaterialTest : public CxxTest::TestSuite
TS_ASSERT_DELTA( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda), 15.7048, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda), 0.46257, 0.0001);

AnalysisDataService::Instance().remove(wsName);
checkOutputProperties(setmat,m_sampleMaterial);

AnalysisDataService::Instance().remove(wsName);

}
void testExecMat_Formula()
Expand Down Expand Up @@ -95,10 +97,27 @@ class SetSampleMaterialTest : public CxxTest::TestSuite
TS_ASSERT_DELTA( m_sampleMaterial->numberDensity(), 0.0236649, 0.0001 );
TS_ASSERT_DELTA( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda), 3.1404, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda), 0.0925, 0.0001);


checkOutputProperties(setmat,m_sampleMaterial);

AnalysisDataService::Instance().remove(wsName);
}

void checkOutputProperties(const IAlgorithm* alg,const Material *material)
{
//test output properties
double testvalue = alg->getProperty("AbsorptionXSectionResult");
TS_ASSERT_DELTA(material->absorbXSection(), testvalue, 0.0001);
testvalue = alg->getProperty("CoherentXSectionResult");
TS_ASSERT_DELTA(material->cohScatterXSection(), testvalue, 0.0001);
testvalue = alg->getProperty("IncoherentXSectionResult");
TS_ASSERT_DELTA(material->incohScatterXSection(), testvalue, 0.0001);
testvalue = alg->getProperty("TotalXSectionResult");
TS_ASSERT_DELTA(material->totalScatterXSection(), testvalue, 0.0001);
testvalue = alg->getProperty("SampleNumberDensityResult");
TS_ASSERT_DELTA(material->numberDensity(), testvalue, 0.0001);
}

};

#endif /*SetSampleMaterialTEST_H_*/

0 comments on commit 1065a8b

Please sign in to comment.