Changeset 8809e48 in sasview for sansmodels/src/sans/models/test


Ignore:
Timestamp:
Oct 15, 2008 11:01:06 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
00353b4
Parents:
ae60f86
Message:

Updated cloning

Location:
sansmodels/src/sans/models/test
Files:
1 added
3 edited

Legend:

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

    rae60f86 r8809e48  
    4747        self.assertAlmostEqual(self.model.run(0.001), 4723.32213339, 3) 
    4848        self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 4743.56, 2) 
     49         
     50    def test_clone(self): 
     51        from sans.models.dispersion_models import GaussianDispersion 
     52        disp = GaussianDispersion() 
     53        self.model.set_dispersion('radius', disp) 
     54        self.model.dispersion['radius']['width'] = 5.0 
     55        self.model.dispersion['radius']['npts'] = 100 
     56        self.model.setParam('scale', 10.0) 
     57         
     58        new_model = self.model.clone() 
     59        self.assertAlmostEqual(new_model.run(0.001), 4723.32213339, 3) 
     60        self.assertAlmostEqual(new_model.runXY([0.001,0.001]), 4743.56, 2) 
    4961         
    5062    def test_gaussian_zero(self): 
  • sansmodels/src/sans/models/test/utest_newstylemodels.py

    rae60f86 r8809e48  
    2222        return self.params['scale']*x 
    2323 
    24 from sans.models.BaseModel import BaseModel,ParameterProperty 
     24from sans.models.BaseModel import BaseModel, Parameter, ParameterProperty 
    2525class NewTestModel(BaseModel): 
    2626    scale = ParameterProperty('scale') 
     
    3131        self.parameters['scale'] = Parameter('scale', 4.0)  
    3232         
    33     def run(self, x): 
     33         
     34    def runXY(self, x): 
    3435        return self.scale*x 
    3536         
    36  
     37class TestBogusModel(unittest.TestCase): 
     38    def setUp(self): 
     39        self.model = NewTestModel() 
     40         
     41    def test_call(self): 
     42        self.assertEqual(self.model(1), 4.0) 
     43        self.model.scale = 1.0 
     44        self.assertEqual(self.model(1), 1.0) 
     45        self.model.setParam('scale',2.0) 
     46        self.assertEqual(self.model(1), 2.0) 
     47        self.assertEqual(self.model.getParam('scale'), 2.0) 
     48         
    3749class TestBaseModel(unittest.TestCase): 
    3850    """ 
     
    6678         
    6779         
    68         print self.model.parameters 
    6980         
    7081        print self.model(0.001) 
     82        print self.model.parameters['length'] 
    7183        self.model.setParam("length", 250.0) 
     84        self.assertEquals(self.model.getParam("length"), 250.0) 
     85         
     86        print self.model.parameters['length'] 
    7287        print self.model(0.001) 
    7388         
  • sansmodels/src/sans/models/test/utest_nonshape.py

    ra55fac1 r8809e48  
    130130        # An exceptio is raised 
    131131        self.assertRaises(ZeroDivisionError, self.model.run, 0.0) 
     132         
     133    def test1D_clone(self): 
     134        value = self._func(50.0, 1.0, 10.0, 2.0) 
     135        self.model.setParam('background', 10.0) 
     136        clone = self.model.clone() 
     137        self.assertEqual(clone.run(2.0), value) 
     138        self.assertEqual(clone.runXY(2.0), value) 
     139         
     140        # User enter zero as a value of x 
     141        # An exceptio is raised 
     142        self.assertRaises(ZeroDivisionError, clone.run, 0.0) 
    132143         
    133144    def test2D(self): 
Note: See TracChangeset for help on using the changeset viewer.