source: sasview/sansmodels/src/sans/models/test/utest_extra_models.py @ 339ce67

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 339ce67 was 339ce67, checked in by Jae Cho <jhjcho@…>, 14 years ago

added some models and tests

  • Property mode set to 100644
File size: 7.6 KB
Line 
1"""
2Unit tests for extra models,PolymerexclVolume, RPA10Model
3The reference values are calculated on IGOR/NIST package(Oct.,2010)
4@author: JHJ Cho / UTK
5"""
6import unittest
7class TestPolymerExclVolume(unittest.TestCase):
8    """
9    Unit tests for PolymerexclVolume (non-shape) function
10    """
11    def setUp(self):
12        from sans.models.PolymerExclVolume import PolymerExclVolume
13        self.model= PolymerExclVolume()
14       
15    def test1D(self):         
16        # the values are from Igor pro calculation   
17        self.assertAlmostEqual(self.model.run(0.001), 0.998801, 6)
18        self.assertAlmostEqual(self.model.run(0.21571), 0.00192041, 6)
19        self.assertAlmostEqual(self.model.runXY(0.41959), 0.000261302, 6)
20       
21class TestRPA10Case(unittest.TestCase):
22    """
23    Unit tests for RPA10Model (non-shape) function
24    """
25    def setUp(self):
26        from sans.models.RPA10Model import RPA10Model
27        self.model0= RPA10Model(0)
28        self.model1= RPA10Model(1)
29        self.model2= RPA10Model(2)
30        self.model3= RPA10Model(3)
31        self.model4= RPA10Model(4)
32        self.model5= RPA10Model(5)
33        self.model6= RPA10Model(6)
34        self.model7= RPA10Model(7)
35        self.model8= RPA10Model(8)
36        self.model9= RPA10Model(9)
37       
38    def test1D(self):         
39        # the test values are from Igor pro calculation   
40        # case 0
41        # set default of vol fration consistent with IGor
42        self.model0.setParam('Phic',0.5)
43        self.model0.setParam('Phid',0.5)
44        self.assertAlmostEqual(self.model0.run(0.001), 0.0716863, 6)
45        self.assertAlmostEqual(self.model0.runXY(0.414955), 0.00396997, 6)
46        # case 1
47        # set default of vol fration consistent with IGor
48        self.model1.setParam('Phic',0.5)
49        self.model1.setParam('Phid',0.5)
50        self.assertAlmostEqual(self.model1.run(0.001), 0.00395016, 6)
51        self.assertAlmostEqual(self.model1.runXY(0.414955), 0.00396735, 6)
52        # case 2
53        # set default of vol fration consistent with IGor
54        self.model2.setParam('Phib',0.33)
55        self.model2.setParam('Phic',0.33)
56        self.model2.setParam('Phid',0.33)
57        self.assertAlmostEqual(self.model2.run(0.001), 0.0932902, 6)
58        self.assertAlmostEqual(self.model2.runXY(0.414955), 0.00355736, 6)
59        # case 3
60        # set default of vol fration consistent with IGor
61        self.model3.setParam('Phib',0.33)
62        self.model3.setParam('Phic',0.33)
63        self.model3.setParam('Phid',0.33)
64        self.assertAlmostEqual(self.model3.run(0.001), 0.026254, 6)
65        self.assertAlmostEqual(self.model3.runXY(0.414955), 0.00355577, 6)
66        # case 4
67        # set default of vol fration consistent with IGor
68        self.model4.setParam('Phib',0.33)
69        self.model4.setParam('Phic',0.33)
70        self.model4.setParam('Phid',0.33)
71        self.assertAlmostEqual(self.model4.run(0.001), 0.0067433, 6)
72        self.assertAlmostEqual(self.model4.runXY(0.414955), 0.00355656, 6)
73        # case 5
74        self.assertAlmostEqual(self.model5.run(0.001), 0.102636, 6)
75        self.assertAlmostEqual(self.model5.runXY(0.414955), 0.00305812, 6)
76        # case 6
77        self.assertAlmostEqual(self.model6.run(0.001), 0.0370357, 6)
78        self.assertAlmostEqual(self.model6.runXY(0.414955), 0.00305708, 6)
79        # case 7
80        self.assertAlmostEqual(self.model7.run(0.001), 0.0167775, 6)
81        self.assertAlmostEqual(self.model7.runXY(0.414955), 0.00305743, 6)
82        # case 8
83        self.assertAlmostEqual(self.model8.run(0.001), 0.0378691, 6)
84        self.assertAlmostEqual(self.model8.runXY(0.414955), 0.00305743, 6)
85        # case 9
86        self.assertAlmostEqual(self.model9.run(0.001), 0.00839376, 6)
87        self.assertAlmostEqual(self.model9.runXY(0.414955), 0.00305777, 6) 
88             
89class TestBarBell(unittest.TestCase):
90    """
91    Unit tests for BarBell function
92    """
93    def setUp(self):
94        from sans.models.BarBellModel import BarBellModel
95        self.model= BarBellModel()
96       
97    def test1D(self):         
98        # the values are from Igor pro calculation   
99        self.assertAlmostEqual(self.model.run(0.001), 2864.7, 1)
100        self.assertAlmostEqual(self.model.run(0.215268), 0.526351, 4)
101        self.assertAlmostEqual(self.model.runXY(0.414467), 0.0685892, 6)
102
103class TestCappedCylinder(unittest.TestCase):
104    """
105    Unit tests for CappedCylinder function
106    """
107    def setUp(self):
108        from sans.models.CappedCylinderModel import CappedCylinderModel
109        self.model= CappedCylinderModel()
110       
111    def test1D(self):         
112        # the values are from Igor pro calculation 
113        # the different digits are due to precision of q values 
114        self.assertAlmostEqual(self.model.run(0.001), 1424.72, 2)
115        self.assertAlmostEqual(self.model.run(0.215268), 0.360736, 4)
116        self.assertAlmostEqual(self.model.runXY(0.414467), 0.110283, 5)
117
118class TestLamellarParaCrystal(unittest.TestCase):
119    """
120    Unit tests for LamellarParaCystal function
121    """
122    def setUp(self):
123        from sans.models.LamellarPCrystalModel import LamellarPCrystalModel
124        self.model= LamellarPCrystalModel()
125       
126    def test1D(self):   
127        self.model.setParam("pd_spacing", 0.2)     
128        # the values are from Igor pro calculation 
129        # the different digits are due to precision of q values 
130        self.assertAlmostEqual(self.model.run(0.001), 21829.3, 1)
131        self.assertAlmostEqual(self.model.run(0.215268), 0.00487686, 6)
132        self.assertAlmostEqual(self.model.runXY(0.414467), 0.00062029, 6)
133
134
135class TestSCParaCrystal(unittest.TestCase):
136    """
137    Unit tests for Simple Cubic ParaCrystal Model function
138    """
139    def setUp(self):
140        from sans.models.SCCrystalModel import SCCrystalModel
141        self.model= SCCrystalModel()
142       
143    def test1D(self):       
144        # the values are from Igor pro calculation 
145        # the different digits are due to precision of q values 
146        self.assertAlmostEqual(self.model.run(0.001), 10.3038, 4)
147        self.assertAlmostEqual(self.model.run(0.215268), 0.00714905, 6)
148        self.assertAlmostEqual(self.model.runXY(0.414467), 0.000313289, 6)
149
150class TestFCParaCrystal(unittest.TestCase):
151    """
152    Unit tests for Face Centered Cubic ParaCrystal Model function
153    """
154    def setUp(self):
155        from sans.models.FCCrystalModel import FCCrystalModel
156        self.model= FCCrystalModel()
157       
158    def test1D(self):       
159        self.model.setParam("d_factor", 0.05) 
160        # the values are from Igor pro calculation 
161        # the different digits are due to precision of q values 
162        self.assertAlmostEqual(self.model.run(0.001), 0.121017, 6)
163        self.assertAlmostEqual(self.model.run(0.215268), 0.0107218, 6)
164        self.assertAlmostEqual(self.model.runXY(0.414467), 0.000443282, 6)
165
166class TestBCParaCrystal(unittest.TestCase):
167    """
168    Unit tests for Body Centered Cubic ParaCrystal Model function
169    """
170    def setUp(self):
171        from sans.models.BCCrystalModel import BCCrystalModel
172        self.model= BCCrystalModel()
173       
174    def test1D(self):       
175        # the values are from Igor pro calculation 
176        # the different digits are due to precision of q values 
177        self.assertAlmostEqual(self.model.run(0.001), 1.77267, 4)
178        self.assertAlmostEqual(self.model.run(0.215268), 0.00927739, 6)
179        self.assertAlmostEqual(self.model.runXY(0.414467), 0.000406973, 6)
180                                                       
181if __name__ == '__main__':
182    unittest.main()
Note: See TracBrowser for help on using the repository browser.