class TestCylinder(unittest.TestCase):
    """ Unit tests for Cylinder model using evalDistribution function """
    
    def setUp(self):
        from sas.models.CylinderModel import CylinderModel
        self.comp = CylinderModel()
        self.x = numpy.array([1.0,2.0,3.0, 4.0])
        self.y = self.x +1
        
    def test1D(self):
        """ Test 1D model for a cylinder with vector as input"""
        
        answer = numpy.array([1.98860592e-04,7.03686335e-05,2.89144683e-06,2.04282827e-06])

        testvector= self.comp.evalDistribution(self.x)
        self.assertAlmostEqual(len(testvector),4)
        for i in xrange(len(answer)):
            self.assertAlmostEqual(testvector[i],answer[i])
       
    def test1D_1(self):
        """ Test 2D model for a cylinder  with scalar as input"""
        self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4)
         
    def test1D_2(self):
        """ Test 2D model of a cylinder """ 
        self.comp.setParam('cyl_theta', 10.0)
        self.comp.setParam('cyl_phi', 10.0)
        self.assertAlmostEqual(self.comp.run([0.2, 2.5]), 
                               0.038176446608393366, 2)
        
    def test1D_3(self):
        """ Test 2D model for a cylinder for 2 vectors as input """
        vect = self.comp.evalDistribution([self.x,self.y])
      
        self.assertAlmostEqual(vect[0],5.06121018e-08,4)
        self.assertAlmostEqual(vect[len(self.x)-1],2.5978e-11, 4)
Beispiel #2
0
class TestCylinder(unittest.TestCase):
    """ Unit tests for Cylinder model using evalDistribution function """
    def setUp(self):
        from sas.models.CylinderModel import CylinderModel
        self.comp = CylinderModel()
        self.x = numpy.array([1.0, 2.0, 3.0, 4.0])
        self.y = self.x + 1

    def test1D(self):
        """ Test 1D model for a cylinder with vector as input"""

        answer = numpy.array(
            [1.98860592e-04, 7.03686335e-05, 2.89144683e-06, 2.04282827e-06])

        testvector = self.comp.evalDistribution(self.x)
        self.assertAlmostEqual(len(testvector), 4)
        for i in xrange(len(answer)):
            self.assertAlmostEqual(testvector[i], answer[i])

    def test1D_1(self):
        """ Test 2D model for a cylinder  with scalar as input"""
        self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4)

    def test1D_2(self):
        """ Test 2D model of a cylinder """
        self.comp.setParam('cyl_theta', 10.0)
        self.comp.setParam('cyl_phi', 10.0)
        self.assertAlmostEqual(self.comp.run([0.2, 2.5]), 0.038176446608393366,
                               2)

    def test1D_3(self):
        """ Test 2D model for a cylinder for 2 vectors as input """
        vect = self.comp.evalDistribution([self.x, self.y])

        self.assertAlmostEqual(vect[0], 5.06121018e-08, 4)
        self.assertAlmostEqual(vect[len(self.x) - 1], 2.5978e-11, 4)