[d0cda82] | 1 | """ |
---|
[c1e865a] | 2 | Unit tests for calculate_ER of specific models |
---|
| 3 | @author: JHJ Cho / UTK |
---|
[d0cda82] | 4 | """ |
---|
| 5 | |
---|
[c1e865a] | 6 | import unittest, time, math, numpy |
---|
[d0cda82] | 7 | |
---|
| 8 | |
---|
| 9 | class TestSphere(unittest.TestCase): |
---|
| 10 | """ Unit tests for calculate_ER (sphere model) """ |
---|
| 11 | |
---|
| 12 | def setUp(self): |
---|
| 13 | from sans.models.SphereModel import SphereModel |
---|
| 14 | self.comp = SphereModel() |
---|
| 15 | |
---|
| 16 | def test(self): |
---|
| 17 | """ Test 1D model for a sphere """ |
---|
| 18 | self.comp.setParam("radius", 20) |
---|
| 19 | self.assertAlmostEqual(self.comp.calculate_ER(), 20) |
---|
| 20 | |
---|
| 21 | class TestCoreShell(unittest.TestCase): |
---|
| 22 | """ Unit tests for calculate_ER (CoreShellModel) """ |
---|
| 23 | |
---|
| 24 | def setUp(self): |
---|
| 25 | from sans.models.CoreShellModel import CoreShellModel |
---|
| 26 | self.comp = CoreShellModel() |
---|
| 27 | |
---|
| 28 | def test(self): |
---|
| 29 | """ Test 1D model for a CoreShell """ |
---|
| 30 | self.comp.setParam("radius", 20) |
---|
| 31 | self.comp.setParam("thickness", 20) |
---|
| 32 | self.assertAlmostEqual(self.comp.calculate_ER(), 40) |
---|
| 33 | |
---|
| 34 | class TestMultiShell(unittest.TestCase): |
---|
| 35 | """ Unit tests for calculate_ER (MultiShellModel) """ |
---|
| 36 | |
---|
| 37 | def setUp(self): |
---|
| 38 | from sans.models.MultiShellModel import MultiShellModel |
---|
| 39 | self.comp = MultiShellModel() |
---|
| 40 | |
---|
| 41 | def test(self): |
---|
| 42 | """ Test 1D model for a MultiShell """ |
---|
| 43 | self.comp.setParam("core_radius", 60) |
---|
| 44 | self.comp.setParam("s_thickness", 10) |
---|
| 45 | self.comp.setParam("w_thickness", 15) |
---|
| 46 | self.comp.setParam("n_pairs", 2) |
---|
| 47 | self.assertAlmostEqual(self.comp.calculate_ER(), 95) |
---|
| 48 | |
---|
| 49 | class TestVesicle(unittest.TestCase): |
---|
| 50 | """ Unit tests for calculate_ER (VesicleModel) """ |
---|
| 51 | |
---|
| 52 | def setUp(self): |
---|
| 53 | from sans.models.VesicleModel import VesicleModel |
---|
| 54 | self.comp = VesicleModel() |
---|
| 55 | |
---|
| 56 | def test(self): |
---|
| 57 | """ Test 1D model for a Vesicle """ |
---|
| 58 | self.comp.setParam("radius", 60) |
---|
| 59 | self.comp.setParam("thickness", 30) |
---|
| 60 | self.assertAlmostEqual(self.comp.calculate_ER(), 90) |
---|
| 61 | |
---|
| 62 | class TestCylinder(unittest.TestCase): |
---|
| 63 | """ Unit tests for calculate_ER (cylinder model) """ |
---|
| 64 | |
---|
| 65 | def setUp(self): |
---|
| 66 | from sans.models.CylinderModel import CylinderModel |
---|
| 67 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 68 | self.comp = CylinderModel() |
---|
| 69 | self.diam = DiamCylFunc() |
---|
| 70 | |
---|
| 71 | def test(self): |
---|
| 72 | """ Test 1D model for a Cylinder """ |
---|
| 73 | self.comp.setParam("radius", 20) |
---|
| 74 | self.comp.setParam("length",400) |
---|
| 75 | self.diam.setParam("radius", 20) |
---|
| 76 | self.diam.setParam("length",400) |
---|
| 77 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 78 | |
---|
| 79 | class TestCoreShellCylinder(unittest.TestCase): |
---|
| 80 | """ Unit tests for calculate_ER (CoreShellcylinder model) """ |
---|
| 81 | |
---|
| 82 | def setUp(self): |
---|
| 83 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
| 84 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 85 | self.comp = CoreShellCylinderModel() |
---|
| 86 | self.diam = DiamCylFunc() |
---|
| 87 | |
---|
| 88 | def test(self): |
---|
| 89 | """ Test 1D model for a CoreShellCylinder """ |
---|
| 90 | self.comp.setParam("radius", 20) |
---|
| 91 | self.comp.setParam("thickness", 10) |
---|
| 92 | self.comp.setParam("length",400) |
---|
| 93 | self.diam.setParam("radius", 30) |
---|
| 94 | self.diam.setParam("length",400) |
---|
| 95 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 96 | |
---|
| 97 | class TestHollowCylinder(unittest.TestCase): |
---|
| 98 | """ Unit tests for calculate_ER (Hollowcylinder model) """ |
---|
| 99 | |
---|
| 100 | def setUp(self): |
---|
| 101 | from sans.models.HollowCylinderModel import HollowCylinderModel |
---|
| 102 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 103 | self.comp = HollowCylinderModel() |
---|
| 104 | self.diam = DiamCylFunc() |
---|
| 105 | |
---|
| 106 | def test(self): |
---|
| 107 | """ Test 1D model for a Hollowcylinder """ |
---|
| 108 | self.comp.setParam("radius", 20) |
---|
| 109 | self.comp.setParam("length",400) |
---|
| 110 | self.diam.setParam("radius", 20) |
---|
| 111 | self.diam.setParam("length",400) |
---|
| 112 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 113 | |
---|
| 114 | class TestStackedDisksModel(unittest.TestCase): |
---|
| 115 | """ Unit tests for calculate_ER (StackedDisks model) """ |
---|
| 116 | |
---|
| 117 | def setUp(self): |
---|
| 118 | from sans.models.StackedDisksModel import StackedDisksModel |
---|
| 119 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 120 | self.comp = StackedDisksModel() |
---|
| 121 | self.diam = DiamCylFunc() |
---|
| 122 | |
---|
| 123 | def test(self): |
---|
| 124 | """ Test 1D model for a StackedDisks """ |
---|
| 125 | self.comp.setParam("radius", 3000) |
---|
| 126 | self.comp.setParam("n_stacking", 2) |
---|
| 127 | self.comp.setParam("core_thick",10) |
---|
| 128 | self.comp.setParam("layer_thick", 15) |
---|
| 129 | self.diam.setParam("radius", 3000) |
---|
| 130 | self.diam.setParam("length",80) |
---|
[c1e865a] | 131 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 132 | |
---|
| 133 | class TestEllipticalCylinder(unittest.TestCase): |
---|
| 134 | """ Unit tests for calculate_ER (EllipticalCylindermodel) """ |
---|
| 135 | |
---|
| 136 | def setUp(self): |
---|
| 137 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
| 138 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 139 | self.comp = EllipticalCylinderModel() |
---|
| 140 | self.diam = DiamCylFunc() |
---|
| 141 | |
---|
| 142 | def test(self): |
---|
| 143 | """ Test 1D model for a EllipticalCylinder """ |
---|
| 144 | self.comp.setParam("r_minor", 20) |
---|
| 145 | self.comp.setParam("r_ratio",1.5) |
---|
| 146 | self.comp.setParam("length",400) |
---|
| 147 | r_value = math.sqrt(20*20*1.5) |
---|
| 148 | self.diam.setParam("radius", r_value) |
---|
| 149 | self.diam.setParam("length",400) |
---|
| 150 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 151 | |
---|
| 152 | class TestParallelepiped(unittest.TestCase): |
---|
| 153 | """ Unit tests for calculate_ER (Parallelepipedmodel) """ |
---|
| 154 | |
---|
| 155 | def setUp(self): |
---|
| 156 | from sans.models.ParallelepipedModel import ParallelepipedModel |
---|
| 157 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 158 | self.comp = ParallelepipedModel() |
---|
| 159 | self.diam = DiamCylFunc() |
---|
| 160 | |
---|
| 161 | def test(self): |
---|
| 162 | """ Test 1D model for a Parallelepiped """ |
---|
| 163 | self.comp.setParam("short_a", 35) |
---|
| 164 | self.comp.setParam("short_b", 75) |
---|
| 165 | self.comp.setParam("long_c",400) |
---|
| 166 | r_value = math.sqrt(35*75/math.pi) |
---|
| 167 | self.diam.setParam("radius", r_value) |
---|
| 168 | self.diam.setParam("length",400) |
---|
| 169 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 170 | |
---|
[d0cda82] | 171 | class TestEllipsoid(unittest.TestCase): |
---|
| 172 | """ Unit tests for calculate_ER (Ellipsoid model) """ |
---|
| 173 | |
---|
| 174 | def setUp(self): |
---|
| 175 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
| 176 | from sans.models.DiamEllipFunc import DiamEllipFunc |
---|
| 177 | self.comp = EllipsoidModel() |
---|
| 178 | self.diam = DiamEllipFunc() |
---|
| 179 | |
---|
| 180 | def test(self): |
---|
| 181 | """ Test 1D model for a Ellipsoid """ |
---|
| 182 | self.comp.setParam("radius_a", 20) |
---|
| 183 | self.comp.setParam("radius_b",400) |
---|
| 184 | self.diam.setParam("radius_a", 20) |
---|
| 185 | self.diam.setParam("radius_b",400) |
---|
| 186 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 187 | |
---|
| 188 | class TestCoreShellEllipsoid(unittest.TestCase): |
---|
| 189 | """ Unit tests for calculate_ER (CoreShellEllipsoid model) """ |
---|
| 190 | |
---|
| 191 | def setUp(self): |
---|
| 192 | from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel |
---|
| 193 | from sans.models.DiamEllipFunc import DiamEllipFunc |
---|
| 194 | self.comp = CoreShellEllipsoidModel() |
---|
| 195 | self.diam = DiamEllipFunc() |
---|
| 196 | |
---|
| 197 | def test(self): |
---|
| 198 | """ Test 1D model for a CoreShellEllipsoid """ |
---|
| 199 | self.comp.setParam("polar_shell", 20) |
---|
| 200 | self.comp.setParam("equat_shell",400) |
---|
| 201 | self.diam.setParam("radius_a", 20) |
---|
| 202 | self.diam.setParam("radius_b",400) |
---|
[c1e865a] | 203 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
[72a05d0] | 204 | |
---|
| 205 | class TestTriaxialEllipsoid(unittest.TestCase): |
---|
| 206 | """ Unit tests for calculate_ER (TriaxialEllipsoid model) """ |
---|
| 207 | |
---|
| 208 | def setUp(self): |
---|
| 209 | from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel |
---|
| 210 | from sans.models.DiamEllipFunc import DiamEllipFunc |
---|
| 211 | self.comp = TriaxialEllipsoidModel() |
---|
| 212 | self.diam = DiamEllipFunc() |
---|
| 213 | |
---|
| 214 | def test(self): |
---|
| 215 | """ Test 1D model for a TriaxialEllipsoid """ |
---|
| 216 | self.comp.setParam("semi_axisA", 35) |
---|
| 217 | self.comp.setParam("semi_axisB", 100) |
---|
| 218 | self.comp.setParam("semi_axisC", 400) |
---|
| 219 | r_value = math.sqrt(35*100) |
---|
| 220 | self.diam.setParam("radius_a", 400) |
---|
| 221 | self.diam.setParam("radius_b",r_value) |
---|
| 222 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
| 223 | |
---|
[c1e865a] | 224 | class TestLamellar(unittest.TestCase): |
---|
| 225 | """ Unit tests for calculate_ER (Lamellarmodel)""" |
---|
| 226 | |
---|
| 227 | def setUp(self): |
---|
| 228 | from sans.models.LamellarModel import LamellarModel |
---|
| 229 | self.comp = LamellarModel() |
---|
| 230 | |
---|
| 231 | def test(self): |
---|
| 232 | """ Test 1D model for a Lamellar """ |
---|
| 233 | #No finite number should return from Lamellar models. |
---|
| 234 | self.assertFalse(numpy.isfinite(self.comp.calculate_ER())) |
---|
| 235 | |
---|
| 236 | class TestGuinier(unittest.TestCase): |
---|
| 237 | """ Unit tests for calculate_ER (Guinier model) """ |
---|
| 238 | |
---|
| 239 | def setUp(self): |
---|
| 240 | from sans.models.GuinierModel import GuinierModel |
---|
| 241 | self.comp = GuinierModel() |
---|
| 242 | |
---|
| 243 | def test(self): |
---|
| 244 | """ Test 1D model for Guinier """ |
---|
| 245 | #calculate_ER() is not implemented for pure python model functions |
---|
| 246 | self.assertEqual(self.comp.calculate_ER(), NotImplemented) |
---|
| 247 | |
---|
[d0cda82] | 248 | if __name__ == '__main__': |
---|
| 249 | unittest.main() |
---|