source: sasview/sansmodels/src/sans/models/test/utest_models_array.py @ 812b901

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 812b901 was 812b901, checked in by Gervaise Alina <gervyh@…>, 15 years ago

write run function for vector also

  • Property mode set to 100644
File size: 3.3 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 """
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        testvector= self.comp.run(self.x)
23       
24        self.assertAlmostEqual(len(testvector),4)
25        for i in xrange(len(answer)):
26            self.assertAlmostEqual(testvector[i],answer[i])
27       
28    def test1D_1(self):
29        """ Test 2D model for a sphere  with scalar as input"""
30        self.assertAlmostEqual(self.comp.run(1.0),5.63877831e-05, 4)
31         
32    def test1D_2(self):
33        """ Test 2D model for a sphere for 2 scalar """
34        self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878e-06, 4)
35   
36       
37class TestCylinder(unittest.TestCase):
38    """ Unit tests for sphere model """
39   
40    def setUp(self):
41        from sans.models.CylinderModel import CylinderModel
42        self.comp = CylinderModel()
43        self.x = numpy.array([1.0,2.0,3.0, 4.0])
44        self.y = numpy.array([1.0,2.0,3.0, 4.0])
45       
46    def test1D(self):
47        """ Test 1D model for a Cylinder  with vector as input"""
48        answer = numpy.array([1.98860592e-04,7.03686335e-05,2.89144683e-06,2.04282827e-06])
49        testvector= self.comp.run(self.x)
50       
51        self.assertAlmostEqual(len(testvector),4)
52        for i in xrange(len(answer)):
53            self.assertAlmostEqual(testvector[i],answer[i])
54       
55    def test1D_1(self):
56        """ Test 2D model for a Cylinder with scalar as input"""
57        self.assertAlmostEqual(self.comp.run(1.0),1.9886e-04, 4)
58         
59    def test1D_2(self):
60        """ Test 2D model for a Cylinder for 2 scalar """
61        self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878e-06, 4)
62       
63    def test1D_3(self):
64        """ Test 2D model for a Cylinder for 2 vectors as input """
65        ans_input = numpy.zeros(len(self.x))
66        temp_x = numpy.zeros(len(self.x))
67        temp_y = numpy.zeros(len(self.y))
68       
69        for i in xrange(len(self.x)):
70            qx = self.x[i]
71            qy = self.y[i]
72         
73            temp_x[i]= qx*math.cos(qy)
74            temp_y[i]= qx*math.sin(qy)
75           
76            value = math.sqrt(temp_x[i]*temp_x[i]+ temp_y[i]*temp_y[i] )#qx*qx +qy*qy)
77            ans_input[i]= value
78         
79        vect_runXY_qx_qy = self.comp.runXY([temp_x, temp_y])
80        vect_run_x_y = self.comp.run([self.x, self.y])
81       
82        for i in xrange(len(vect_runXY_qx_qy)):
83            self.assertAlmostEqual(vect_runXY_qx_qy[i], vect_run_x_y[i])
84           
85        vect_run_x = self.comp.run(self.x)
86        vect_run_answer = self.comp.run(ans_input)
87       
88        for i in xrange(len(vect_run_x )):
89            self.assertAlmostEqual(vect_run_x [i], vect_run_answer[i])
90           
91
92
93if __name__ == '__main__':
94    unittest.main()
Note: See TracBrowser for help on using the repository browser.