# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus # # MAUS is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # MAUS is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with MAUS. If not, see . """ Test maus_cpp.material """ import StringIO import unittest import Configuration import maus_cpp.material import maus_cpp.globals class MaterialTestCase(unittest.TestCase): # pylint: disable=R0904 """Test maus_cpp.field""" def setUp(self): # pylint: disable=C0103 """Set up test""" self.test_config = "" if maus_cpp.globals.has_instance(): maus_cpp.globals.death() config_options = StringIO.StringIO(u"") self.config = Configuration.Configuration().getConfigJSON( config_options, False) maus_cpp.globals.birth(self.config) def tearDown(self): # pylint: disable = C0103 """Reset the globals""" if maus_cpp.globals.has_instance(): maus_cpp.globals.death() def test_position(self): """Test maus_cpp.material.get_position()/set_position(...)/step(...)""" maus_cpp.material.set_position(1, 2, 3) pos = maus_cpp.material.get_position() self.assertAlmostEqual(pos[0], 1., 1e-9) self.assertAlmostEqual(pos[1], 2., 1e-9) self.assertAlmostEqual(pos[2], 3., 1e-9) maus_cpp.material.step(4, 5, 6) pos = maus_cpp.material.get_position() self.assertAlmostEqual(pos[0], 5., 1e-9) self.assertAlmostEqual(pos[1], 7., 1e-9) self.assertAlmostEqual(pos[2], 9., 1e-9) def test_get_material(self): """Test maus_cpp.material.get_material()""" maus_cpp.material.set_position(1, 2, 3) mat = maus_cpp.material.get_material_data() ref_float = { 'A': 1.0079407526651407, 'density':0.0708, 'radlen': 890.4450575478568, 'interlen': 498.2757962825731, 'Z': 1.0 } ref_string = { 'volume':'Box', 'name': 'G4_lH2' } self.assertEqual(sorted(ref_string.keys()+ref_float.keys()), sorted(mat.keys())) # because the MICE geometry can change, I just check the type; I don't # particularly want to debug the MICE geometry... for key, value in ref_string.iteritems(): self.assertEqual(type(value), type(mat[key])) for key, value in ref_float.iteritems(): self.assertEqual(type(value), type(mat[key])) if __name__ == "__main__": unittest.main()