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 | |
---|
17 | self.model = SphereExpShellModel(n_shells=1) |
---|
18 | self.model2 = SphereExpShellModel(n_shells=1).model |
---|
19 | self.model3 = CoreMultiShellModel(n_shells=1) |
---|
20 | |
---|
21 | def test_compare_Exp0_flat(self): |
---|
22 | """ |
---|
23 | Check if Exp function with A_shell=0 gives the same value as Flat function |
---|
24 | """ |
---|
25 | print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..." |
---|
26 | # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. |
---|
27 | # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) |
---|
28 | # exp function by default |
---|
29 | # exp function crosses over to flat func at A_shell=0 |
---|
30 | self.model.setParam("A_shell1", 0) |
---|
31 | # set A_shell=1 |
---|
32 | self.model2.setParam("A_shell1", 1) |
---|
33 | # change the function to flat function |
---|
34 | self.model2.setParam("func_shell1", 0) |
---|
35 | #self.model2.setParam("sld_in_shell1", 1.7e-006) |
---|
36 | #self.model2.setParam("sld_out_shell1", 1.7e-006) |
---|
37 | |
---|
38 | # model3: set param values as same as the model2 |
---|
39 | self.model3.setParam("background", 0.0) |
---|
40 | self.model3.setParam("rad_core", 200.0) |
---|
41 | self.model3.setParam("scale", 1.0) |
---|
42 | self.model3.setParam("sld_core", 1.0e-006) |
---|
43 | self.model3.setParam("sld_shell1", 1.7e-006) |
---|
44 | self.model3.setParam("sld_solv", 6.4e-006) |
---|
45 | self.model3.setParam("thick_shell1", 50.0) |
---|
46 | |
---|
47 | #Compare exp(A=0) to flat (where A_shell is null) function |
---|
48 | self.assertEqual(self.model.run(0.1),self.model2.run(0.1)) |
---|
49 | self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) |
---|
50 | |
---|
51 | |
---|
52 | def test_compare_Expsmall_line(self): |
---|
53 | """ |
---|
54 | Check if Exp function with A_shell-->0 gives the same value as linear function |
---|
55 | """ |
---|
56 | # exp function crosses over to line func as A_shell-->0 |
---|
57 | self.model.setParam("A_shell1", 0.000001) |
---|
58 | self.model2.setParam("A_shell1", 1) |
---|
59 | # change the function to a line function |
---|
60 | self.model2.setParam("func_shell1", 1) |
---|
61 | |
---|
62 | #Compare exp(A=0.000001) to linear (where A_shell is null) function |
---|
63 | self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4) |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | if __name__ == '__main__': |
---|
68 | unittest.main() |
---|