source: sasview/sansmodels/test/utest_models_array.py @ f80236f

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f80236f was 18e250c, checked in by Gervaise Alina <gervyh@…>, 13 years ago

move test to sansmodels top level

  • Property mode set to 100644
File size: 3.1 KB
Line 
1"""
2    Unit tests for specific models using numpy array input
3    @author: Gervaise B Alina/ UTK
4"""
5
6import unittest, time, math, numpy
7
8       
9class 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       
46class 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', 1.0 * 180/3.1415)
72        self.comp.setParam('cyl_phi', 1.0 * 180/3.1415)
73        self.assertAlmostEqual(self.comp.run([0.2, 2.5]), 
74                               0.038176446608393366, 3)
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
85if __name__ == '__main__':
86    unittest.main()
Note: See TracBrowser for help on using the repository browser.