1 | """ |
---|
2 | Unit tests for specific models II |
---|
3 | """ |
---|
4 | |
---|
5 | import unittest, time, math |
---|
6 | |
---|
7 | class TestPerlNecklace(unittest.TestCase): |
---|
8 | """ Unit tests for PerlNecklace """ |
---|
9 | |
---|
10 | def setUp(self): |
---|
11 | from sans.models.PearlNecklaceModel import PearlNecklaceModel |
---|
12 | self.pnl = PearlNecklaceModel() |
---|
13 | from sans.models.SphereModel import SphereModel |
---|
14 | self.sphere = SphereModel() |
---|
15 | from sans.models.BarBellModel import BarBellModel |
---|
16 | self.bar = BarBellModel() |
---|
17 | |
---|
18 | def testwithsphere(self): |
---|
19 | """ Compare 1D model with sphere """ |
---|
20 | self.pnl.setParam("radius", 60) |
---|
21 | self.pnl.setParam("num_pearls", 1) |
---|
22 | self.pnl.setParam("sld_pearl", 2e-06) |
---|
23 | self.pnl.setParam("sld_solv", 1e-06) |
---|
24 | self.assertAlmostEqual(self.pnl.run(0.001), self.sphere.run(0.001), 5) |
---|
25 | self.assertAlmostEqual(self.pnl.run(0.005), self.sphere.run(0.005), 5) |
---|
26 | self.assertAlmostEqual(self.pnl.run(0.01), self.sphere.run(0.01), 5) |
---|
27 | self.assertAlmostEqual(self.pnl.run(0.05), self.sphere.run(0.05), 5) |
---|
28 | self.assertAlmostEqual(self.pnl.run(0.1), self.sphere.run(0.1), 5) |
---|
29 | self.assertAlmostEqual(self.pnl.run(0.5), self.sphere.run(0.5), 5) |
---|
30 | |
---|
31 | def testwithbarbell(self): |
---|
32 | """ |
---|
33 | Compare 1D model with barbell |
---|
34 | |
---|
35 | Note: pearlnecklace assumes infinite thin rod |
---|
36 | """ |
---|
37 | self.pnl.setParam("radius", 20) |
---|
38 | self.pnl.setParam("num_pearls", 2) |
---|
39 | self.pnl.setParam("sld_pearl", 1e-06) |
---|
40 | self.pnl.setParam("sld_string", 1e-06) |
---|
41 | self.pnl.setParam("sld_solv", 6.3e-06) |
---|
42 | self.pnl.setParam("thick_string", 0.1) |
---|
43 | self.pnl.setParam("edge_separation", 400) |
---|
44 | self.bar.setParam("rad_bar", 0.1) |
---|
45 | self.bar.setParam("rad_bell", 20) |
---|
46 | |
---|
47 | self.assertAlmostEqual(self.pnl.run(0.001), self.bar.run(0.001), 1) |
---|
48 | self.assertAlmostEqual(self.pnl.run(0.005), self.bar.run(0.005), 1) |
---|
49 | self.assertAlmostEqual(self.pnl.run(0.01), self.bar.run(0.01), 1) |
---|
50 | self.assertAlmostEqual(self.pnl.run(0.05), self.bar.run(0.05), 1) |
---|
51 | self.assertAlmostEqual(self.pnl.run(0.1), self.bar.run(0.1), 1) |
---|
52 | self.assertAlmostEqual(self.pnl.run(0.5), self.bar.run(0.5), 1) |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | if __name__ == '__main__': |
---|
57 | unittest.main() |
---|