1 | """ |
---|
2 | Unit tests for specific models |
---|
3 | @author: JHJ Cho / UTK |
---|
4 | """ |
---|
5 | |
---|
6 | import unittest |
---|
7 | |
---|
8 | class TestSphericalSLDModel(unittest.TestCase): |
---|
9 | """ |
---|
10 | Unit tests for OnionExpShellModel |
---|
11 | """ |
---|
12 | def setUp(self): |
---|
13 | |
---|
14 | from sans.models.SphericalSLDModel import SphericalSLDModel |
---|
15 | from sans.models.OnionExpShellModel import OnionExpShellModel |
---|
16 | |
---|
17 | # intit models and the multifactor |
---|
18 | # layer |
---|
19 | self.model = SphericalSLDModel(1) |
---|
20 | self.model2 = OnionExpShellModel(3) |
---|
21 | |
---|
22 | def test_compare_SphericalSLD_OnionExpShell(self): |
---|
23 | """ |
---|
24 | Check if SphericalSLD equals (up to 1%) to |
---|
25 | OnionExpShellModel with an equivalent SLD profile |
---|
26 | """ |
---|
27 | note = "\n*****Note: This test was passes since Nov. 1st, 2010..." |
---|
28 | print note |
---|
29 | # set params |
---|
30 | self.model.setParam("npts_inter", 35) |
---|
31 | self.model.setParam("rad_core0", 100) |
---|
32 | self.model.setParam("thick_inter0", 200) |
---|
33 | self.model.setParam("nu_inter0", 4) |
---|
34 | # Rexp func |
---|
35 | self.model.setParam("func_inter0", 3) |
---|
36 | self.model.setParam("thick_inter1", 200) |
---|
37 | self.model.setParam("nu_inter1", 4) |
---|
38 | self.model.setParam("func_inter1", 3) |
---|
39 | # set A_shell=1 |
---|
40 | self.model2.setParam("sld_core0", 2.07e-006) |
---|
41 | # change the function to flat function |
---|
42 | self.model2.setParam("rad_core0", 100) |
---|
43 | self.model2.setParam("thick_shell1", 200) |
---|
44 | self.model2.setParam("sld_out_shell1", 4e-006) |
---|
45 | self.model2.setParam("sld_in_shell1", 2.07e-006) |
---|
46 | self.model2.setParam("A_shell1", -4) |
---|
47 | self.model2.setParam("thick_shell2", 100) |
---|
48 | self.model2.setParam("sld_out_shell2", 4e-006) |
---|
49 | self.model2.setParam("sld_in_shell2", 4e-006) |
---|
50 | self.model2.setParam("A_shell2", 0) |
---|
51 | self.model2.setParam("thick_shell3", 200) |
---|
52 | self.model2.setParam("sld_out_shell3", 1e-006) |
---|
53 | self.model2.setParam("sld_in_shell3", 4e-006) |
---|
54 | self.model2.setParam("A_shell3", -4) |
---|
55 | self.model2.setParam("sld_solv", 1e-006) |
---|
56 | |
---|
57 | #sphericalsld model runs |
---|
58 | model_run_0_1 = self.model.run(0.1) |
---|
59 | model_run_0_01 = self.model.run(0.01) |
---|
60 | model_run_0_001 = self.model.run(0.001) |
---|
61 | #onionexp model runs |
---|
62 | model2_run_0_1 = self.model2.run(0.1) |
---|
63 | model2_run_0_01 = self.model2.run(0.01) |
---|
64 | model2_run_0_001 = self.model2.run(0.001) |
---|
65 | import time |
---|
66 | st = time.time() |
---|
67 | qs = [] |
---|
68 | qs = [i/10000 for i in range(1,1000)] |
---|
69 | out = map(self.model.run,qs) |
---|
70 | print time.time()-st |
---|
71 | #Compare exp(A=0) to flat (where A_shell is null) function |
---|
72 | self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4) |
---|
73 | self.assertAlmostEqual(self.model.run(0.01),self.model2.run(0.01),0) |
---|
74 | self.assertAlmostEqual(self.model.run(0.001),self.model2.run(0.001),-3) |
---|
75 | |
---|
76 | if __name__ == '__main__': |
---|
77 | unittest.main() |
---|