Skip to content

Commit

Permalink
Added more unit tests, fixed an issue with Elastic mode
Browse files Browse the repository at this point in the history
Refs #11188
  • Loading branch information
DanNixon committed Mar 2, 2015
1 parent 6a82cb8 commit 597e400
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Expand Up @@ -76,12 +76,12 @@ def PyInit(self):
doc='Scale factor to multiply can data')

self.declareProperty(name='NumberWavelengths', defaultValue=10,
validator=IntBoundedValidator(0),
validator=IntBoundedValidator(1),
doc='Number of wavelengths for calculation')
self.declareProperty(name='Emode', defaultValue='Elastic',
validator=StringListValidator(['Elastic', 'Indirect']),
doc='Emode: Elastic or Indirect')
self.declareProperty(name='Efixed', defaultValue=0.0,
self.declareProperty(name='Efixed', defaultValue=1.0,
doc='Analyser energy')

self.declareProperty(WorkspaceGroupProperty('OutputWorkspace', '',
Expand Down Expand Up @@ -225,7 +225,7 @@ def _wave_range(self):
self._waves.append(wave_min + idx * wave_bin)

if self._emode == 'Elastic':
self._elastic = waves[int(number_waves / 2)]
self._elastic = self._waves[int(number_waves / 2)]
elif self._emode == 'Indirect':
self._elastic = math.sqrt(81.787 / self._efixed) # elastic wavelength

Expand Down
Expand Up @@ -15,7 +15,7 @@ set ( TEST_PY_FILES
DSFinterpTest.py
FilterLogByTimeTest.py
FindReflectometryLinesTest.py
FlatPlatePaalmanPIngsCorrectionTest.py
FlatPlatePaalmanPingsCorrectionTest.py
GetEiT0atSNSTest.py
IndirectILLReductionTest.py
InelasticIndirectReductionTest.py
Expand Down
Expand Up @@ -32,7 +32,9 @@ def tearDown(self):

DeleteWorkspace(self._sample_ws)
DeleteWorkspace(self._can_ws)
DeleteWorkspace(self._corrections_ws_name)

if self._corrections_ws_name in mtd:
DeleteWorkspace(self._corrections_ws_name)


def _verify_workspace(self, ws_name):
Expand Down Expand Up @@ -116,5 +118,38 @@ def test_sampleAndCan(self):
self._verify_workspaces_for_can()


def test_sampleAndCanDefaults(self):
"""
Test simple run with sample and can workspace using the default values.
"""

FlatPlatePaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name,
SampleWorkspace=self._sample_ws,
SampleChemicalFormula='H2-O',
CanWorkspace=self._can_ws,
CanChemicalFormula='V')

self._verify_workspaces_for_can()


def test_validationNoCanFormula(self):
"""
Tests validation for no chemical formula for can when a can WS is provided.
"""

with self.assertRaises(RuntimeError):
FlatPlatePaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name,
SampleWorkspace=self._sample_ws,
SampleChemicalFormula='H2-O',
SampleThickness=0.1,
SampleAngle=45,
CanWorkspace=self._can_ws,
CanFrontThickness=0.1,
CanBackThickness=0.1,
NumberWavelengths=10,
Emode='Indirect',
Efixed=1.845)


if __name__=="__main__":
unittest.main()

0 comments on commit 597e400

Please sign in to comment.