[d17597f] | 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() |
---|
[d9547e7] | 13 | from sans.models.LinearPearlsModel import LinearPearlsModel |
---|
| 14 | self.lpm = LinearPearlsModel() |
---|
[d17597f] | 15 | from sans.models.SphereModel import SphereModel |
---|
| 16 | self.sphere = SphereModel() |
---|
| 17 | from sans.models.BarBellModel import BarBellModel |
---|
| 18 | self.bar = BarBellModel() |
---|
| 19 | |
---|
| 20 | def testwithsphere(self): |
---|
| 21 | """ Compare 1D model with sphere """ |
---|
| 22 | self.pnl.setParam("radius", 60) |
---|
| 23 | self.pnl.setParam("num_pearls", 1) |
---|
| 24 | self.pnl.setParam("sld_pearl", 2e-06) |
---|
| 25 | self.pnl.setParam("sld_solv", 1e-06) |
---|
| 26 | self.assertAlmostEqual(self.pnl.run(0.001), self.sphere.run(0.001), 5) |
---|
| 27 | self.assertAlmostEqual(self.pnl.run(0.005), self.sphere.run(0.005), 5) |
---|
| 28 | self.assertAlmostEqual(self.pnl.run(0.01), self.sphere.run(0.01), 5) |
---|
| 29 | self.assertAlmostEqual(self.pnl.run(0.05), self.sphere.run(0.05), 5) |
---|
| 30 | self.assertAlmostEqual(self.pnl.run(0.1), self.sphere.run(0.1), 5) |
---|
| 31 | self.assertAlmostEqual(self.pnl.run(0.5), self.sphere.run(0.5), 5) |
---|
| 32 | |
---|
| 33 | def testwithbarbell(self): |
---|
| 34 | """ |
---|
| 35 | Compare 1D model with barbell |
---|
| 36 | |
---|
| 37 | Note: pearlnecklace assumes infinite thin rod |
---|
| 38 | """ |
---|
| 39 | self.pnl.setParam("radius", 20) |
---|
| 40 | self.pnl.setParam("num_pearls", 2) |
---|
| 41 | self.pnl.setParam("sld_pearl", 1e-06) |
---|
| 42 | self.pnl.setParam("sld_string", 1e-06) |
---|
| 43 | self.pnl.setParam("sld_solv", 6.3e-06) |
---|
| 44 | self.pnl.setParam("thick_string", 0.1) |
---|
| 45 | self.pnl.setParam("edge_separation", 400) |
---|
| 46 | self.bar.setParam("rad_bar", 0.1) |
---|
| 47 | self.bar.setParam("rad_bell", 20) |
---|
[d9547e7] | 48 | self.lpm.setParam("radius", 20) |
---|
| 49 | self.lpm.setParam("num_pearls", 2) |
---|
| 50 | self.lpm.setParam("sld_pearl", 1e-06) |
---|
| 51 | self.lpm.setParam("sld_solv", 6.3e-06) |
---|
| 52 | self.lpm.setParam("edge_separation", 400) |
---|
| 53 | |
---|
[d17597f] | 54 | self.assertAlmostEqual(self.pnl.run(0.001), self.bar.run(0.001), 1) |
---|
| 55 | self.assertAlmostEqual(self.pnl.run(0.005), self.bar.run(0.005), 1) |
---|
| 56 | self.assertAlmostEqual(self.pnl.run(0.01), self.bar.run(0.01), 1) |
---|
| 57 | self.assertAlmostEqual(self.pnl.run(0.05), self.bar.run(0.05), 1) |
---|
| 58 | self.assertAlmostEqual(self.pnl.run(0.1), self.bar.run(0.1), 1) |
---|
| 59 | self.assertAlmostEqual(self.pnl.run(0.5), self.bar.run(0.5), 1) |
---|
| 60 | |
---|
[d9547e7] | 61 | self.assertAlmostEqual(self.pnl.run(0.001), self.lpm.run(0.001), 1) |
---|
| 62 | self.assertAlmostEqual(self.pnl.run(0.005), self.lpm.run(0.005), 1) |
---|
| 63 | self.assertAlmostEqual(self.pnl.run(0.01), self.lpm.run(0.01), 1) |
---|
| 64 | self.assertAlmostEqual(self.pnl.run(0.05), self.lpm.run(0.05), 1) |
---|
| 65 | self.assertAlmostEqual(self.pnl.run(0.1), self.lpm.run(0.1), 1) |
---|
| 66 | self.assertAlmostEqual(self.pnl.run(0.5), self.lpm.run(0.5), 1) |
---|
[d17597f] | 67 | |
---|
| 68 | |
---|
| 69 | if __name__ == '__main__': |
---|
| 70 | unittest.main() |
---|