1 | """ |
---|
2 | Unit tests for specific models |
---|
3 | @author: Mathieu Doucet / UTK |
---|
4 | """ |
---|
5 | |
---|
6 | import unittest |
---|
7 | from 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 | |
---|
16 | from sans_extension.c_models import Disperser |
---|
17 | from sans.models.ModelFactory import ModelFactory |
---|
18 | from sans.models.DisperseModel import DisperseModel |
---|
19 | |
---|
20 | class 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 | |
---|
82 | class 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 | |
---|
105 | if __name__ == '__main__': |
---|
106 | unittest.main() |
---|