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

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

test model at q=0

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