class TestGuinierHayterM(unittest.TestCase):
    """ 
        Unit tests for GuinierModel(Q) * HayterMSAStructure(Q)
    """
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        from sas.models.HayterMSAStructure import HayterMSAStructure
        from sas.models.MultiplicationModel import MultiplicationModel

        self.model = GuinierModel()
        self.model2 = HayterMSAStructure()
        self.model3 = MultiplicationModel(self.model, self.model2)  

    #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions
    def test_multplication_radius(self):
        """
            test multiplication model (check the effective radius & the output
             of the multiplication)
        """
        self.model.setParam("rg", 60)
        self.model.setParam("scale", 1)
        #Compare new method with old method         
        self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1))
        
        #effective radius calculation is not implemented for this model. 
        self.assertEqual(self.model3.calculate_ER(), NotImplemented)       
class TestGuinierHayterM(unittest.TestCase):
    """ 
        Unit tests for GuinierModel(Q) * HayterMSAStructure(Q)
    """
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        from sas.models.HayterMSAStructure import HayterMSAStructure
        from sas.models.MultiplicationModel import MultiplicationModel

        self.model = GuinierModel()
        self.model2 = HayterMSAStructure()
        self.model3 = MultiplicationModel(self.model, self.model2)  

    #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions
    def test_multplication_radius(self):
        """
            test multiplication model (check the effective radius & the output
             of the multiplication)
        """
        self.model.setParam("rg", 60)
        self.model.setParam("scale", 1)
        #Compare new method with old method         
        self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1))
        
        #effective radius calculation is not implemented for this model. 
        self.assertEqual(self.model3.calculate_ER(), NotImplemented)       
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        from sas.models.HayterMSAStructure import HayterMSAStructure
        from sas.models.MultiplicationModel import MultiplicationModel

        self.model = GuinierModel()
        self.model2 = HayterMSAStructure()
        self.model3 = MultiplicationModel(self.model, self.model2)  
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        from sas.models.HayterMSAStructure import HayterMSAStructure
        from sas.models.MultiplicationModel import MultiplicationModel

        self.model = GuinierModel()
        self.model2 = HayterMSAStructure()
        self.model3 = MultiplicationModel(self.model, self.model2)  
class TestGuinier(unittest.TestCase):
    """ Unit tests for calculate_ER (Guinier model) """
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        self.comp = GuinierModel()

    def test(self):
        """ Test 1D model for Guinier """
        #calculate_ER() is not implemented for pure python model functions
        self.assertEqual(self.comp.calculate_ER(), NotImplemented)
class TestGuinier(unittest.TestCase):
    """ Unit tests for calculate_ER (Guinier model) """
    
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        self.comp = GuinierModel()
        
    def test(self):
        """ Test 1D model for Guinier """    
        #calculate_ER() is not implemented for pure python model functions
        self.assertEqual(self.comp.calculate_ER(), NotImplemented)  
 def setUp(self):
     from sas.models.GuinierModel import GuinierModel
     self.comp = GuinierModel()
 def setUp(self):
     from sas.models.GuinierModel import GuinierModel
     self.comp = GuinierModel()
Пример #9
0
class TestGuinier(unittest.TestCase):
    """
        Unit tests for Guinier function
        
        F(x) = exp[ [A] + [B]*Q**2 ]
        
        The model has two parameters: A and B
    """
    def _func(self, a, b, x):
        return a*math.exp(-(b*x)**2/3.0)
    
    def setUp(self):
        from sas.models.GuinierModel import GuinierModel
        self.model= GuinierModel()
        
    def test1D(self):
        self.model.setParam('scale', 2.0)
        self.model.setParam('rg', 1.0)
        
        self.assertEqual(self.model.run(0.0), 2.0)
        self.assertEqual(self.model.run(2.0), 2.0*math.exp(-(1.0*2.0)**2/3.0))
        self.assertEqual(self.model.runXY(2.0), 2.0*math.exp(-(1.0*2.0)**2/3.0))
        
    def test2D(self):
        self.model.setParam('scale', 2.0)
        self.model.setParam('rg', 1.0)
        
        #value = self._func(2.0, 1.0, 1.0)*self._func(2.0, 1.0, 2.0)
        value = self._func(2.0, 1.0, math.sqrt(5.0))
        #self.assertEqual(self.model.runXY([0.0,0.0]), 2.0*2.0)
        self.assertEqual(self.model.runXY([0.0,0.0]), 2.0)
        self.assertEqual(self.model.runXY([1.0,2.0]), value)
        
    def test2Dphi(self):
        self.model.setParam('scale', 2.0)
        self.model.setParam('rg', 1.0)
        
        x = 1.0
        y = 2.0
        r = math.sqrt(x**2 + y**2)
        phi = math.atan2(y, x)
        
        #value = self._func(2.0, 1.0, x)*self._func(2.0, 1.0, y)
        value = self._func(2.0, 1.0, r)
        
        #self.assertEqual(self.model.run([r, phi]), value)
        self.assertAlmostEquals(self.model.run([r, phi]), value,1)