source: sasview/sansmodels/test/utest_disperser.py @ 5f15492

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 5f15492 was 77220ee, checked in by Jae Cho <jhjcho@…>, 13 years ago

update sans_extensions name in import

  • Property mode set to 100644
File size: 3.5 KB
Line 
1"""
2    Unit tests for specific models
3    @author: Mathieu Doucet / UTK
4"""
5
6import unittest
7from SmearList import Smear
8
9# Disable "missing docstring" complaint
10# pylint: disable-msg=C0111
11# Disable "too many methods" complaint
12# pylint: disable-msg=R0904
13# Disable "could be a function" complaint
14# pylint: disable-msg=R0201
15
16from sans.models.sans_extension.c_models import Disperser
17from sans.models.ModelFactory import ModelFactory
18from sans.models.DisperseModel import DisperseModel
19     
20class TestDisperser(unittest.TestCase):
21    """ Unit tests for sphere model """
22   
23    def setUp(self):
24        self.model = ModelFactory().getModel("CylinderModel")
25        self.model.setParam("cyl_theta", 1.57)
26        self.model.setParam("cyl_phi", 0.1)
27       
28       
29
30    def testNoDisp(self):
31        """ Test 1D model for a sphere """
32        q = 0.005
33        d = Disperser(self.model, [], [])
34        value = d.run([q, 0])
35        self.assertEqual(value, self.model.run([q, 0]))
36
37    def testComp(self):
38        q = 0.005
39        phi = 0.10
40        sigma = 0.3
41        value_0 = self.model.run([q, phi])
42        app = Smear(self.model, ['cyl_phi'], [sigma])
43        val_py = app.run([q, phi])
44       
45        # Check that the parameters were returned to original values
46        self.assertEqual(value_0, self.model.run([q, phi]))
47        d = Disperser(self.model, ["cyl_phi"], [sigma])
48        val_c = d.run([q, phi])
49        self.assertEqual(val_py, val_c)
50       
51    def test2Disp(self):
52        q = 0.005
53        phi = 0.10
54        sigma = 0.3
55        value_0 = self.model.run([q, phi])
56        app = Smear(self.model, ['cyl_phi', 'cyl_theta'], [sigma, sigma])
57        val_py = app.run([q, phi])
58       
59        # Check that the parameters were returned to original values
60        self.assertEqual(value_0, self.model.run([q, phi]))
61        d = Disperser(self.model, ["cyl_phi", "cyl_theta"], [sigma, sigma])
62        val_c = d.run([q, phi])
63        self.assertEqual(val_py, val_c)
64       
65    def test3Disp(self):
66        q = 0.005
67        phi = 0.10
68        sigma = 0.3
69        value_0 = self.model.run([q, phi])
70        app = Smear(self.model, 
71                    ['cyl_phi', 'cyl_theta', 'radius'], [sigma, sigma, 1.0])
72        val_py = app.run([q, phi])
73       
74        # Check that the parameters were returned to original values
75        self.assertEqual(value_0, self.model.run([q, phi]))
76        d = Disperser(self.model, 
77                      ["cyl_phi", "cyl_theta", 'radius'], [sigma, sigma, 1.0])
78        val_c = d.run([q, phi])
79        self.assertEqual(val_py, val_c)
80       
81       
82class TestDisperserModel(unittest.TestCase):
83    """ Unit tests for sphere model """
84   
85    def setUp(self):
86        self.model = ModelFactory().getModel("CylinderModel")
87        self.model.setParam("cyl_theta", 1.57)
88        self.model.setParam("cyl_phi", 0.1)
89       
90    def test2Disp(self):
91        q = 0.005
92        phi = 0.10
93        sigma = 0.3
94        value_0 = self.model.run([q, phi])
95        app = Smear(self.model, ['cyl_phi', 'cyl_theta'], [sigma, sigma])
96        val_py = app.run([q, phi])
97       
98        # Check that the parameters were returned to original values
99        self.assertEqual(value_0, self.model.run([q, phi]))
100        d = DisperseModel(self.model, ["cyl_phi", "cyl_theta"], [sigma, sigma])
101        val_c = d.run([q, phi])
102        self.assertEqual(val_py, val_c)
103
104
105if __name__ == '__main__':
106    unittest.main()
Note: See TracBrowser for help on using the repository browser.