Changeset c1e865a in sasview for sansmodels/src/sans


Ignore:
Timestamp:
Sep 11, 2009 10:40:17 AM (15 years ago)
Author:
Jae Cho <jhjcho@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
1affe64
Parents:
f9bf661
Message:

Added more model cases

Location:
sansmodels/src/sans/models/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/test/utest_model_calculate_ER.py

    rca90d54 rc1e865a  
    11""" 
    2     Unit tests for specific models 
     2    Unit tests for calculate_ER of specific models 
     3    @author: JHJ Cho / UTK 
    34""" 
    45 
    5 import unittest, time, math 
    6  
    7 # Disable "missing docstring" complaint 
    8 # pylint: disable-msg=C0111 
    9 # Disable "too many methods" complaint  
    10 # pylint: disable-msg=R0904  
    11 # Disable "could be a function" complaint  
    12 # pylint: disable-msg=R0201 
    13  
     6import unittest, time, math, numpy 
    147 
    158         
     
    136129        self.diam.setParam("radius", 3000) 
    137130        self.diam.setParam("length",80)        
    138         self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)        
    139  
     131        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
     132              
     133class TestEllipticalCylinder(unittest.TestCase): 
     134    """ Unit tests for calculate_ER (EllipticalCylindermodel) """ 
     135     
     136    def setUp(self): 
     137        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 
     138        from sans.models.DiamCylFunc import DiamCylFunc 
     139        self.comp = EllipticalCylinderModel() 
     140        self.diam = DiamCylFunc() 
     141         
     142    def test(self): 
     143        """ Test 1D model for a EllipticalCylinder """ 
     144        self.comp.setParam("r_minor", 20) 
     145        self.comp.setParam("r_ratio",1.5)   
     146        self.comp.setParam("length",400)   
     147        r_value = math.sqrt(20*20*1.5)     
     148        self.diam.setParam("radius", r_value) 
     149        self.diam.setParam("length",400)        
     150        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)   
     151          
     152class TestParallelepiped(unittest.TestCase): 
     153    """ Unit tests for calculate_ER (Parallelepipedmodel) """ 
     154     
     155    def setUp(self): 
     156        from sans.models.ParallelepipedModel import ParallelepipedModel 
     157        from sans.models.DiamCylFunc import DiamCylFunc 
     158        self.comp = ParallelepipedModel() 
     159        self.diam = DiamCylFunc() 
     160         
     161    def test(self): 
     162        """ Test 1D model for a Parallelepiped """ 
     163        self.comp.setParam("short_a", 35) 
     164        self.comp.setParam("short_b", 75)   
     165        self.comp.setParam("long_c",400)   
     166        r_value = math.sqrt(35*75/math.pi)     
     167        self.diam.setParam("radius", r_value) 
     168        self.diam.setParam("length",400)    
     169        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)    
     170                                                   
    140171class TestEllipsoid(unittest.TestCase): 
    141172    """ Unit tests for calculate_ER (Ellipsoid model) """ 
     
    170201        self.diam.setParam("radius_a", 20) 
    171202        self.diam.setParam("radius_b",400) 
    172         self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)                       
     203        self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2)  
     204             
     205class TestLamellar(unittest.TestCase): 
     206    """ Unit tests for calculate_ER (Lamellarmodel)""" 
     207     
     208    def setUp(self): 
     209        from sans.models.LamellarModel import LamellarModel 
     210        self.comp = LamellarModel() 
     211         
     212    def test(self): 
     213        """ Test 1D model for a Lamellar """ 
     214        #No finite number should return from Lamellar models. 
     215        self.assertFalse(numpy.isfinite(self.comp.calculate_ER()))  
     216          
     217class TestGuinier(unittest.TestCase): 
     218    """ Unit tests for calculate_ER (Guinier model) """ 
     219     
     220    def setUp(self): 
     221        from sans.models.GuinierModel import GuinierModel 
     222        self.comp = GuinierModel() 
     223         
     224    def test(self): 
     225        """ Test 1D model for Guinier """     
     226        #calculate_ER() is not implemented for pure python model functions 
     227        self.assertEqual(self.comp.calculate_ER(), NotImplemented)   
     228         
    173229if __name__ == '__main__': 
    174230    unittest.main() 
  • sansmodels/src/sans/models/test/utest_modelmultiplication.py

    rec38f27 rc1e865a  
    11""" 
    22    Unit tests for specific models 
    3     @author: Gervaise Alina / UTK 
     3    @author: JHJ Cho / UTK 
    44""" 
    55#This test replaces the older utests for multiplicationModel. Aug. 31, 2009. JC 
     
    559559class TestcylinderHayterM(unittest.TestCase): 
    560560    """  
    561         Unit tests for SphereModel(Q) * HayterMSAStructure(Q) 
     561        Unit tests for CylinderModel(Q) * HayterMSAStructure(Q) 
    562562    """ 
    563563    def setUp(self): 
     
    635635        self.assertEqual(model4.getParam("radius"), 20)         
    636636         
    637          
     637class TestGuinierHayterM(unittest.TestCase): 
     638    """  
     639        Unit tests for GuinierModel(Q) * HayterMSAStructure(Q) 
     640    """ 
     641    def setUp(self): 
     642        from sans.models.GuinierModel import GuinierModel 
     643        from sans.models.HayterMSAStructure import HayterMSAStructure 
     644        from sans.models.MultiplicationModel import MultiplicationModel 
     645 
     646        self.model = GuinierModel() 
     647        self.model2 = HayterMSAStructure() 
     648        self.model3 = MultiplicationModel(self.model, self.model2)   
     649 
     650    #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions 
     651    def test_multplication_radius(self): 
     652        """ 
     653            test multiplication model (check the effective radius & the output 
     654             of the multiplication) 
     655        """ 
     656        self.model.setParam("rg", 60) 
     657        self.model.setParam("scale", 1) 
     658        #Compare new method with old method          
     659        self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) 
     660         
     661        #effective radius calculation is not implemented for this model.  
     662        self.assertEqual(self.model3.calculate_ER(), NotImplemented)        
     663         
     664class TestLamellarHayterM(unittest.TestCase): 
     665    """  
     666        Unit tests for LamellarModel(Q) * HayterMSAStructure(Q) 
     667    """ 
     668    def setUp(self): 
     669        from sans.models.LamellarModel import LamellarModel 
     670        from sans.models.HayterMSAStructure import HayterMSAStructure 
     671        from sans.models.MultiplicationModel import MultiplicationModel 
     672 
     673        self.model = LamellarModel() 
     674        self.model2 = HayterMSAStructure() 
     675        self.model3 = MultiplicationModel(self.model, self.model2)   
     676 
     677    #Radius of model1.calculate_ER should Not be finite. 
     678    def test_multplication_radius(self): 
     679        """ 
     680            test multiplication model (check the effective radius & the output 
     681             of the multiplication) 
     682        """ 
     683        #Check run        
     684        self.assertFalse(numpy.isfinite(self.model3.run(0.1))) 
     685        #check effective radius .  
     686        self.assertFalse(numpy.isfinite(self.model.calculate_ER()))       
     687                 
    638688if __name__ == '__main__': 
    639689    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.