source: sasview/sansmodels/src/sans/models/test/utest_model_calculate_ER.py @ f9bf661

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f9bf661 was ca90d54, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

Removed my name from a file a most definitely did not author.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1"""
2    Unit tests for specific models
3"""
4
5import unittest, time, math
6
7# Disable "missing docstring" complaint
8# pylint: disable-msg=C0111
9# Disable "too many methods" complaint
10# pylint: disable-msg=R0904
11# Disable "could be a function" complaint
12# pylint: disable-msg=R0201
13
14
15       
16class TestSphere(unittest.TestCase):
17    """ Unit tests for calculate_ER (sphere model) """
18   
19    def setUp(self):
20        from sans.models.SphereModel import SphereModel
21        self.comp = SphereModel()
22       
23    def test(self):
24        """ Test 1D model for a sphere """
25        self.comp.setParam("radius", 20)
26        self.assertAlmostEqual(self.comp.calculate_ER(), 20)
27       
28class TestCoreShell(unittest.TestCase):
29    """ Unit tests for calculate_ER (CoreShellModel) """
30   
31    def setUp(self):
32        from sans.models.CoreShellModel import CoreShellModel
33        self.comp = CoreShellModel()
34       
35    def test(self):
36        """ Test 1D model for a CoreShell """
37        self.comp.setParam("radius", 20)
38        self.comp.setParam("thickness", 20)
39        self.assertAlmostEqual(self.comp.calculate_ER(), 40)       
40         
41class TestMultiShell(unittest.TestCase):
42    """ Unit tests for calculate_ER (MultiShellModel) """
43   
44    def setUp(self):
45        from sans.models.MultiShellModel import MultiShellModel
46        self.comp = MultiShellModel()
47       
48    def test(self):
49        """ Test 1D model for a MultiShell """
50        self.comp.setParam("core_radius", 60)
51        self.comp.setParam("s_thickness", 10)
52        self.comp.setParam("w_thickness", 15)
53        self.comp.setParam("n_pairs", 2)
54        self.assertAlmostEqual(self.comp.calculate_ER(), 95)     
55
56class TestVesicle(unittest.TestCase):
57    """ Unit tests for calculate_ER (VesicleModel) """
58   
59    def setUp(self):
60        from sans.models.VesicleModel import VesicleModel
61        self.comp = VesicleModel()
62       
63    def test(self):
64        """ Test 1D model for a Vesicle """
65        self.comp.setParam("radius", 60)
66        self.comp.setParam("thickness", 30)
67        self.assertAlmostEqual(self.comp.calculate_ER(), 90)   
68
69class TestCylinder(unittest.TestCase):
70    """ Unit tests for calculate_ER (cylinder model) """
71   
72    def setUp(self):
73        from sans.models.CylinderModel import CylinderModel
74        from sans.models.DiamCylFunc import DiamCylFunc
75        self.comp = CylinderModel()
76        self.diam = DiamCylFunc()
77       
78    def test(self):
79        """ Test 1D model for a Cylinder """
80        self.comp.setParam("radius", 20)
81        self.comp.setParam("length",400)
82        self.diam.setParam("radius", 20)
83        self.diam.setParam("length",400)       
84        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) 
85         
86class TestCoreShellCylinder(unittest.TestCase):
87    """ Unit tests for calculate_ER (CoreShellcylinder model) """
88   
89    def setUp(self):
90        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel
91        from sans.models.DiamCylFunc import DiamCylFunc
92        self.comp = CoreShellCylinderModel()
93        self.diam = DiamCylFunc()
94       
95    def test(self):
96        """ Test 1D model for a CoreShellCylinder """
97        self.comp.setParam("radius", 20)
98        self.comp.setParam("thickness", 10)
99        self.comp.setParam("length",400)
100        self.diam.setParam("radius", 30)
101        self.diam.setParam("length",400)       
102        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
103
104class TestHollowCylinder(unittest.TestCase):
105    """ Unit tests for calculate_ER (Hollowcylinder model) """
106   
107    def setUp(self):
108        from sans.models.HollowCylinderModel import HollowCylinderModel
109        from sans.models.DiamCylFunc import DiamCylFunc
110        self.comp = HollowCylinderModel()
111        self.diam = DiamCylFunc()
112       
113    def test(self):
114        """ Test 1D model for a Hollowcylinder """
115        self.comp.setParam("radius", 20)
116        self.comp.setParam("length",400)
117        self.diam.setParam("radius", 20)
118        self.diam.setParam("length",400)       
119        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)       
120
121class TestStackedDisksModel(unittest.TestCase):
122    """ Unit tests for calculate_ER (StackedDisks model) """
123   
124    def setUp(self):
125        from sans.models.StackedDisksModel import StackedDisksModel
126        from sans.models.DiamCylFunc import DiamCylFunc
127        self.comp = StackedDisksModel()
128        self.diam = DiamCylFunc()
129       
130    def test(self):
131        """ Test 1D model for a StackedDisks """
132        self.comp.setParam("radius", 3000)
133        self.comp.setParam("n_stacking", 2)
134        self.comp.setParam("core_thick",10)
135        self.comp.setParam("layer_thick", 15)
136        self.diam.setParam("radius", 3000)
137        self.diam.setParam("length",80)       
138        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)       
139
140class TestEllipsoid(unittest.TestCase):
141    """ Unit tests for calculate_ER (Ellipsoid model) """
142   
143    def setUp(self):
144        from sans.models.EllipsoidModel import EllipsoidModel
145        from sans.models.DiamEllipFunc import DiamEllipFunc
146        self.comp = EllipsoidModel()
147        self.diam = DiamEllipFunc()
148       
149    def test(self):
150        """ Test 1D model for a Ellipsoid """
151        self.comp.setParam("radius_a", 20)
152        self.comp.setParam("radius_b",400)
153        self.diam.setParam("radius_a", 20)
154        self.diam.setParam("radius_b",400)       
155        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
156
157class TestCoreShellEllipsoid(unittest.TestCase):
158    """ Unit tests for calculate_ER (CoreShellEllipsoid model) """
159   
160    def setUp(self):
161        from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel
162        from sans.models.DiamEllipFunc import DiamEllipFunc
163        self.comp = CoreShellEllipsoidModel()
164        self.diam = DiamEllipFunc()
165       
166    def test(self):
167        """ Test 1D model for a CoreShellEllipsoid """
168        self.comp.setParam("polar_shell", 20)
169        self.comp.setParam("equat_shell",400)       
170        self.diam.setParam("radius_a", 20)
171        self.diam.setParam("radius_b",400)
172        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)                     
173if __name__ == '__main__':
174    unittest.main()
Note: See TracBrowser for help on using the repository browser.