Skip to content

Commit

Permalink
Added unit test Re #12541
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Jun 17, 2015
1 parent c18f4a2 commit 9cad93f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set ( TEST_PY_FILES
MolDynTest.py
MSDFitTest.py
PDDetermineCharacterizationsTest.py
ResNormTest.py
RetrieveRunInfoTest.py
SANSWideAngleCorrectionTest.py
SavePlot1DTest.py
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import unittest
from mantid.simpleapi import *
from mantid.api import MatrixWorkspace, WorkspaceGroup


class ResNormTest(unittest.TestCase):

_res_ws = None
_van_ws = None


def setUp(self):
self._res_ws = Load(Filename='irs26173_graphite002_res.nxs',
OutputWorkspace='__ResNormTest_Resolution')
self._van_ws = Load(Filename='irs26173_graphite002_red.nxs',
OutputWorkspace='__ResNormTest_Vanadium')


def _validate_result(self, result):
"""
Validates that the result workspace is of the correct type, units and shape.
@param result Result workspace form ResNorm
"""

self.assertTrue(isinstance(result, WorkspaceGroup))
self.assertEquals(result.getNumberOfEntries(), 2)

expected_names = [result.name() + '_' + n for n in ['Intensity', 'Stretch']]
for name in expected_names:
self.assertTrue(name in result.getNames())

for idx in range(result.getNumberOfEntries()):
sub_ws = result.getItem(idx)
self.assertTrue(isinstance(sub_ws, MatrixWorkspace))
self.assertEqual(sub_ws.blocksize(), self._van_ws.getNumberHistograms())
self.assertEquals(sub_ws.getAxis(0).getUnit().unitID(), 'MomentumTransfer')


def test_basic(self):
"""
Tests a basic run of ResNorm.
"""
result = ResNorm(ResolutionWorkspace=self._res_ws,
VanadiumWorkspace=self._van_ws)
self._validate_result(result)


def test_with_limits(self):
"""
Tests a basic run of ResNorm with energy limits.
"""
result = ResNorm(ResolutionWorkspace=self._res_ws,
VanadiumWorkspace=self._van_ws,
EnergyMin=-0.1,
EnergyMax=0.1)
self._validate_result(result)


def test_with_bad_limits(self):
"""
Tests validation for energy range.
"""
self.assertRaises(RuntimeError, ResNorm,
ResolutionWorkspace=self._res_ws,
VanadiumWorkspace=self._van_ws,
EnergyMin=0.1,
EnergyMax=-0.1)


if __name__=="__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f52ac64ec23fb50b6d4649592aee4fdb

0 comments on commit 9cad93f

Please sign in to comment.