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

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

write unittest for guinier model

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