source: sasview/sansmodels/src/sans/models/test/utest_other_models.py @ c1e865a

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 c1e865a was 9ce41c6, checked in by Gervaise Alina <gervyh@…>, 15 years ago

wrote unittest for all model untested , haven' test critial point error handling

  • Property mode set to 100644
File size: 68.6 KB
Line 
1"""
2    Unit tests for specific models.
3    @since: 08/25/2009
4    @note:  The models are running also with numpy array as input.
5            Some models return limit of the function at critical point .
6            So the user should expect finite value for some critical points.
7            Initial values for models are given as the one of Igo software.
8    @author: Gervaise Alina / UTK
9"""
10
11import unittest
12import numpy 
13import math
14
15class TestCoreShell(unittest.TestCase):
16    """ Unit tests for coreshell model """
17   
18    def setUp(self):
19        from sans.models.CoreShellModel import CoreShellModel
20        self.comp = CoreShellModel()
21        #Give initial value to model
22        self.comp.setParam("scale", 1.0)
23        self.comp.setParam("radius", 60.0)
24        self.comp.setParam("thickness", 10.0)
25        self.comp.setParam("core_sld", 1.0e-6)
26        self.comp.setParam("shell_sld",2.0e-6)
27        self.comp.setParam("solvent_sld",3.0e-6)
28        self.comp.setParam("Background", 0.001)
29   
30        self.x = numpy.array([0.4, 1.3])
31        self.y = numpy.array([0.5, 1.57])
32        self.x_array = self.comp.evalDistribution(self.x)
33        self.y_array = self.comp.evalDistribution(self.y)
34        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
35        qy_prime = numpy.reshape(self.y, [len(self.y),1])
36        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
37       
38    def test1D(self):
39        """ Test 1D model for a coreshell """
40        self.assertAlmostEquals(self.comp.run(0.4),0.00169, 4)
41       
42    def test1D_2(self):
43        """ Test 2D model for a coreshell """
44        self.assertAlmostEquals(self.comp.run([0.4, 1.3]),0.00169, 4)
45       
46    def testEval_1D(self):
47        """ Test 1D model for a coreshell  with evalDistribution"""
48        self.assertEquals(self.comp.run(0.4),self.x_array[0])
49        self.assertEquals(self.comp.run(1.3),self.x_array[1])
50       
51    def testEval_2D(self):
52        """ Test 2D model for a coreshell  with evalDistribution"""
53        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
54        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
55        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
56        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
57       
58       
59 
60class TestMultiShellModel(unittest.TestCase):
61    """ Unit tests for MultiShell Model """
62   
63    def setUp(self):
64        from sans.models.MultiShellModel import MultiShellModel
65        self.comp = MultiShellModel()
66        #Give initial value to model
67        self.comp.setParam("scale", 1.0)
68        self.comp.setParam("core_radius", 60.0)
69        self.comp.setParam("s_thickness", 10.0)
70        self.comp.setParam("w_thickness",10.0 )
71        self.comp.setParam("core_sld",6.4e-6)
72        self.comp.setParam("shell_sld",4e-7)
73        self.comp.setParam("n_pairs", 2)
74        self.comp.setParam("Background", 0.001)
75       
76        self.x = numpy.array([0.4, 1.3])
77        self.y = numpy.array([0.5, 1.57])
78        self.x_array = self.comp.evalDistribution(self.x)
79        self.y_array = self.comp.evalDistribution(self.y)
80        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
81        qy_prime = numpy.reshape(self.y, [len(self.y),1])
82        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
83       
84    def test1D(self):
85        """ Test 1D model for a MultiShell Model """
86        self.assertAlmostEquals(self.comp.run(0.001), 2442.81, 2)
87       
88    def test1D_2(self):
89        """ Test 2D model for a MultiShell Model"""
90        self.assertAlmostEquals(self.comp.run([0.001, 0.30903]), 2442.81, 2)
91     
92    def testEval_1D(self):
93        """ Test 1D model for a MultiShell  with evalDistribution"""
94        self.assertEquals(self.comp.run(0.4),self.x_array[0])
95        self.assertEquals(self.comp.run(1.3),self.x_array[1])
96       
97    def testEval_2D(self):
98        """ Test 2D model for a MultiShell  with evalDistribution"""
99        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
100        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
101        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
102        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
103   
104   
105class TestVesicleModel(unittest.TestCase):
106    """ Unit tests for Vesicle Model """
107   
108    def setUp(self):
109        from sans.models.VesicleModel import VesicleModel
110        self.comp = VesicleModel()
111        #Give initial value to model
112        self.comp.setParam("scale", 1.0)
113        self.comp.setParam("radius", 100.0)
114        self.comp.setParam("core_sld", 6.36e-6)
115        self.comp.setParam("shell_sld",5e-7)
116        self.comp.setParam("thickness",30.0 )
117        self.comp.setParam("Background", 0.001)
118       
119        self.x = numpy.array([0.4, 1.3])
120        self.y = numpy.array([0.5, 1.57])
121        self.x_array = self.comp.evalDistribution(self.x)
122        self.y_array = self.comp.evalDistribution(self.y)
123        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
124        qy_prime = numpy.reshape(self.y, [len(self.y),1])
125        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
126       
127    def test1D(self):
128        """ Test 1D model for a Vesicle Model """
129        self.assertAlmostEquals(self.comp.run(0.001), 1.71399e4,1)
130       
131    def test1D_2(self):
132        """ Test 2D model for a Vesicle Model"""
133        self.assertAlmostEquals(self.comp.run([0.001, 1.3]), 1.71399e4,1)
134       
135    def testEval_1D(self):
136        """ Test 1D model for a Vesicle with evalDistribution"""
137        self.assertEquals(self.comp.run(0.4),self.x_array[0])
138        self.assertEquals(self.comp.run(1.3),self.x_array[1])
139       
140    def testEval_2D(self):
141        """ Test 2D model for a Vesicle with evalDistribution"""
142        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
143        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
144        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
145        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
146   
147     
148class TestBinaryHSModel(unittest.TestCase):
149    """ Unit tests for BinaryHS Model"""
150   
151    def setUp(self):
152        from sans.models.BinaryHSModel import BinaryHSModel
153        self.comp = BinaryHSModel()
154        #Give initial value to model
155        self.comp.setParam("l_radius", 100.0)
156        self.comp.setParam("ls_sld", 3.5e-6)
157        self.comp.setParam("s_radius",25)
158        self.comp.setParam("solvent_sld",6.36e-6 )
159        self.comp.setParam("ss_sld", 5e-7)
160        self.comp.setParam("vol_frac_ss", 0.1)
161        self.comp.setParam("vol_frac_ls", 0.2)
162        self.comp.setParam("Background", 0.001)
163       
164        self.x = numpy.array([0.4, 1.3])
165        self.y = numpy.array([0.5, 1.57])
166        self.x_array = self.comp.evalDistribution(self.x)
167        self.y_array = self.comp.evalDistribution(self.y)
168        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
169        qy_prime = numpy.reshape(self.y, [len(self.y),1])
170        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
171       
172    def test1D(self):
173        """ Test 1D model for a BinaryHS Model"""
174        self.assertAlmostEquals(self.comp.run(0.001),60.6785, 4)
175       
176    def test1D_2(self):
177        """ Test 2D model for a BinaryHS Model"""
178        self.assertAlmostEquals(self.comp.run([0.001, 1.3]),60.6785, 4)
179     
180    def testEval_1D(self):
181        """ Test 1D model for a BinaryHS with evalDistribution"""
182        self.assertEquals(self.comp.run(0.4),self.x_array[0])
183        self.assertEquals(self.comp.run(1.3),self.x_array[1])
184       
185    def testEval_2D(self):
186        """ Test 2D model for a BinaryHS with evalDistribution"""
187        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
188        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
189        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
190        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
191     
192     
193class TestCoreShellCylinderModel(unittest.TestCase):
194    """ Unit tests for CoreShellCylinder Model"""
195   
196    def setUp(self):
197        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel
198        self.comp = CoreShellCylinderModel()
199        #Give initial value to model
200        self.comp.setParam("scale", 1.0)
201        self.comp.setParam("core_sld", 1e-6)
202        self.comp.setParam("length", 400)
203        self.comp.setParam("radius",20)
204        self.comp.setParam("solvent_sld",1e-6 )
205        self.comp.setParam("shell_sld", 4e-6)
206        self.comp.setParam("thickness", 10.0)
207        self.comp.setParam("Background", 0.01)
208       
209        self.x = numpy.array([0.4, 1.3])
210        self.y = numpy.array([0.5, 1.57])
211        self.x_array = self.comp.evalDistribution(self.x)
212        self.y_array = self.comp.evalDistribution(self.y)
213       
214        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
215        qy_prime = numpy.reshape(self.y, [len(self.y),1])
216        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
217       
218        self.q = 0.001
219        self.phi= math.pi/2
220        self.qx= self.q*math.cos(self.phi)
221        self.qy= self.q*math.sin(self.phi)
222       
223    def test1D(self):
224        """ Test 1D model for a CoreShellCylinder Model"""
225        self.assertAlmostEqual(self.comp.run(0.001), 353.56,1)
226       
227    def test1D_2(self):
228        """ Test 2D model for a CoreShellCylinder Model"""
229        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
230                              self.comp.runXY([self.qx, self.qy]),1)
231       
232    def testEval_1D(self):
233        """ Test 1D model for a CoreShellCylinder with evalDistribution"""
234        self.assertEquals(self.comp.run(0.4),self.x_array[0])
235        self.assertEquals(self.comp.run(1.3),self.x_array[1])
236       
237    def testEval_2D(self):
238        """ Test 2D model for a CoreShellCylinder with evalDistribution"""
239        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
240        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
241        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
242        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
243 
244 
245class TestHollowCylinderModel(unittest.TestCase):
246    """ Unit tests for HollowCylinder Model"""
247   
248    def setUp(self):
249        from sans.models.HollowCylinderModel import HollowCylinderModel
250        self.comp = HollowCylinderModel()
251        #Give initial value to model
252        self.comp.setParam("scale", 1.0)
253        self.comp.setParam("core_radius",20.0)
254        self.comp.setParam("radius",30)
255        self.comp.setParam("length", 400)
256        self.comp.setParam("contrast",5.3e-6 )
257        self.comp.setParam("Background", 0.01)
258       
259        self.x = numpy.array([0.4, 1.3])
260        self.y = numpy.array([0.5, 1.57])
261        self.x_array = self.comp.evalDistribution(self.x)
262        self.y_array = self.comp.evalDistribution(self.y)
263        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
264        qy_prime = numpy.reshape(self.y, [len(self.y),1])
265        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
266       
267        self.q = 0.001
268        self.phi= math.pi/2
269        self.qx= self.q*math.cos(self.phi)
270        self.qy= self.q*math.sin(self.phi)
271       
272    def test1D(self):
273        """ Test 1D model for a HollowCylinder Model"""
274        self.assertAlmostEqual(self.comp.run(0.001), 1756.76, 1)
275       
276    def test1D_2(self):
277        """ Test 2D model for a HollowCylinder Model"""
278        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
279                              self.comp.runXY([self.qx, self.qy]),1) 
280 
281    def testEval_1D(self):
282        """ Test 1D model for a HollowCylinder with evalDistribution"""
283        self.assertEquals(self.comp.run(0.4),self.x_array[0])
284        self.assertEquals(self.comp.run(1.3),self.x_array[1])
285       
286    def testEval_2D(self):
287        """ Test 2D model for a HollowCylinder with evalDistribution"""
288        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
289        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
290        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
291        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
292       
293       
294class TestFlexibleCylinderModel(unittest.TestCase):
295    """ Unit tests for FlexibleCylinder Model"""
296   
297    def setUp(self):
298        from sans.models.FlexibleCylinderModel import FlexibleCylinderModel
299        self.comp = FlexibleCylinderModel()
300        #Give initial value to model
301        self.comp.setParam("scale", 1.0)
302        self.comp.setParam("contrast",5.3e-6 )
303        self.comp.setParam("kuhn_length",100)
304        self.comp.setParam("length", 1000)
305        self.comp.setParam("radius",20)
306        self.comp.setParam("Background", 0.0001)
307       
308        self.x = numpy.array([0.4, 1.3])
309        self.y = numpy.array([0.5, 1.57])
310        self.x_array = self.comp.evalDistribution(self.x)
311        self.y_array = self.comp.evalDistribution(self.y)
312       
313        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
314        qy_prime = numpy.reshape(self.y, [len(self.y),1])
315        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
316       
317        self.q = 0.001
318        self.phi= math.pi/2
319        self.qx= self.q*math.cos(self.phi)
320        self.qy= self.q*math.sin(self.phi)
321       
322    def test1D(self):
323        """ Test 1D model for a FlexibleCylinder Model"""
324        self.assertAlmostEqual(self.comp.run(0.001), 3509.22, 1)
325       
326    def test1D_2(self):
327        """ Test 2D model for a FlexibleCylinder Model"""
328        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
329                              self.comp.runXY([self.qx, self.qy]),1) 
330    def testEval_1D(self):
331        """ Test 1D model for a FlexibleCylinder Model with evalDistribution"""
332        self.assertEquals(self.comp.run(0.4),self.x_array[0])
333        self.assertEquals(self.comp.run(1.3),self.x_array[1])
334       
335    def testEval_2D(self):
336        """ Test 2D model for a FlexibleCylinder Model with evalDistribution"""
337        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
338        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
339        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
340        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
341   
342 
343             
344class TestStackedDisksModel(unittest.TestCase):
345    """ Unit tests for StackedDisks Model"""
346   
347    def setUp(self):
348        from sans.models.StackedDisksModel import StackedDisksModel
349        self.comp = StackedDisksModel()
350        #Give initial value to model
351        self.comp.setParam("scale", 0.01 )
352        self.comp.setParam("radius",3000.0 )
353        self.comp.setParam("core_thick", 10.0)
354        self.comp.setParam("layer_thick",15.0 )
355        self.comp.setParam("core_sld",4e-006 )
356        self.comp.setParam("layer_sld",-4e-007 )
357        self.comp.setParam("solvent_sld", 5e-006 )
358        self.comp.setParam("n_stacking",1.0 )
359        self.comp.setParam("sigma_d", 0.0)
360        self.comp.setParam("background",0.001)
361        self.comp.setParam("axis_theta", 0.0 )
362        self.comp.setParam("axis_phi",0.0)
363       
364        self.x = numpy.array([0.4, 1.3])
365        self.y = numpy.array([0.5, 1.57])
366        self.x_array = self.comp.evalDistribution(self.x)
367        self.y_array = self.comp.evalDistribution(self.y)
368       
369        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
370        qy_prime = numpy.reshape(self.y, [len(self.y),1])
371        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
372       
373        self.q = 0.001
374        self.phi= math.pi/2
375        self.qx= self.q*math.cos(self.phi)
376        self.qy= self.q*math.sin(self.phi)
377       
378    def test1D(self):
379        """ Test 1D model for a StackedDisks Model"""
380        self.assertAlmostEqual(self.comp.run(0.001), 5075.12, 1)
381       
382    def test1D_2(self):
383        """ Test 2D model for a StackedDisks Model"""
384        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
385                              self.comp.runXY([self.qx, self.qy]),1)
386       
387    def testEval_1D(self):
388        """ Test 1D model for a StackedDisks Model with evalDistribution"""
389        self.assertEquals(self.comp.run(0.4),self.x_array[0])
390        self.assertEquals(self.comp.run(1.3),self.x_array[1])
391       
392    def testEval_2D(self):
393        """ Test 2D model for a StackedDisks Model with evalDistribution"""
394        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
395        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
396        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
397        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
398 
399 
400class TestParallelepipedModel(unittest.TestCase):
401    """ Unit tests for Parallelepiped Model"""
402   
403    def setUp(self):
404        from sans.models.ParallelepipedModel import ParallelepipedModel
405        self.comp = ParallelepipedModel()
406        #Give initial value to model
407        self.comp.setParam("background", 0.0 )
408        self.comp.setParam("short_a",35)
409        self.comp.setParam("short_b", 75)
410        self.comp.setParam("long_c",400 )
411        self.comp.setParam("contrast", 5.3e-006 )
412        self.comp.setParam("scale",1.0 )
413       
414        self.x = numpy.array([0.4, 1.3])
415        self.y = numpy.array([0.5, 1.57])
416        self.x_array = self.comp.evalDistribution(self.x)
417        self.y_array = self.comp.evalDistribution(self.y)
418       
419        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
420        qy_prime = numpy.reshape(self.y, [len(self.y),1])
421        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
422       
423        self.q = 0.001
424        self.phi= math.pi/2
425        self.qx= self.q*math.cos(self.phi)
426        self.qy= self.q*math.sin(self.phi)
427       
428   
429    def test1D(self):
430        """ Test 1D model for a Parallelepiped Model"""
431        self.assertAlmostEqual(self.comp.run(0.001), 2935.82, 2)
432       
433    def test1D_2(self):
434        """ Test 2D model for a Parallelepiped Model"""
435        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
436                              self.comp.runXY([self.qx, self.qy]),1)
437       
438    def testEval_1D(self):
439        """ Test 1D model for a Parallelepiped Model with evalDistribution"""
440        self.assertEquals(self.comp.run(0.4),self.x_array[0])
441        self.assertEquals(self.comp.run(1.3),self.x_array[1])
442       
443    def testEval_2D(self):
444        """ Test 2D model for a Parallelepiped Model with evalDistribution"""
445        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
446        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
447        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
448        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
449   
450 
451class TestEllipticalCylinderModel(unittest.TestCase):
452    """ Unit tests for EllipticalCylinder Model"""
453   
454    def setUp(self):
455        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel
456        self.comp = EllipticalCylinderModel()
457        self.comp.setParam("scale",1.0) 
458        self.comp.setParam("r_minor",20.0)
459        self.comp.setParam("r_ratio",1.5) 
460        self.comp.setParam("length",400.0)
461        self.comp.setParam("contrast",5.3e-006)
462        self.comp.setParam("background",0.0)
463        self.comp.setParam("cyl_theta",0.0)
464        self.comp.setParam("cyl_phi",0.0)
465        self.comp.setParam("cyl_psi",0.0)
466       
467        self.x = numpy.array([0.4, 1.3])
468        self.y = numpy.array([0.5, 1.57])
469        self.x_array = self.comp.evalDistribution(self.x)
470        self.y_array = self.comp.evalDistribution(self.y)
471       
472        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
473        qy_prime = numpy.reshape(self.y, [len(self.y),1])
474        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
475       
476        self.q = 0.001
477        self.phi= math.pi/2
478        self.qx= self.q*math.cos(self.phi)
479        self.qy= self.q*math.sin(self.phi)
480       
481    def test1D(self):
482        """ Test 1D model for a EllipticalCylinder Model"""
483        self.assertAlmostEqual(self.comp.run(0.001),2108.32, 1)
484       
485    def test1D_2(self):
486        """ Test 2D model for a EllipticalCylinder Model"""
487        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
488                              self.comp.runXY([self.qx, self.qy]),1)
489       
490    def testEval_1D(self):
491        """ Test 1D model for a EllipticalCylinder with evalDistribution"""
492        self.assertEquals(self.comp.run(0.4),self.x_array[0])
493        self.assertEquals(self.comp.run(1.3),self.x_array[1])
494       
495    def testEval_2D(self):
496        """ Test 2D model for a EllipticalCylinder with evalDistribution"""
497        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
498        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
499        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
500        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
501       
502 
503       
504class TestEllipsoidModel(unittest.TestCase):
505    """ Unit tests for Ellipsoid Model"""
506   
507    def setUp(self):
508        from sans.models.EllipsoidModel import EllipsoidModel
509        self.comp = EllipsoidModel()
510        self.comp.setParam("scale",1.0) 
511        self.comp.setParam("radius_a",20.0)
512        self.comp.setParam("radius_b",400.0)
513        self.comp.setParam("contrast",3e-006)
514        self.comp.setParam("background",0.0)
515        self.comp.setParam("axis_theta",1.57)
516        self.comp.setParam("axis_phi",0.0)
517       
518        self.x = numpy.array([0.4, 1.3])
519        self.y = numpy.array([0.5, 1.57])
520        self.x_array = self.comp.evalDistribution(self.x)
521        self.y_array = self.comp.evalDistribution(self.y)
522       
523        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
524        qy_prime = numpy.reshape(self.y, [len(self.y),1])
525        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
526       
527        self.q = 0.001
528        self.phi= math.pi/2
529        self.qx= self.q*math.cos(self.phi)
530        self.qy= self.q*math.sin(self.phi)
531       
532    def test1D(self):
533        """ Test 1D model for a Ellipsoid Model"""
534        self.assertAlmostEqual(self.comp.run(1.0), 0.000733968, 4)
535       
536    def test1D_2(self):
537        """ Test 2D model for a Ellipsoid Model"""
538        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
539                              self.comp.runXY([self.qx, self.qy]),1)
540    def testEval_1D(self):
541        """ Test 1D model for a Ellipsoid Model with evalDistribution"""
542        self.assertEquals(self.comp.run(0.4),self.x_array[0])
543        self.assertEquals(self.comp.run(1.3),self.x_array[1])
544       
545    def testEval_2D(self):
546        """ Test 2D model for a Ellipsoid Model with evalDistribution"""
547        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
548        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
549        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
550        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
551       
552       
553class TestCoreShellEllipsoidModel(unittest.TestCase):
554    """ Unit tests for CoreShellEllipsoid Model"""
555   
556    def setUp(self):
557        from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel
558        self.comp = CoreShellEllipsoidModel()
559        #Give initial value to model
560        self.comp.setParam("scale", 1.0)
561        self.comp.setParam("equat_core", 200.0)
562        self.comp.setParam("polar_core", 20.0)
563        self.comp.setParam("equat_shell",250.0)
564        self.comp.setParam("polar_shell", 30.0)
565        self.comp.setParam("contrast",1e-006)
566        self.comp.setParam("sld_solvent",6.3e-006)
567        self.comp.setParam("background",0.001)
568        self.comp.setParam("axis_theta", 0.0)
569        self.comp.setParam("axis_phi",0.0)
570         
571        self.x = numpy.array([0.4, 1.3])
572        self.y = numpy.array([0.5, 1.57])
573        self.x_array = self.comp.evalDistribution(self.x)
574        self.y_array = self.comp.evalDistribution(self.y)
575       
576        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
577        qy_prime = numpy.reshape(self.y, [len(self.y),1])
578        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
579       
580        self.q = 0.001
581        self.phi= math.pi/2
582        self.qx= self.q*math.cos(self.phi)
583        self.qy= self.q*math.sin(self.phi)
584       
585    def test1D(self):
586        """ Test 1D model for a CoreShellEllipsoid Model"""
587        self.assertAlmostEqual(self.comp.run(1.0), 0.002578943, 4)
588       
589    def test1D_2(self):
590        """ Test 2D model for a CoreShellEllipsoid Model"""
591        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
592                              self.comp.runXY([self.qx, self.qy]),1)
593       
594    def testEval_1D(self):
595        """ Test 1D model for a CoreShellEllipsoid with evalDistribution"""
596        self.assertEquals(self.comp.run(0.4),self.x_array[0])
597        self.assertEquals(self.comp.run(1.3),self.x_array[1])
598       
599    def testEval_2D(self):
600        """ Test 2D model for a CoreShellEllipsoid with evalDistribution"""
601        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
602        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
603        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
604        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
605 
606   
607class TestTriaxialEllipsoidModel(unittest.TestCase):
608    """ Unit tests for TriaxialEllipsoid Model"""
609   
610    def setUp(self):
611        from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
612        self.comp = TriaxialEllipsoidModel()
613        self.comp.setParam("scale",1.0)
614        self.comp.setParam("semi_axisA",35.0)
615        self.comp.setParam("semi_axisB", 100.0)
616        self.comp.setParam("semi_axisC",400.0 )
617        self.comp.setParam("contrast",5.3e-6)
618        self.comp.setParam("background",0.0)
619        self.comp.setParam("axis_theta", 1.0)
620        self.comp.setParam("axis_phi",0.0 )
621        self.comp.setParam("axis_psi",0.0 )
622       
623        self.x = numpy.array([0.4, 1.3])
624        self.y = numpy.array([0.5, 1.57])
625       
626        self.x_array = self.comp.evalDistribution(self.x)
627        self.y_array = self.comp.evalDistribution(self.y)
628        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
629        qy_prime = numpy.reshape(self.y, [len(self.y),1])
630        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
631       
632        self.q = 0.001
633        self.phi= math.pi/2
634        self.qx= self.q*math.cos(self.phi)
635        self.qy= self.q*math.sin(self.phi)
636       
637       
638    def test1D(self):
639        """ Test 1D model for a TriaxialEllipsoid Model"""
640        self.assertAlmostEquals(self.comp.run(0.001),16285.6, 1)
641       
642    def test1D_2(self):
643        """ Test 2D model for a TriaxialEllipsoid Model"""
644        self.assertAlmostEqual(self.comp.run([self.q, self.phi]), 
645                              self.comp.runXY([self.qx, self.qy]),1)
646     
647    def testEval_1D(self):
648        """ Test 1D model for a TriaxialEllipsoid Model with evalDistribution"""
649        self.assertEquals(self.comp.run(0.4),self.x_array[0])
650        self.assertEquals(self.comp.run(1.3),self.x_array[1])
651       
652    def testEval_2D(self):
653        """ Test 2D model for a TriaxialEllipsoid Model with evalDistribution"""
654        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
655        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
656        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
657        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
658                     
659   
660class TestLamellarModel(unittest.TestCase):
661    """ Unit tests for Lamellar Model"""
662   
663    def setUp(self):
664        from sans.models.LamellarModel import LamellarModel
665        self.comp = LamellarModel()
666        self.comp.setParam("scale",1.0) 
667        self.comp.setParam("bi_thick",50.0)
668        self.comp.setParam("sld_bi",1e-006)
669        self.comp.setParam("sld_sol",6.3e-006)
670        self.comp.setParam("background",0.0)
671
672        self.x = numpy.array([0.4, 1.3])
673        self.y = numpy.array([0.5, 1.57])
674       
675        self.x_array = self.comp.evalDistribution(self.x)
676        self.y_array = self.comp.evalDistribution(self.y)
677        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
678        qy_prime = numpy.reshape(self.y, [len(self.y),1])
679        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
680       
681    def test1D(self):
682        """ Test 1D model for a Lamellar Model"""
683        self.assertAlmostEquals(self.comp.run(0.001), 902120)
684       
685    def test1D_2(self):
686        """ Test 2D model for a Lamellar Model"""
687        self.assertAlmostEquals(self.comp.run([0.001, 1.3]),902120)     
688   
689    def testEval_1D(self):
690        """ Test 1D model for a Lamellar Model with evalDistribution"""
691        self.assertEquals(self.comp.run(0.4),self.x_array[0])
692        self.assertEquals(self.comp.run(1.3),self.x_array[1])
693       
694    def testEval_2D(self):
695        """ Test 2D model for a Lamellar Model with evalDistribution"""
696        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
697        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
698        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
699        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)       
700   
701     
702class TestLamellarFFHGModel(unittest.TestCase):
703    """ Unit tests for LamellarFFHG Model"""
704   
705    def setUp(self):
706        from sans.models.LamellarFFHGModel import LamellarFFHGModel
707        self.comp = LamellarFFHGModel()
708        self.comp.setParam("scale",1.0) 
709        self.comp.setParam("t_length",15.0)
710        self.comp.setParam("h_thickness",10.0)
711        self.comp.setParam("sld_tail",4e-007)
712        self.comp.setParam("sld_head",3e-006)
713        self.comp.setParam("sld_solvent",6e-006)
714        self.comp.setParam("background",0.0)
715       
716        self.x = numpy.array([0.4, 1.3])
717        self.y = numpy.array([0.5, 1.57])
718       
719        self.x_array = self.comp.evalDistribution(self.x)
720        self.y_array = self.comp.evalDistribution(self.y)
721        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
722        qy_prime = numpy.reshape(self.y, [len(self.y),1])
723        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
724       
725       
726    def test1D(self):
727        """ Test 1D model for a LamellarFFHG Model"""
728        self.assertAlmostEquals(self.comp.run(0.001),653144)
729       
730    def test1D_2(self):
731        """ Test 2D model for a LamellarFFHG Model"""
732        self.assertAlmostEquals(self.comp.run([0.001, 1.3]),653144)
733   
734    def testEval_1D(self):
735        """ Test 1D model for a LamellarFFHG Model with evalDistribution"""
736        self.assertEquals(self.comp.run(0.4),self.x_array[0])
737        self.assertEquals(self.comp.run(1.3),self.x_array[1])
738       
739    def testEval_2D(self):
740        """ Test 2D model for a LamellarFFHG Model with evalDistribution"""
741        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
742        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
743        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
744        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)       
745                 
746   
747class TestLamellarPSModel(unittest.TestCase):
748    """ Unit tests for LamellarPS Model"""
749   
750    def setUp(self):
751        from sans.models.LamellarPSModel import LamellarPSModel
752        self.comp = LamellarPSModel()
753        self.comp.setParam("scale",1.0) 
754        self.comp.setParam("spacing",400.0)
755        self.comp.setParam("delta",30.0)
756        self.comp.setParam("contrast",5.3e-006)
757        self.comp.setParam("n_plates",20.0) 
758        self.comp.setParam("caille", 0.1)
759        self.comp.setParam("background",0.0)
760
761        self.x = numpy.array([0.4, 1.3])
762        self.y = numpy.array([0.5, 1.57])
763       
764        self.x_array = self.comp.evalDistribution(self.x)
765        self.y_array = self.comp.evalDistribution(self.y)
766        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
767        qy_prime = numpy.reshape(self.y, [len(self.y),1])
768        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
769       
770       
771    def test1D(self):
772        """ Test 1D model for a LamellarPS Model"""
773        self.assertAlmostEquals(self.comp.run(0.001), 28526.8, 1)
774       
775    def test1D_2(self):
776        """ Test 2D model for a LamellarPS Model"""
777        self.assertAlmostEquals(self.comp.run([0.001, 1.3]),28526.8, 1) 
778   
779    def testEval_1D(self):
780        """ Test 1D model for a LamellarPS Model with evalDistribution"""
781        self.assertEquals(self.comp.run(0.4),self.x_array[0])
782        self.assertEquals(self.comp.run(1.3),self.x_array[1])
783       
784    def testEval_2D(self):
785        """ Test 2D model for a LamellarPS Model with evalDistribution"""
786        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
787        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
788        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
789        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)       
790           
791     
792     
793class TestLamellarPSHGModel(unittest.TestCase):
794    """ Unit tests for LamellarPSHG Model"""
795   
796    def setUp(self):
797        from sans.models.LamellarPSHGModel import LamellarPSHGModel
798        self.comp = LamellarPSHGModel()
799        self.comp.setParam("scale",1.0)
800        self.comp.setParam("spacing",40.0)
801        self.comp.setParam("deltaT",10.0)
802        self.comp.setParam("deltaH",2.0)
803        self.comp.setParam("sld_tail",4e-7)
804        self.comp.setParam("sld_head",2e-6)
805        self.comp.setParam("sld_solvent",6e-6)
806        self.comp.setParam("n_plates",30)
807        self.comp.setParam("caille",0.001)
808        self.comp.setParam("background",0.001)
809
810        self.x = numpy.array([0.4, 1.3])
811        self.y = numpy.array([0.5, 1.57])
812       
813        self.x_array = self.comp.evalDistribution(self.x)
814        self.y_array = self.comp.evalDistribution(self.y)
815        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
816        qy_prime = numpy.reshape(self.y, [len(self.y),1])
817        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
818       
819    def test1D(self):
820        """ Test 1D model for a LamellarPSHG Model"""
821        self.assertAlmostEquals(self.comp.run(0.001),6.83139e6, 3)
822       
823    def test1D_2(self):
824        """ Test 2D model for a LamellarPSHG Model"""
825        self.assertAlmostEquals(self.comp.run([0.001, 1.3]),6.83139e6,3)
826       
827    def testEval_1D(self):
828        """ Test 1D model for a LamellarPSHG Model with evalDistribution"""
829        self.assertEquals(self.comp.run(0.4),self.x_array[0])
830        self.assertEquals(self.comp.run(1.3),self.x_array[1])
831       
832    def testEval_2D(self):
833        """ Test 2D model for a LamellarPSHG Model with evalDistribution"""
834        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
835        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
836        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
837        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)       
838     
839     
840class TestSquareWellStructure(unittest.TestCase):
841    """ Unit tests for SquareWellStructure """
842   
843    def setUp(self):
844        from sans.models.SquareWellStructure import SquareWellStructure
845        self.comp = SquareWellStructure()
846        self.comp.setParam("effect_radius",50.0)
847        self.comp.setParam("volfraction",0.04)
848        self.comp.setParam("welldepth",1.5 )
849        self.comp.setParam("wellwidth",1.2)
850       
851        self.x = numpy.array([0.4, 1.3])
852        self.y = numpy.array([0.5, 1.57])
853       
854        self.x_array = self.comp.evalDistribution(self.x)
855        self.y_array = self.comp.evalDistribution(self.y)
856        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
857        qy_prime = numpy.reshape(self.y, [len(self.y),1])
858        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
859       
860       
861    def test1D(self):
862        """ Test 1D model for a SquareWellStructure"""
863        self.assertAlmostEqual(self.comp.run(0.001), 0.976657, 2)
864       
865    def test1D_2(self):
866        """ Test 2D model for a SquareWellStructure"""
867        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.9776657,2)     
868   
869    def testEval_1D(self):
870        """ Test 1D model for a SquareWellStructure with evalDistribution"""
871        self.assertEquals(self.comp.run(0.4),self.x_array[0])
872        self.assertEquals(self.comp.run(1.3),self.x_array[1])
873       
874    def testEval_2D(self):
875        """ Test 2D model for a SquareWellStructure with evalDistribution"""
876        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
877        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
878        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
879        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
880                         
881     
882class TestHardsphereStructure(unittest.TestCase):
883    """ Unit tests for HardsphereStructure"""
884   
885    def setUp(self):
886        from sans.models.HardsphereStructure import HardsphereStructure
887        self.comp = HardsphereStructure()
888        self.comp.setParam("effect_radius",50.0)
889        self.comp.setParam("volfraction", 0.2)
890        self.x = numpy.array([0.4, 1.3])
891        self.y = numpy.array([0.5, 1.57])
892       
893        self.x_array = self.comp.evalDistribution(self.x)
894        self.y_array = self.comp.evalDistribution(self.y)
895        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
896        qy_prime = numpy.reshape(self.y, [len(self.y),1])
897        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
898       
899       
900    def test1D(self):
901        """ Test 1D model for a HardsphereStructure"""
902        self.assertAlmostEqual(self.comp.run(0.001),0.209128, 4)
903       
904    def test1D_2(self):
905        """ Test 2D model for a HardsphereStructure"""
906        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.209128, 4)
907       
908    def testEval_1D(self):
909        """ Test 1D model for a HardsphereStructure with evalDistribution"""
910        self.assertEquals(self.comp.run(0.4),self.x_array[0])
911        self.assertEquals(self.comp.run(1.3),self.x_array[1])
912       
913    def testEval_2D(self):
914        """ Test 2D model for a HardsphereStructure with evalDistribution"""
915        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
916        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
917        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
918        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
919                     
920   
921class TestStickyHSStructure(unittest.TestCase):
922    """ Unit tests for StickyHSStructure"""
923   
924    def setUp(self):
925        from sans.models.StickyHSStructure import StickyHSStructure
926        self.comp = StickyHSStructure()
927        self.comp.setParam("effect_radius",50.0)
928        self.comp.setParam("volfraction",0.1)
929        self.comp.setParam("perturb",0.05)
930        self.comp.setParam("stickiness",0.2)
931
932        self.x = numpy.array([0.4, 1.3])
933        self.y = numpy.array([0.5, 1.57])
934       
935        self.x_array = self.comp.evalDistribution(self.x)
936        self.y_array = self.comp.evalDistribution(self.y)
937        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
938        qy_prime = numpy.reshape(self.y, [len(self.y),1])
939        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
940       
941    def test1D(self):
942        """ Test 1D model for a StickyHSStructure"""
943        self.assertAlmostEqual(self.comp.run(0.001),1.09718, 4)
944       
945    def test1D_2(self):
946        """ Test 2D model for a StickyHSStructure"""
947        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.09718, 4)
948       
949    def testEval_1D(self):
950        """ Test 1D model for a StickyHSStructure with evalDistribution"""
951        self.assertEquals(self.comp.run(0.4),self.x_array[0])
952        self.assertEquals(self.comp.run(1.3),self.x_array[1])
953       
954       
955    def testEval_2D(self):
956        """ Test 2D model for a StickyHSStructure with evalDistribution"""
957        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
958        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
959        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
960        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
961               
962     
963       
964class TestHayterMSAStructure(unittest.TestCase):
965    """ Unit tests for HayterMSAStructure"""
966   
967    def setUp(self):
968        from sans.models.HayterMSAStructure import HayterMSAStructure
969        self.comp = HayterMSAStructure()
970        self.comp.setParam("effect_radius",20.75)
971        self.comp.setParam("charge",19.0)
972        self.comp.setParam("volfraction",0.0192 )
973        self.comp.setParam("temperature",298)
974        self.comp.setParam("saltconc",0.0)
975        self.comp.setParam("dielectconst",78)
976       
977        self.x = numpy.array([0.4, 1.3])
978        self.y = numpy.array([0.5, 1.57])
979       
980        self.x_array = self.comp.evalDistribution(self.x)
981        self.y_array = self.comp.evalDistribution(self.y)
982        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
983        qy_prime = numpy.reshape(self.y, [len(self.y),1])
984        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
985
986    def test1D(self):
987        """ Test 1D model for a HayterMSAStructure"""
988        self.assertAlmostEqual(self.comp.run(0.001),0.0712928, 4)
989       
990    def test1D_2(self):
991        """ Test 2D model for a HayterMSAStructure"""
992        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.0712928, 4) 
993       
994    def testEval_1D(self):
995        """ Test 1D model for a HayterMSAStructure with evalDistribution"""
996        self.assertEquals(self.comp.run(0.4),self.x_array[0])
997        self.assertEquals(self.comp.run(1.3),self.x_array[1])
998       
999    def testEval_2D(self):
1000        """ Test 2D model for a HayterMSAStructure with evalDistribution"""
1001        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1002        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1003        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1004        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1005                       
1006     
1007     
1008class TestBEPolyelectrolyte(unittest.TestCase):
1009    """ Unit tests for BEPolyelectrolyte"""
1010   
1011    def setUp(self):
1012        from sans.models.BEPolyelectrolyte import BEPolyelectrolyte
1013        self.comp = BEPolyelectrolyte()
1014       
1015        self.comp.setParam('k',10)
1016        self.comp.setParam('lb',7.1)
1017        self.comp.setParam('h',12)
1018        self.comp.setParam('b',10)
1019        self.comp.setParam('cs', 0.0)
1020        self.comp.setParam('alpha',0.05)
1021        self.comp.setParam('c', 0.7)
1022        self.comp.setParam('background',0.001)
1023         
1024        self.x = numpy.array([0.4, 1.3])
1025        self.y = numpy.array([0.5, 1.57])
1026       
1027        self.x_array = self.comp.evalDistribution(self.x)
1028        self.y_array = self.comp.evalDistribution(self.y)
1029        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1030        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1031        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1032       
1033    def test1D(self):
1034        """ Test 1D model for a BEPolyelectrolyte"""
1035        self.assertAlmostEqual(self.comp.run(0.001),0.0948, 3)
1036       
1037    def test1D_2(self):
1038        """ Test 2D model for a BEPolyelectrolyte"""
1039        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.0948, 3)
1040     
1041    def testEval_1D(self):
1042        """ Test 1D model for a BEPolyelectrolyte with evalDistribution"""
1043        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1044        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1045       
1046       
1047    def testEval_2D(self):
1048        """ Test 2D model for a BEPolyelectrolyte with evalDistribution"""
1049        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1050        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1051        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1052        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1053               
1054             
1055class TestDABModel(unittest.TestCase):
1056    """ Unit tests for DABModel"""
1057   
1058    def setUp(self):
1059        from sans.models.DABModel import DABModel
1060        self.comp = DABModel()
1061        self.comp.setParam('length',40.0)
1062        self.comp.setParam('scale',10.0)
1063        self.comp.setParam('background',1.0)
1064       
1065        self.x = numpy.array([0.4, 1.3])
1066        self.y = numpy.array([0.5, 1.57])
1067   
1068        self.x_array = self.comp.evalDistribution(self.x)
1069        self.y_array = self.comp.evalDistribution(self.y)
1070        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1071        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1072        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1073       
1074    def test1D(self):
1075        """ Test 1D model for a DABModel"""
1076        self.assertAlmostEqual(self.comp.run(0.001),10.9681, 3)
1077       
1078    def test1D_2(self):
1079        """ Test 2D model for a DABModel"""
1080        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),10.9681, 3)
1081         
1082    def testEval_1D(self):
1083        """ Test 1D model for a DABModel with evalDistribution"""
1084        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1085        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1086       
1087       
1088    def testEval_2D(self):
1089        """ Test 2D model for a DABModel with evalDistribution"""
1090        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1091        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1092        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1093        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1094               
1095             
1096   
1097class TestGuinierModel(unittest.TestCase):
1098    """ Unit tests for Guinier Model"""
1099   
1100    def setUp(self):
1101        from sans.models.GuinierModel import GuinierModel
1102        self.comp = GuinierModel()
1103        self.comp.setParam('scale',1.0)
1104        self.comp.setParam('rg', 60)
1105       
1106        self.x = numpy.array([0.4, 1.3])
1107        self.y = numpy.array([0.5, 1.57])
1108       
1109        self.x_array = self.comp.evalDistribution(self.x)
1110        self.y_array = self.comp.evalDistribution(self.y)
1111        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1112        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1113        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1114       
1115       
1116    def test1D(self):
1117        """ Test 1D model for a GuinierModel"""
1118        self.assertAlmostEqual(self.comp.run(1.0), 5.6387e-5, 4)
1119       
1120    def test1D_2(self):
1121        """ Test 2D model for a GuinierModel"""
1122        self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 5.6387e-5, 4) 
1123        from sans.models.GuinierModel import GuinierModel
1124        self.shape_indep_list.append(GuinierModel )
1125       
1126    def testEval_1D(self):
1127        """ Test 1D model for a GuinierModel with evalDistribution"""
1128        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1129        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1130       
1131    def testEval_2D(self):
1132        """ Test 2D model for a GuinierModel with evalDistribution"""
1133        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1134        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1135        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1136        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1137   
1138       
1139       
1140class TestDebyeModel(unittest.TestCase):
1141    """ Unit tests for Debye Model"""
1142   
1143    def setUp(self):
1144        from sans.models.DebyeModel import DebyeModel
1145        self.comp = DebyeModel()
1146        self.comp.setParam('rg', 50.0)
1147        self.comp.setParam('scale',1.0)
1148        self.comp.setParam('background',0.001)
1149       
1150        self.x = numpy.array([0.4, 1.3])
1151        self.y = numpy.array([0.5, 1.57])
1152       
1153        self.x_array = self.comp.evalDistribution(self.x)
1154        self.y_array = self.comp.evalDistribution(self.y)
1155        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1156        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1157        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1158       
1159    def test1D(self):
1160        """ Test 1D model for a DebyeModel"""
1161        self.assertAlmostEqual(self.comp.run(0.001),1.00017,4)
1162       
1163    def test1D_2(self):
1164        """ Test 2D model for a DebyeModel"""
1165        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.00017,4)
1166       
1167    def testEval_1D(self):
1168        """ Test 1D model for a DebyeModel with evalDistribution"""
1169        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1170        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1171       
1172    def testEval_2D(self):
1173        """ Test 2D model for a DebyeModel with evalDistribution"""
1174        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1175        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1176        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1177        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1178   
1179       
1180class TestPorodModel(unittest.TestCase):
1181    """ Unit tests for PorodModel"""
1182   
1183    def setUp(self):
1184        from sans.models.PorodModel import PorodModel
1185        self.comp = PorodModel()
1186        self.comp.setParam('scale', 1.0)
1187        self.comp.setParam('background', 0.0)
1188         
1189        self.x = numpy.array([0.4, 1.3])
1190        self.y = numpy.array([0.5, 1.57])
1191       
1192        self.x_array = self.comp.evalDistribution(self.x)
1193        self.y_array = self.comp.evalDistribution(self.y)
1194        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1195        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1196        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1197       
1198    def test1D(self):
1199        """ Test 1D model for a PorodModel"""
1200        self.assertEquals(self.comp.run(0.5), 16)
1201       
1202    def test1D_2(self):
1203        """ Test 2D model for a PorodModel"""
1204        self.assertEquals(self.comp.run([0.5, 1.3]),16) 
1205       
1206    def testEval_1D(self):
1207        """ Test 1D model for a PorodModel with evalDistribution"""
1208        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1209        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1210       
1211    def testEval_2D(self):
1212        """ Test 2D model for a PorodModel with evalDistribution"""
1213        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1214        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1215        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1216        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1217   
1218    def testCreaticalPt(self):
1219        """ Test for critical point for PorodModel run"""
1220        self.assertRaises(ZeroDivisionError, self.comp.run, 0.0)
1221       
1222       
1223class TestPeakGaussModel(unittest.TestCase):
1224    """ Unit tests for PeakGaussModel"""
1225   
1226    def setUp(self):
1227        from sans.models.PeakGaussModel import PeakGaussModel
1228        self.comp = PeakGaussModel()
1229        self.comp.setParam('scale', 100)
1230        self.comp.setParam('B', 0.005)
1231        self.comp.setParam('q0',0.05)
1232        self.comp.setParam('background',1.0)
1233       
1234        self.x = numpy.array([0.4, 1.3])
1235        self.y = numpy.array([0.5, 1.57])
1236       
1237        self.x_array = self.comp.evalDistribution(self.x)
1238        self.y_array = self.comp.evalDistribution(self.y)
1239        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1240        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1241        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1242       
1243    def test1D(self):
1244        """ Test 1D model for a PeakGauss Model"""
1245        self.assertEquals(self.comp.run(0.001),1)
1246       
1247    def test1D_2(self):
1248        """ Test 2D model for a PeakGauss Model"""
1249        self.assertEquals(self.comp.run([0.001, 1.3]),1) 
1250       
1251    def testEval_1D(self):
1252        """ Test 1D model for a PeakGauss Model with evalDistribution"""
1253        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1254        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1255       
1256    def testEval_2D(self):
1257        """ Test 2D model for a PeakGauss Model with evalDistribution"""
1258        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1259        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1260        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1261        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1262       
1263       
1264class TestPeakLorentzModel(unittest.TestCase):
1265    """ Unit tests for PeakLorentzModel"""
1266   
1267    def setUp(self):
1268        from sans.models.PeakLorentzModel import PeakLorentzModel
1269        self.comp = PeakLorentzModel()
1270        self.comp.setParam('scale', 100)
1271        self.comp.setParam('B', 0.005)
1272        self.comp.setParam('q0',0.05)
1273        self.comp.setParam('background',1.0)
1274       
1275        self.x = numpy.array([0.4, 1.3])
1276        self.y = numpy.array([0.5, 1.57])
1277       
1278        self.x_array = self.comp.evalDistribution(self.x)
1279        self.y_array = self.comp.evalDistribution(self.y)
1280        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1281        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1282        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1283       
1284    def test1D(self):
1285        """ Test 1D model for a PeakLorentz Model"""
1286        self.assertAlmostEqual(self.comp.run(0.001), 2.0305, 3)
1287       
1288    def test1D_2(self):
1289        """ Test 2D model for a PeakLorentz Model"""
1290        self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 2.0305, 3)
1291       
1292    def testEval_1D(self):
1293        """ Test 1D model for a PeakLorentz Model with evalDistribution"""
1294        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1295        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1296       
1297    def testEval_2D(self):
1298        """ Test 2D model for a PeakLorentz Model with evalDistribution"""
1299        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1300        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1301        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1302        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1303       
1304       
1305class TestFractalAbsModel(unittest.TestCase):
1306    """ Unit tests for FractalAbsModel"""
1307   
1308    def setUp(self):
1309        from sans.models.FractalAbsModel import FractalAbsModel
1310        self.comp = FractalAbsModel()
1311        self.comp.setParam('scale', 0.05)
1312        self.comp.setParam('radius', 5.0)
1313        self.comp.setParam('fractal_dim', 2.0)
1314        self.comp.setParam('corr_length',100.0)
1315        self.comp.setParam('block_sld', 2.0e-6)
1316        self.comp.setParam('solvent_sld', 6.35e-6)
1317        self.comp.setParam('background',0.0)
1318       
1319        self.x = numpy.array([0.4, 1.3])
1320        self.y = numpy.array([0.5, 1.57])
1321       
1322        self.x_array = self.comp.evalDistribution(self.x)
1323        self.y_array = self.comp.evalDistribution(self.y)
1324        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1325        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1326        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1327       
1328    def test1D(self):
1329        """ Test 1D model for a Fractal Abs Model"""
1330        self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3)
1331       
1332    def test1D_2(self):
1333        """ Test 2D model for a Fractal Abs Model"""
1334        self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3)
1335       
1336    def testEval_1D(self):
1337        """ Test 1D model for a Fractal Abs Model with evalDistribution"""
1338        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1339        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1340       
1341    def testEval_2D(self):
1342        """ Test 2D model for a Fractal Abs Model with evalDistribution"""
1343        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1344        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1345        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1346        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1347       
1348   
1349class TestFractalModel(unittest.TestCase):
1350    """ Unit tests for FractalModel"""
1351   
1352    def setUp(self):
1353        from sans.models.FractalModel import FractalModel
1354        self.comp = FractalModel()
1355        self.comp.setParam('scale', 0.05)
1356        self.comp.setParam('radius', 5.0)
1357        self.comp.setParam('fractal_dim', 2.0)
1358        self.comp.setParam('corr_length',100.0)
1359        self.comp.setParam('block_sld', 2.0e-6)
1360        self.comp.setParam('solvent_sld', 6.35e-6)
1361        self.comp.setParam('background',0.0)
1362       
1363        self.x = numpy.array([0.4, 1.3])
1364        self.y = numpy.array([0.5, 1.57])
1365       
1366        self.x_array = self.comp.evalDistribution(self.x)
1367        self.y_array = self.comp.evalDistribution(self.y)
1368        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1369        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1370        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1371       
1372    def test1D(self):
1373        """ Test 1D model for a Fractal Model"""
1374        self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3)
1375       
1376    def test1D_2(self):
1377        """ Test 2D model for a Fractal Model"""
1378        self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3)
1379       
1380    def testEval_1D(self):
1381        """ Test 1D model for a Fractal Model with evalDistribution"""
1382        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1383        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1384       
1385    def testEval_2D(self):
1386        """ Test 2D model for a Fractal Model with evalDistribution"""
1387        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1388        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1389        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1390        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1391       
1392   
1393class TestLorentzModel(unittest.TestCase):
1394    """ Unit tests for LorentzModel"""
1395   
1396    def setUp(self):
1397        from sans.models.LorentzModel import LorentzModel
1398        self.comp = LorentzModel()
1399        self.comp.setParam("background",1)
1400        self.comp.setParam("length",50)
1401        self.comp.setParam("scale",100)
1402       
1403        self.x = numpy.array([0.4, 1.3])
1404        self.y = numpy.array([0.5, 1.57])
1405       
1406        self.x_array = self.comp.evalDistribution(self.x)
1407        self.y_array = self.comp.evalDistribution(self.y)
1408        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1409        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1410        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1411       
1412    def test1D(self):
1413        """ Test 1D model for a Lorentz Model"""
1414        self.assertAlmostEqual(self.comp.run(0.001),100.751, 2)
1415       
1416    def test1D_2(self):
1417        """ Test 2D model for a Lorentz Model"""
1418        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),100.751, 2)
1419   
1420    def testEval_1D(self):
1421        """ Test 1D model for a Lorentz Model with evalDistribution"""
1422        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1423        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1424       
1425    def testEval_2D(self):
1426        """ Test 2D model for a Lorentz Model with evalDistribution"""
1427        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1428        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1429        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1430        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1431           
1432class TestPowerLawAbsModel(unittest.TestCase):
1433    """ Unit tests for PowerLawAbsModel"""
1434   
1435    def setUp(self):
1436        from sans.models.PowerLawAbsModel import PowerLawAbsModel
1437        self.comp = PowerLawAbsModel()
1438        self.comp.setParam("background",1)
1439        self.comp.setParam("m",4)
1440        self.comp.setParam("scale",1e-6)
1441       
1442        self.x = numpy.array([0.4, 1.3])
1443        self.y = numpy.array([0.5, 1.57])
1444        self.x_array = self.comp.evalDistribution(self.x)
1445        self.y_array = self.comp.evalDistribution(self.y)
1446        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1447        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1448        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1449       
1450    def test1D(self):
1451        """ Test 1D model for a PowerLawAbs Model"""
1452        self.assertAlmostEqual(self.comp.run(0.19189), 1.00074,4)
1453       
1454    def test1D_2(self):
1455        """ Test 2D model for a PowerLawAbs Model"""
1456        self.assertAlmostEqual(self.comp.run([0.19189,1.3]), 1.00074,4)
1457       
1458    def testEval_1D(self):
1459        """ Test 1D model for a PowerLawAbs Model with evalDistribution"""
1460        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1461        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1462       
1463    def testEval_2D(self):
1464        """ Test 2D model for a PowerLawAbs Model with evalDistribution"""
1465        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1466        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1467        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1468        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1469   
1470class TestPowerLawModel(unittest.TestCase):
1471    """ Unit tests for PowerLawModel"""
1472   
1473    def setUp(self):
1474        from sans.models.PowerLawModel import PowerLawModel
1475        self.comp = PowerLawModel()
1476        self.comp.setParam("background",1)
1477        self.comp.setParam("m",4)
1478        self.comp.setParam("scale",1e-6)
1479       
1480        self.x = numpy.array([0.4, 1.3])
1481        self.y = numpy.array([0.5, 1.57])
1482        self.x_array = self.comp.evalDistribution(self.x)
1483        self.y_array = self.comp.evalDistribution(self.y)
1484        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1485        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1486        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1487       
1488    def test1D(self):
1489        """ Test 1D model for a PowerLaw Model"""
1490        self.assertAlmostEquals(self.comp.run(0.19189), 1.00074,4)
1491       
1492    def test1D_2(self):
1493        """ Test 2D model for a PowerLawModel"""
1494        self.assertAlmostEquals(self.comp.run([0.19189,1.3]), 1.00074,4)
1495       
1496    def testEval_1D(self):
1497        """ Test 1D model for a PowerLawModel with evalDistribution"""
1498        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1499        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1500       
1501    def testEval_2D(self):
1502        """ Test 2D model for a PowerLawModel with evalDistribution"""
1503        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1504        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1505        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1506        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1507     
1508     
1509class TestTeubnerStreyModel(unittest.TestCase):
1510    """ Unit tests for TeubnerStreyModel"""
1511   
1512    def setUp(self):
1513        from sans.models.TeubnerStreyModel import TeubnerStreyModel
1514        self.comp = TeubnerStreyModel()
1515        self.comp.setParam("background",0.1)
1516        self.comp.setParam("c1",-30)
1517        self.comp.setParam("c2",5000)
1518        self.comp.setParam("scale",0.1)
1519       
1520        self.x = numpy.array([0.4, 1.3])
1521        self.y = numpy.array([0.5, 1.57])
1522        self.x_array = self.comp.evalDistribution(self.x)
1523        self.y_array = self.comp.evalDistribution(self.y)
1524        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1525        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1526        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1527       
1528    def test1D(self):
1529        """ Test 1D model for a TeubnerStrey Model"""
1530        self.assertAlmostEqual(self.comp.run(0.001),10.103, 1)
1531       
1532    def test1D_2(self):
1533        """ Test 2D model for a TeubnerStrey Model"""
1534        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),10.103, 1)
1535       
1536    def testEval_1D(self):
1537        """ Test 1D model for a TeubnerStrey  with evalDistribution"""
1538        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1539        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1540       
1541    def testEval_2D(self):
1542        """ Test 2D model for a TeubnerStrey  with evalDistribution"""
1543        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1544        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1545        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1546        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1547       
1548     
1549class TestLineModel(unittest.TestCase):
1550    """ Unit tests for LineModel"""
1551   
1552    def setUp(self):
1553        from sans.models.LineModel import LineModel
1554        self.comp = LineModel()
1555        self.comp.setParam("A",1)
1556        self.comp.setParam("B",1)
1557       
1558        self.x = numpy.array([0.4, 1.3])
1559        self.y = numpy.array([0.5, 1.57])
1560        self.x_array = self.comp.evalDistribution(self.x)
1561        self.y_array = self.comp.evalDistribution(self.y)
1562        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1563        qy_prime = numpy.reshape(self.y, [len(self.y),1])
1564        self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime])
1565       
1566    def test1D(self):
1567        """ Test 1D model for a Line Model"""
1568        self.assertEquals(self.comp.run(1.0),2)
1569       
1570    def testEval_1D(self):
1571        """ Test 1D model for a Line  with evalDistribution"""
1572        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1573        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1574       
1575    def testEval_2D(self):
1576        """ Test 2D model for a Line  with evalDistribution"""
1577        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8)
1578        self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8)
1579        self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8)
1580        self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8)
1581 
1582 
1583if __name__ == '__main__':
1584    unittest.main()
Note: See TracBrowser for help on using the repository browser.