source: sasview/sansmodels/test/utest_other_models.py @ ac2b835

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 ac2b835 was 279e371, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Fixing code style problems

  • 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)))           
[9ce41c6]1235             
1236   
1237class TestGuinierModel(unittest.TestCase):
1238    """ Unit tests for Guinier Model"""
1239   
1240    def setUp(self):
1241        from sans.models.GuinierModel import GuinierModel
1242        self.comp = GuinierModel()
1243        self.comp.setParam('scale',1.0)
[a65ffcb]1244        self.comp.setParam('rg', 1)
[9ce41c6]1245       
1246        self.x = numpy.array([0.4, 1.3])
1247        self.y = numpy.array([0.5, 1.57])
1248       
1249        self.x_array = self.comp.evalDistribution(self.x)
1250        self.y_array = self.comp.evalDistribution(self.y)
1251        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1252        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1253        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1254       
1255    def test1D(self):
1256        """ Test 1D model for a GuinierModel"""
[a65ffcb]1257        self.assertAlmostEqual(self.comp.run(1.0),0.716531, 4)
[9ce41c6]1258       
1259    def test1D_2(self):
1260        """ Test 2D model for a GuinierModel"""
[a65ffcb]1261        self.assertAlmostEqual(self.comp.run([1.0, 1.3]),0.716531, 4)
1262     
[9ce41c6]1263    def testEval_1D(self):
1264        """ Test 1D model for a GuinierModel with evalDistribution"""
1265        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1266        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1267       
1268    def testEval_2D(self):
1269        """ Test 2D model for a GuinierModel with evalDistribution"""
[64f0c5d]1270        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1271        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1272
[9ce41c6]1273   
[7ef319e]1274    def testCriticalPoint(self):
1275        """ Test GuinierModel at the critical point"""
1276        self.assert_(numpy.isfinite(self.comp.run(0.0)))
[9ce41c6]1277       
1278       
1279class TestDebyeModel(unittest.TestCase):
1280    """ Unit tests for Debye Model"""
1281   
1282    def setUp(self):
1283        from sans.models.DebyeModel import DebyeModel
1284        self.comp = DebyeModel()
1285        self.comp.setParam('rg', 50.0)
1286        self.comp.setParam('scale',1.0)
1287        self.comp.setParam('background',0.001)
1288       
1289        self.x = numpy.array([0.4, 1.3])
1290        self.y = numpy.array([0.5, 1.57])
1291       
1292        self.x_array = self.comp.evalDistribution(self.x)
1293        self.y_array = self.comp.evalDistribution(self.y)
1294        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1295        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1296        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1297       
1298    def test1D(self):
1299        """ Test 1D model for a DebyeModel"""
1300        self.assertAlmostEqual(self.comp.run(0.001),1.00017,4)
1301       
1302    def test1D_2(self):
1303        """ Test 2D model for a DebyeModel"""
1304        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.00017,4)
1305       
1306    def testEval_1D(self):
1307        """ Test 1D model for a DebyeModel with evalDistribution"""
1308        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1309        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1310       
1311    def testEval_2D(self):
1312        """ Test 2D model for a DebyeModel with evalDistribution"""
[64f0c5d]1313        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1314        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1315
[9ce41c6]1316   
[7ef319e]1317    def testCriticalPoint(self):
1318        """ Test DebyeModel at the critical point"""
1319        self.assertEquals(self.comp.run(0.0),1.001)
1320       
[9ce41c6]1321       
1322class TestPorodModel(unittest.TestCase):
1323    """ Unit tests for PorodModel"""
1324   
1325    def setUp(self):
1326        from sans.models.PorodModel import PorodModel
1327        self.comp = PorodModel()
1328        self.comp.setParam('scale', 1.0)
1329        self.comp.setParam('background', 0.0)
1330         
1331        self.x = numpy.array([0.4, 1.3])
1332        self.y = numpy.array([0.5, 1.57])
1333       
1334        self.x_array = self.comp.evalDistribution(self.x)
1335        self.y_array = self.comp.evalDistribution(self.y)
1336        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1337        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1338        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1339       
1340    def test1D(self):
1341        """ Test 1D model for a PorodModel"""
1342        self.assertEquals(self.comp.run(0.5), 16)
1343       
1344    def test1D_2(self):
1345        """ Test 2D model for a PorodModel"""
1346        self.assertEquals(self.comp.run([0.5, 1.3]),16) 
1347       
1348    def testEval_1D(self):
1349        """ Test 1D model for a PorodModel with evalDistribution"""
1350        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1351        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1352       
1353    def testEval_2D(self):
1354        """ Test 2D model for a PorodModel with evalDistribution"""
[64f0c5d]1355        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1356        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1357
[9ce41c6]1358   
[7ef319e]1359    def testCreaticalPoint(self):
[9ce41c6]1360        """ Test for critical point for PorodModel run"""
1361        self.assertRaises(ZeroDivisionError, self.comp.run, 0.0)
1362       
1363       
1364class TestPeakGaussModel(unittest.TestCase):
1365    """ Unit tests for PeakGaussModel"""
1366   
1367    def setUp(self):
1368        from sans.models.PeakGaussModel import PeakGaussModel
1369        self.comp = PeakGaussModel()
1370        self.comp.setParam('scale', 100)
1371        self.comp.setParam('B', 0.005)
1372        self.comp.setParam('q0',0.05)
1373        self.comp.setParam('background',1.0)
1374       
1375        self.x = numpy.array([0.4, 1.3])
1376        self.y = numpy.array([0.5, 1.57])
1377       
1378        self.x_array = self.comp.evalDistribution(self.x)
1379        self.y_array = self.comp.evalDistribution(self.y)
1380        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1381        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1382        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1383       
1384    def test1D(self):
1385        """ Test 1D model for a PeakGauss Model"""
1386        self.assertEquals(self.comp.run(0.001),1)
1387       
1388    def test1D_2(self):
1389        """ Test 2D model for a PeakGauss Model"""
1390        self.assertEquals(self.comp.run([0.001, 1.3]),1) 
1391       
1392    def testEval_1D(self):
1393        """ Test 1D model for a PeakGauss Model with evalDistribution"""
1394        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1395        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1396       
1397    def testEval_2D(self):
1398        """ Test 2D model for a PeakGauss Model with evalDistribution"""
[64f0c5d]1399        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1400        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
[7ef319e]1401   
1402    def testCriticalPoint(self):
1403        """ Test PeakGauss at the critical point"""
1404        self.assert_(numpy.isfinite(self.comp.run(0.0)))   
[9ce41c6]1405       
1406class TestPeakLorentzModel(unittest.TestCase):
1407    """ Unit tests for PeakLorentzModel"""
1408   
1409    def setUp(self):
1410        from sans.models.PeakLorentzModel import PeakLorentzModel
1411        self.comp = PeakLorentzModel()
1412        self.comp.setParam('scale', 100)
1413        self.comp.setParam('B', 0.005)
1414        self.comp.setParam('q0',0.05)
1415        self.comp.setParam('background',1.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])
[64f0c5d]1424        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1425       
1426    def test1D(self):
1427        """ Test 1D model for a PeakLorentz Model"""
1428        self.assertAlmostEqual(self.comp.run(0.001), 2.0305, 3)
1429       
1430    def test1D_2(self):
1431        """ Test 2D model for a PeakLorentz Model"""
1432        self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 2.0305, 3)
1433       
1434    def testEval_1D(self):
1435        """ Test 1D model for a PeakLorentz 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 PeakLorentz Model with evalDistribution"""
[64f0c5d]1441        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1442        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1443
[9ce41c6]1444       
[7ef319e]1445    def testCriticalPoint(self):
1446        """ Test PeakLorentz at the critical point"""
1447        self.comp.setParam('B', 0.0)
1448        self.assertRaises(ZeroDivisionError, self.comp.run, 10)
[279e371]1449        #self.assert_(numpy.isfinite(self.comp.run(0.0)))       
[9ce41c6]1450   
1451class TestFractalModel(unittest.TestCase):
1452    """ Unit tests for FractalModel"""
1453   
1454    def setUp(self):
1455        from sans.models.FractalModel import FractalModel
1456        self.comp = FractalModel()
1457        self.comp.setParam('scale', 0.05)
1458        self.comp.setParam('radius', 5.0)
1459        self.comp.setParam('fractal_dim', 2.0)
[64f0c5d]1460        self.comp.setParam('cor_length',100.0)
1461        self.comp.setParam('sldBlock', 2.0e-6)
1462        self.comp.setParam('sldSolv', 6.35e-6)
[9ce41c6]1463        self.comp.setParam('background',0.0)
1464       
1465        self.x = numpy.array([0.4, 1.3])
1466        self.y = numpy.array([0.5, 1.57])
1467       
1468        self.x_array = self.comp.evalDistribution(self.x)
1469        self.y_array = self.comp.evalDistribution(self.y)
1470        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1471        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1472        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1473       
1474    def test1D(self):
1475        """ Test 1D model for a Fractal Model"""
1476        self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3)
1477       
1478    def test1D_2(self):
1479        """ Test 2D model for a Fractal Model"""
1480        self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3)
1481       
1482    def testEval_1D(self):
1483        """ Test 1D model for a Fractal Model with evalDistribution"""
1484        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1485        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1486       
1487    def testEval_2D(self):
1488        """ Test 2D model for a Fractal Model with evalDistribution"""
[64f0c5d]1489        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1490        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1491
1492    # No more singular point   
1493    #def testCriticalPoint(self):
1494    #    """ Test Fractal at the critical point"""
1495    #    self.assert_(numpy.isfinite(self.comp.run(0.0)))
[9ce41c6]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])
[64f0c5d]1514        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]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"""
[64f0c5d]1531        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1532        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1533
[7ef319e]1534         
1535    def testCriticalPoint(self):
1536        """ Test Lorentz at the critical point"""
1537        self.assert_(numpy.isfinite(self.comp.run(0.0)))
1538       
1539         
[9ce41c6]1540class TestPowerLawAbsModel(unittest.TestCase):
1541    """ Unit tests for PowerLawAbsModel"""
1542   
1543    def setUp(self):
1544        from sans.models.PowerLawAbsModel import PowerLawAbsModel
1545        self.comp = PowerLawAbsModel()
1546        self.comp.setParam("background",1)
1547        self.comp.setParam("m",4)
1548        self.comp.setParam("scale",1e-6)
1549       
1550        self.x = numpy.array([0.4, 1.3])
1551        self.y = numpy.array([0.5, 1.57])
1552        self.x_array = self.comp.evalDistribution(self.x)
1553        self.y_array = self.comp.evalDistribution(self.y)
1554        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1555        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1556        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1557       
1558    def test1D(self):
1559        """ Test 1D model for a PowerLawAbs Model"""
1560        self.assertAlmostEqual(self.comp.run(0.19189), 1.00074,4)
1561       
1562    def test1D_2(self):
1563        """ Test 2D model for a PowerLawAbs Model"""
1564        self.assertAlmostEqual(self.comp.run([0.19189,1.3]), 1.00074,4)
1565       
1566    def testEval_1D(self):
1567        """ Test 1D model for a PowerLawAbs Model with evalDistribution"""
1568        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1569        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1570       
1571    def testEval_2D(self):
1572        """ Test 2D model for a PowerLawAbs Model with evalDistribution"""
[64f0c5d]1573        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1574        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1575
[9ce41c6]1576   
[7ef319e]1577    def testCriticalPoint(self):
1578        """ Test PowerLawAbs at the critical point"""
1579        self.assert_(numpy.isfinite(self.comp.run(0.0)))
1580       
1581       
[9ce41c6]1582class TestPowerLawModel(unittest.TestCase):
1583    """ Unit tests for PowerLawModel"""
1584   
1585    def setUp(self):
1586        from sans.models.PowerLawModel import PowerLawModel
1587        self.comp = PowerLawModel()
1588        self.comp.setParam("background",1)
1589        self.comp.setParam("m",4)
1590        self.comp.setParam("scale",1e-6)
1591       
1592        self.x = numpy.array([0.4, 1.3])
1593        self.y = numpy.array([0.5, 1.57])
1594        self.x_array = self.comp.evalDistribution(self.x)
1595        self.y_array = self.comp.evalDistribution(self.y)
1596        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1597        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1598        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1599       
1600    def test1D(self):
1601        """ Test 1D model for a PowerLaw Model"""
1602        self.assertAlmostEquals(self.comp.run(0.19189), 1.00074,4)
1603       
1604    def test1D_2(self):
1605        """ Test 2D model for a PowerLawModel"""
1606        self.assertAlmostEquals(self.comp.run([0.19189,1.3]), 1.00074,4)
1607       
1608    def testEval_1D(self):
1609        """ Test 1D model for a PowerLawModel with evalDistribution"""
1610        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1611        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1612       
1613    def testEval_2D(self):
1614        """ Test 2D model for a PowerLawModel with evalDistribution"""
[64f0c5d]1615        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1616        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1617
[7ef319e]1618   
1619    def testCriticalPoint(self):
1620        """ Test PowerLawModel at the critical point"""
1621        self.assert_(numpy.isfinite(self.comp.run(0.0)))
[9ce41c6]1622     
1623     
1624class TestTeubnerStreyModel(unittest.TestCase):
1625    """ Unit tests for TeubnerStreyModel"""
1626   
1627    def setUp(self):
1628        from sans.models.TeubnerStreyModel import TeubnerStreyModel
1629        self.comp = TeubnerStreyModel()
1630        self.comp.setParam("background",0.1)
1631        self.comp.setParam("c1",-30)
1632        self.comp.setParam("c2",5000)
1633        self.comp.setParam("scale",0.1)
1634       
1635        self.x = numpy.array([0.4, 1.3])
1636        self.y = numpy.array([0.5, 1.57])
1637        self.x_array = self.comp.evalDistribution(self.x)
1638        self.y_array = self.comp.evalDistribution(self.y)
1639        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1640        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1641        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1642       
1643    def test1D(self):
1644        """ Test 1D model for a TeubnerStrey Model"""
1645        self.assertAlmostEqual(self.comp.run(0.001),10.103, 1)
1646       
1647    def test1D_2(self):
1648        """ Test 2D model for a TeubnerStrey Model"""
1649        self.assertAlmostEqual(self.comp.run([0.001, 1.3]),10.103, 1)
1650       
1651    def testEval_1D(self):
1652        """ Test 1D model for a TeubnerStrey  with evalDistribution"""
1653        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1654        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1655       
1656    def testEval_2D(self):
1657        """ Test 2D model for a TeubnerStrey  with evalDistribution"""
[64f0c5d]1658        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8)
1659        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1660
[7ef319e]1661   
1662    def testCriticalPoint(self):
1663        """ Test TeubnerStrey at the critical point"""
1664        self.assert_(numpy.isfinite(self.comp.run(0.0)))   
1665     
[9ce41c6]1666     
1667class TestLineModel(unittest.TestCase):
1668    """ Unit tests for LineModel"""
1669   
1670    def setUp(self):
1671        from sans.models.LineModel import LineModel
1672        self.comp = LineModel()
1673        self.comp.setParam("A",1)
1674        self.comp.setParam("B",1)
1675       
1676        self.x = numpy.array([0.4, 1.3])
1677        self.y = numpy.array([0.5, 1.57])
1678        self.x_array = self.comp.evalDistribution(self.x)
1679        self.y_array = self.comp.evalDistribution(self.y)
1680        qx_prime = numpy.reshape(self.x, [1,len(self.x)])
1681        qy_prime = numpy.reshape(self.y, [len(self.y),1])
[64f0c5d]1682        self.xy_matrix = self.comp.evalDistribution([self.x, self.y])
[9ce41c6]1683       
1684    def test1D(self):
1685        """ Test 1D model for a Line Model"""
1686        self.assertEquals(self.comp.run(1.0),2)
1687       
1688    def testEval_1D(self):
1689        """ Test 1D model for a Line  with evalDistribution"""
1690        self.assertEquals(self.comp.run(0.4),self.x_array[0])
1691        self.assertEquals(self.comp.run(1.3),self.x_array[1])
1692       
1693    def testEval_2D(self):
1694        """ Test 2D model for a Line  with evalDistribution"""
[64f0c5d]1695        self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0], 8)
1696        self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8)
1697
[7ef319e]1698   
1699    def testCriticalPoint(self):
1700        """ Test line at the critical point"""
1701        self.assert_(numpy.isfinite(self.comp.run(0.0)))
[9fafa39]1702
1703class TestMassFractalModel(unittest.TestCase):
1704    """ Unit tests for MassFractalModel: Need to verify the test value"""
1705   
1706    def setUp(self):
1707        from sans.models.MassFractalModel import MassFractalModel
1708        self.comp = MassFractalModel()
1709       
1710    def testEval_1D(self):
1711        """ Test 1D model for a MassFractalModel"""
1712        self.assertAlmostEquals(self.comp.run(0.05), 279.59322, 4)
1713
1714class TestSurfaceFractalModel(unittest.TestCase):
1715    """ Unit tests for SurfaceFractalModel: Need to verify the test value"""
1716   
1717    def setUp(self):
1718        from sans.models.SurfaceFractalModel import SurfaceFractalModel
1719        self.comp = SurfaceFractalModel()
1720       
1721    def testEval_1D(self):
1722        """ Test 1D model for a SurfaceFractal"""
1723        self.assertAlmostEquals(self.comp.run(0.05), 301428.65916, 4)
1724
1725class TestMassSurfaceFractal(unittest.TestCase):
1726    """ Unit tests for MassSurfaceFractal: Need to verify the test value"""
1727   
1728    def setUp(self):
1729        from sans.models.MassSurfaceFractal import MassSurfaceFractal
1730        self.comp = MassSurfaceFractal()
1731       
1732    def testEval_1D(self):
1733        """ Test 1D model for a MassSurfaceFractal"""
1734        self.assertAlmostEquals(self.comp.run(0.05), 1.77537e-05, 4)
1735       
[9ce41c6]1736if __name__ == '__main__':
1737    unittest.main()
Note: See TracBrowser for help on using the repository browser.