source: sasview/sansmodels/test/utest_model_calculate_ER.py @ 18253cd

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 18253cd was 18e250c, checked in by Gervaise Alina <gervyh@…>, 13 years ago

move test to sansmodels top level

  • Property mode set to 100644
File size: 9.5 KB
Line 
1"""
2    Unit tests for calculate_ER of specific models
3    @author: JHJ Cho / UTK
4"""
5
6import unittest, time, math, numpy
7
8       
9class TestSphere(unittest.TestCase):
10    """ Unit tests for calculate_ER (sphere model) """
11   
12    def setUp(self):
13        from sans.models.SphereModel import SphereModel
14        self.comp = SphereModel()
15       
16    def test(self):
17        """ Test 1D model for a sphere """
18        self.comp.setParam("radius", 20)
19        self.assertAlmostEqual(self.comp.calculate_ER(), 20)
20       
21class TestCoreShell(unittest.TestCase):
22    """ Unit tests for calculate_ER (CoreShellModel) """
23   
24    def setUp(self):
25        from sans.models.CoreShellModel import CoreShellModel
26        self.comp = CoreShellModel()
27       
28    def test(self):
29        """ Test 1D model for a CoreShell """
30        self.comp.setParam("radius", 20)
31        self.comp.setParam("thickness", 20)
32        self.assertAlmostEqual(self.comp.calculate_ER(), 40)       
33         
34class TestMultiShell(unittest.TestCase):
35    """ Unit tests for calculate_ER (MultiShellModel) """
36   
37    def setUp(self):
38        from sans.models.MultiShellModel import MultiShellModel
39        self.comp = MultiShellModel()
40       
41    def test(self):
42        """ Test 1D model for a MultiShell """
43        self.comp.setParam("core_radius", 60)
44        self.comp.setParam("s_thickness", 10)
45        self.comp.setParam("w_thickness", 15)
46        self.comp.setParam("n_pairs", 2)
47        self.assertAlmostEqual(self.comp.calculate_ER(), 95)     
48
49class TestVesicle(unittest.TestCase):
50    """ Unit tests for calculate_ER (VesicleModel) """
51   
52    def setUp(self):
53        from sans.models.VesicleModel import VesicleModel
54        self.comp = VesicleModel()
55       
56    def test(self):
57        """ Test 1D model for a Vesicle """
58        self.comp.setParam("radius", 60)
59        self.comp.setParam("thickness", 30)
60        self.assertAlmostEqual(self.comp.calculate_ER(), 90)   
61
62class TestCylinder(unittest.TestCase):
63    """ Unit tests for calculate_ER (cylinder model) """
64   
65    def setUp(self):
66        from sans.models.CylinderModel import CylinderModel
67        from sans.models.DiamCylFunc import DiamCylFunc
68        self.comp = CylinderModel()
69        self.diam = DiamCylFunc()
70       
71    def test(self):
72        """ Test 1D model for a Cylinder """
73        self.comp.setParam("radius", 20)
74        self.comp.setParam("length",400)
75        self.diam.setParam("radius", 20)
76        self.diam.setParam("length",400)       
77        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) 
78         
79class TestCoreShellCylinder(unittest.TestCase):
80    """ Unit tests for calculate_ER (CoreShellcylinder model) """
81   
82    def setUp(self):
83        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel
84        from sans.models.DiamCylFunc import DiamCylFunc
85        self.comp = CoreShellCylinderModel()
86        self.diam = DiamCylFunc()
87       
88    def test(self):
89        """ Test 1D model for a CoreShellCylinder """
90        self.comp.setParam("radius", 20)
91        self.comp.setParam("thickness", 10)
92        self.comp.setParam("length",400)
93        self.diam.setParam("radius", 30)
94        self.diam.setParam("length",420)       
95        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
96
97class TestHollowCylinder(unittest.TestCase):
98    """ Unit tests for calculate_ER (Hollowcylinder model) """
99   
100    def setUp(self):
101        from sans.models.HollowCylinderModel import HollowCylinderModel
102        from sans.models.DiamCylFunc import DiamCylFunc
103        self.comp = HollowCylinderModel()
104        self.diam = DiamCylFunc()
105       
106    def test(self):
107        """ Test 1D model for a Hollowcylinder """
108        self.comp.setParam("radius", 20)
109        self.comp.setParam("length",400)
110        self.diam.setParam("radius", 20)
111        self.diam.setParam("length",400)       
112        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)       
113
114class TestStackedDisksModel(unittest.TestCase):
115    """ Unit tests for calculate_ER (StackedDisks model) """
116   
117    def setUp(self):
118        from sans.models.StackedDisksModel import StackedDisksModel
119        from sans.models.DiamCylFunc import DiamCylFunc
120        self.comp = StackedDisksModel()
121        self.diam = DiamCylFunc()
122       
123    def test(self):
124        """ Test 1D model for a StackedDisks """
125        self.comp.setParam("radius", 3000)
126        self.comp.setParam("n_stacking", 2)
127        self.comp.setParam("core_thick",10)
128        self.comp.setParam("layer_thick", 15)
129        self.diam.setParam("radius", 3000)
130        self.diam.setParam("length",80)       
131        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) 
132             
133class TestEllipticalCylinder(unittest.TestCase):
134    """ Unit tests for calculate_ER (EllipticalCylindermodel) """
135   
136    def setUp(self):
137        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel
138        from sans.models.DiamCylFunc import DiamCylFunc
139        self.comp = EllipticalCylinderModel()
140        self.diam = DiamCylFunc()
141       
142    def test(self):
143        """ Test 1D model for a EllipticalCylinder """
144        self.comp.setParam("r_minor", 20)
145        self.comp.setParam("r_ratio",1.5) 
146        self.comp.setParam("length",400) 
147        r_value = math.sqrt(20*20*1.5)   
148        self.diam.setParam("radius", r_value)
149        self.diam.setParam("length",400)       
150        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) 
151         
152class TestParallelepiped(unittest.TestCase):
153    """ Unit tests for calculate_ER (Parallelepipedmodel) """
154   
155    def setUp(self):
156        from sans.models.ParallelepipedModel import ParallelepipedModel
157        from sans.models.DiamCylFunc import DiamCylFunc
158        self.comp = ParallelepipedModel()
159        self.diam = DiamCylFunc()
160       
161    def test(self):
162        """ Test 1D model for a Parallelepiped """
163        self.comp.setParam("short_a", 35)
164        self.comp.setParam("short_b", 75) 
165        self.comp.setParam("long_c",400) 
166        r_value = math.sqrt(35*75/math.pi)   
167        self.diam.setParam("radius", r_value)
168        self.diam.setParam("length",400)   
169        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
170                                                 
171class TestEllipsoid(unittest.TestCase):
172    """ Unit tests for calculate_ER (Ellipsoid model) """
173   
174    def setUp(self):
175        from sans.models.EllipsoidModel import EllipsoidModel
176        from sans.models.DiamEllipFunc import DiamEllipFunc
177        self.comp = EllipsoidModel()
178        self.diam = DiamEllipFunc()
179       
180    def test(self):
181        """ Test 1D model for a Ellipsoid """
182        self.comp.setParam("radius_a", 20)
183        self.comp.setParam("radius_b",400)
184        self.diam.setParam("radius_a", 20)
185        self.diam.setParam("radius_b",400)       
186        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
187
188class TestCoreShellEllipsoid(unittest.TestCase):
189    """ Unit tests for calculate_ER (CoreShellEllipsoid model) """
190   
191    def setUp(self):
192        from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel
193        from sans.models.DiamEllipFunc import DiamEllipFunc
194        self.comp = CoreShellEllipsoidModel()
195        self.diam = DiamEllipFunc()
196       
197    def test(self):
198        """ Test 1D model for a CoreShellEllipsoid """
199        self.comp.setParam("polar_shell", 20)
200        self.comp.setParam("equat_shell",400)       
201        self.diam.setParam("radius_a", 20)
202        self.diam.setParam("radius_b",400)
203        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) 
204
205class TestTriaxialEllipsoid(unittest.TestCase):
206    """ Unit tests for calculate_ER (TriaxialEllipsoid model) """
207   
208    def setUp(self):
209        from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
210        from sans.models.DiamEllipFunc import DiamEllipFunc
211        self.comp = TriaxialEllipsoidModel()
212        self.diam = DiamEllipFunc()
213       
214    def test(self):
215        """ Test 1D model for a TriaxialEllipsoid """
216        self.comp.setParam("semi_axisA", 35)
217        self.comp.setParam("semi_axisB", 100)
218        self.comp.setParam("semi_axisC", 400) 
219        r_value = math.sqrt(35*100)   
220        self.diam.setParam("radius_a", 400)
221        self.diam.setParam("radius_b",r_value)
222        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) 
223                   
224class TestLamellar(unittest.TestCase):
225    """ Unit tests for calculate_ER (Lamellarmodel)"""
226   
227    def setUp(self):
228        from sans.models.LamellarModel import LamellarModel
229        self.comp = LamellarModel()
230       
231    def test(self):
232        """ Test 1D model for a Lamellar """
233        #No finite number should return from Lamellar models.
234        self.assertFalse(numpy.isfinite(self.comp.calculate_ER())) 
235         
236class TestGuinier(unittest.TestCase):
237    """ Unit tests for calculate_ER (Guinier model) """
238   
239    def setUp(self):
240        from sans.models.GuinierModel import GuinierModel
241        self.comp = GuinierModel()
242       
243    def test(self):
244        """ Test 1D model for Guinier """   
245        #calculate_ER() is not implemented for pure python model functions
246        self.assertEqual(self.comp.calculate_ER(), NotImplemented) 
247       
248if __name__ == '__main__':
249    unittest.main()
Note: See TracBrowser for help on using the repository browser.