source: sasview/sansmodels/test/utest_other_models.py @ 1b28ff5

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 1b28ff5 was 1e40ed1, checked in by Kieran Campbell <kieranrcampbell@…>, 12 years ago

Small problem with the maths in starpolymer

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