1 | """ |
---|
2 | Unit tests for specific models using numpy array input |
---|
3 | @author: Gervaise B Alina/ UTK |
---|
4 | """ |
---|
5 | |
---|
6 | import unittest, time, math, numpy |
---|
7 | |
---|
8 | |
---|
9 | class TestSphere(unittest.TestCase): |
---|
10 | """ Unit tests for sphere model using evalDistribution function """ |
---|
11 | |
---|
12 | def setUp(self): |
---|
13 | from sans.models.SphereModel import SphereModel |
---|
14 | self.comp = SphereModel() |
---|
15 | self.x = numpy.array([1.0,2.0,3.0, 4.0]) |
---|
16 | self.y = self.x +1 |
---|
17 | |
---|
18 | def test1D(self): |
---|
19 | """ Test 1D model for a sphere with vector as input""" |
---|
20 | answer = numpy.array([5.63877831e-05,2.57231782e-06,2.73704050e-07,2.54229069e-08]) |
---|
21 | |
---|
22 | |
---|
23 | testvector= self.comp.evalDistribution(self.x) |
---|
24 | |
---|
25 | self.assertAlmostEqual(len(testvector),4) |
---|
26 | for i in xrange(len(answer)): |
---|
27 | self.assertAlmostEqual(testvector[i],answer[i]) |
---|
28 | |
---|
29 | def test1D_1(self): |
---|
30 | """ Test 2D model for a sphere with scalar as input""" |
---|
31 | self.assertAlmostEqual(self.comp.run(1.0),5.63877831e-05, 4) |
---|
32 | |
---|
33 | def test1D_2(self): |
---|
34 | """ Test 2D model for a sphere for 2 scalar """ |
---|
35 | self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878e-06, 4) |
---|
36 | |
---|
37 | def test1D_3(self): |
---|
38 | """ Test 2D model for a Shpere for 2 vectors as input """ |
---|
39 | #x= numpy.reshape(self.x, [len(self.x),1]) |
---|
40 | #y= numpy.reshape(self.y, [1,len(self.y)]) |
---|
41 | vect = self.comp.evalDistribution([self.x,self.y]) |
---|
42 | self.assertAlmostEqual(vect[0],9.2985e-07, 4) |
---|
43 | self.assertAlmostEqual(vect[len(self.x)-1],1.3871e-08, 4) |
---|
44 | |
---|
45 | |
---|
46 | class TestCylinder(unittest.TestCase): |
---|
47 | """ Unit tests for Cylinder model using evalDistribution function """ |
---|
48 | |
---|
49 | def setUp(self): |
---|
50 | from sans.models.CylinderModel import CylinderModel |
---|
51 | self.comp = CylinderModel() |
---|
52 | self.x = numpy.array([1.0,2.0,3.0, 4.0]) |
---|
53 | self.y = self.x +1 |
---|
54 | |
---|
55 | def test1D(self): |
---|
56 | """ Test 1D model for a cylinder with vector as input""" |
---|
57 | |
---|
58 | answer = numpy.array([1.98860592e-04,7.03686335e-05,2.89144683e-06,2.04282827e-06]) |
---|
59 | |
---|
60 | testvector= self.comp.evalDistribution(self.x) |
---|
61 | self.assertAlmostEqual(len(testvector),4) |
---|
62 | for i in xrange(len(answer)): |
---|
63 | self.assertAlmostEqual(testvector[i],answer[i]) |
---|
64 | |
---|
65 | def test1D_1(self): |
---|
66 | """ Test 2D model for a cylinder with scalar as input""" |
---|
67 | self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4) |
---|
68 | |
---|
69 | def test1D_2(self): |
---|
70 | """ Test 2D model of a cylinder """ |
---|
71 | self.comp.setParam('cyl_theta', 10.0) |
---|
72 | self.comp.setParam('cyl_phi', 10.0) |
---|
73 | self.assertAlmostEqual(self.comp.run([0.2, 2.5]), |
---|
74 | 0.038176446608393366, 2) |
---|
75 | |
---|
76 | def test1D_3(self): |
---|
77 | """ Test 2D model for a cylinder for 2 vectors as input """ |
---|
78 | vect = self.comp.evalDistribution([self.x,self.y]) |
---|
79 | |
---|
80 | self.assertAlmostEqual(vect[0],5.06121018e-08,4) |
---|
81 | self.assertAlmostEqual(vect[len(self.x)-1],2.5978e-11, 4) |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | if __name__ == '__main__': |
---|
86 | unittest.main() |
---|