1 | """ |
---|
2 | Unit tests for specific models |
---|
3 | @author: JHJ Cho / UTK |
---|
4 | """ |
---|
5 | |
---|
6 | import unittest |
---|
7 | |
---|
8 | class TestSphereExpShell1(unittest.TestCase): |
---|
9 | """ |
---|
10 | Unit tests for SphereExpShellModel |
---|
11 | """ |
---|
12 | def setUp(self): |
---|
13 | |
---|
14 | from sans.models.SphereExpShellModel import SphereExpShellModel |
---|
15 | from sans.models.CoreMultiShellModel import CoreMultiShellModel |
---|
16 | from sans.models.VesicleModel import VesicleModel |
---|
17 | |
---|
18 | self.model = SphereExpShellModel(n_shells=1) |
---|
19 | self.model2 = SphereExpShellModel(n_shells=1).model |
---|
20 | self.model3 = CoreMultiShellModel(n_shells=1) |
---|
21 | self.model4 = VesicleModel() |
---|
22 | |
---|
23 | def test_compare_Exp0_flat(self): |
---|
24 | """ |
---|
25 | Check if Exp function with A_shell=0 gives the same value as Flat function |
---|
26 | """ |
---|
27 | print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..." |
---|
28 | # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. |
---|
29 | # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) |
---|
30 | # exp function by default |
---|
31 | # exp function crosses over to flat func at A_shell=0 |
---|
32 | self.model.setParam("A_shell1", 0) |
---|
33 | # set A_shell=1 |
---|
34 | self.model2.setParam("A_shell1", 1) |
---|
35 | # change the function to flat function |
---|
36 | self.model2.setParam("func_shell1", 0) |
---|
37 | #self.model2.setParam("sld_in_shell1", 1.7e-006) |
---|
38 | #self.model2.setParam("sld_out_shell1", 1.7e-006) |
---|
39 | |
---|
40 | # model3: set param values as same as the model2 |
---|
41 | self.model3.setParam("background", 0.0) |
---|
42 | self.model3.setParam("rad_core", 200.0) |
---|
43 | self.model3.setParam("scale", 1.0) |
---|
44 | self.model3.setParam("sld_core", 1.0e-006) |
---|
45 | self.model3.setParam("sld_shell1", 1.7e-006) |
---|
46 | self.model3.setParam("sld_solv", 6.4e-006) |
---|
47 | self.model3.setParam("thick_shell1", 50.0) |
---|
48 | |
---|
49 | #Compare exp(A=0) to flat (where A_shell is null) function |
---|
50 | self.assertEqual(self.model.run(0.1),self.model2.run(0.1)) |
---|
51 | self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) |
---|
52 | |
---|
53 | def test_compare_Exp0_flat_vesicle(self): |
---|
54 | """ |
---|
55 | Check if Exp function with A_shell=0 gives the same value as Flat function of vesicle model when sld_solv=sld_core |
---|
56 | """ |
---|
57 | print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..." |
---|
58 | # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. |
---|
59 | # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) |
---|
60 | # exp function by default |
---|
61 | # exp function crosses over to flat func at A_shell=0 |
---|
62 | self.model.setParam("A_shell1", 0) |
---|
63 | # set A_shell=1 |
---|
64 | self.model2.setParam("A_shell1", 1) |
---|
65 | # change the function to flat function |
---|
66 | self.model2.setParam("func_shell1", 0) |
---|
67 | |
---|
68 | # model: set param values as same as the model2 |
---|
69 | self.model.setParam("background", 0.0) |
---|
70 | self.model.setParam("rad_core", 100.0) |
---|
71 | self.model.setParam("scale", 1.0) |
---|
72 | self.model.setParam("sld_core", 6.36e-006) |
---|
73 | self.model.setParam("sld_in_shell1", 5e-007) |
---|
74 | self.model.setParam("sld_solv", 6.36e-006) |
---|
75 | self.model.setParam("thick_shell1", 30.0) |
---|
76 | # model2: set param values as same as the model2 |
---|
77 | self.model2.setParam("background", 0.0) |
---|
78 | self.model2.setParam("rad_core", 100.0) |
---|
79 | self.model2.setParam("scale", 1.0) |
---|
80 | self.model2.setParam("sld_core", 6.36e-006) |
---|
81 | self.model2.setParam("sld_in_shell1", 5e-007) |
---|
82 | self.model2.setParam("sld_solv", 6.36e-006) |
---|
83 | self.model2.setParam("thick_shell1", 30.0) |
---|
84 | #Compare exp(A=0) to flat (where A_shell is null) function |
---|
85 | self.assertEqual(self.model.run(0.1),self.model4.run(0.1)) |
---|
86 | self.assertEqual(self.model2.run(0.1),self.model4.run(0.1)) |
---|
87 | #self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) |
---|
88 | |
---|
89 | |
---|
90 | def test_compare_Expsmall_line(self): |
---|
91 | """ |
---|
92 | Check if Exp function with A_shell-->0 gives the same value as linear function |
---|
93 | """ |
---|
94 | # exp function crosses over to line func as A_shell-->0 |
---|
95 | self.model.setParam("A_shell1", 0.000001) |
---|
96 | self.model2.setParam("A_shell1", 1) |
---|
97 | # change the function to a line function |
---|
98 | self.model2.setParam("func_shell1", 1) |
---|
99 | |
---|
100 | #Compare exp(A=0.000001) to linear (where A_shell is null) function |
---|
101 | self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4) |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | if __name__ == '__main__': |
---|
106 | unittest.main() |
---|