def setUp(self):

        from sas.models.SphericalSLDModel import SphericalSLDModel
        from sas.models.OnionExpShellModel import OnionExpShellModel

        # intit models and the multifactor
        # layer
        self.model = SphericalSLDModel(1)
        self.model2 = OnionExpShellModel(3)
    def setUp(self):

        from sas.models.OnionExpShellModel import OnionExpShellModel
        from sas.models.CoreMultiShellModel import CoreMultiShellModel
        from sas.models.VesicleModel import VesicleModel 
        
        # intit models and the multifactor
        self.model = OnionExpShellModel(1)
        self.model2 = OnionExpShellModel(1).model
        self.model3 = CoreMultiShellModel(1)
        self.model4 = VesicleModel()
        self.model5 = OnionExpShellModel(9)
    def setUp(self):

        from sas.models.SphericalSLDModel import SphericalSLDModel
        from sas.models.OnionExpShellModel import OnionExpShellModel
        
        # intit models and the multifactor
        # layer 
        self.model = SphericalSLDModel(1)
        self.model2 = OnionExpShellModel(3)
class TestOnionExpShell1(unittest.TestCase):
    """ 
        Unit tests for OnionExpShellModel
    """
    def setUp(self):

        from sas.models.OnionExpShellModel import OnionExpShellModel
        from sas.models.CoreMultiShellModel import CoreMultiShellModel
        from sas.models.VesicleModel import VesicleModel 
        
        # intit models and the multifactor
        self.model = OnionExpShellModel(1)
        self.model2 = OnionExpShellModel(1).model
        self.model3 = CoreMultiShellModel(1)
        self.model4 = VesicleModel()
        self.model5 = OnionExpShellModel(9)
        
    def test_compare_Exp0_flat(self):
        """
        Check if Exp function with A_shell=0 gives the same value as Flat function
        """
        print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..."
        # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0.
        # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell)
        # exp function by default
        # exp function crosses over to flat func at A_shell=0
        self.model.setParam("A_shell1", 0)
        # set A_shell=1
        self.model2.setParam("A_shell1", 1)
        # change the function to flat function
        self.model2.setParam("func_shell1", 0)
        #self.model2.setParam("sld_in_shell1", 1.7e-006)
        #self.model2.setParam("sld_out_shell1", 1.7e-006)
        
        # model3: set param values as same as the model2
        self.model3.setParam("background", 0.0)
        self.model3.setParam("rad_core0", 200.0)
        self.model3.setParam("scale", 1.0)
        self.model3.setParam("sld_core0", 1.0e-006)
        self.model3.setParam("sld_shell1", 1.7e-006)
        self.model3.setParam("sld_solv", 6.4e-006)
        self.model3.setParam("thick_shell1", 50.0)
        
        #Compare exp(A=0) to flat (where A_shell is null) function
        self.assertEqual(self.model.run(0.1),self.model2.run(0.1))
        self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10)
        

  
    def test_compare_Expsmall_line(self):
        """
        Check if Exp function with A_shell-->0 gives the same value 
        as a linear function
        """
        # exp function crosses over to line func as A_shell-->0
        self.model.setParam("A_shell1", 0.000001)
        self.model2.setParam("A_shell1", 1)
        # change the function to a line function
        self.model2.setParam("func_shell1", 1)
        
        #Compare exp(A=0.000001) to linear (where A_shell is null) function   
        self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4)
        
    def test_compare_time_linear_flat_functions(self):
        """
        Compare the calculation time between func=1(linear) , and 2 (step).
        """
        from time import time
        # using linear func
        self.model5.model.setParam("func_shell1", 1)
        #input
        input = [0.01,0.01]
        st = time()
        for iter in range(0,100000):
            out1 = self.model5.model.run(0.01)
        time_linear = time()-st
        
        # using flat function
        self.model5.model.setParam("func_shell1", 0)
        st = time()
        for iter in range(0,100000):
            out2 = self.model5.model.run(0.01)
        time_flat = time()-st
        
        print "time (linear) = %s, \n time (flat) = %s"% (time_linear,time_flat)
        
        #Compare time of the calculation: time_linear takes a bit longer
        # but they are not much different  
        self.assertNotEqual(out1, out2)
        #self.assertAlmostEqual(time_linear, time_flat, 0)
  
    # this feature removed!!!
    """
    def test_compare_Exp0_flat_vesicle(self):
    """
    """
        Check if Exp function with A_shell=0 gives the same value as Flat 
        function of vesicle model when sld_solv=sld_core
        """
    """
class TestSphericalSLDModel(unittest.TestCase):
    """ 
        Unit tests for OnionExpShellModel
    """
    def setUp(self):

        from sas.models.SphericalSLDModel import SphericalSLDModel
        from sas.models.OnionExpShellModel import OnionExpShellModel
        
        # intit models and the multifactor
        # layer 
        self.model = SphericalSLDModel(1)
        self.model2 = OnionExpShellModel(3)
        
    def test_compare_SphericalSLD_OnionExpShell(self):
        """
        Check if SphericalSLD equals (up to 1%) to 
        OnionExpShellModel with an equivalent SLD profile 
        """
        note = "\n*****Note: This test was passes since Nov. 1st, 2010..."
        print note
        # set params
        self.model.setParam("npts_inter", 35)
        self.model.setParam("rad_core0", 100)
        self.model.setParam("thick_inter0", 200)
        self.model.setParam("nu_inter0", 4)
        # Rexp func
        self.model.setParam("func_inter0", 3)
        self.model.setParam("thick_inter1", 200)
        self.model.setParam("nu_inter1", 4)
        self.model.setParam("func_inter1", 3)
        # set A_shell=1
        self.model2.setParam("sld_core0", 2.07e-006)
        # change the function to flat function
        self.model2.setParam("rad_core0", 100)
        self.model2.setParam("thick_shell1", 200)
        self.model2.setParam("sld_out_shell1", 4e-006)
        self.model2.setParam("sld_in_shell1", 2.07e-006)
        self.model2.setParam("A_shell1", -4)
        self.model2.setParam("thick_shell2", 100)
        self.model2.setParam("sld_out_shell2", 4e-006)
        self.model2.setParam("sld_in_shell2", 4e-006)
        self.model2.setParam("A_shell2", 0)
        self.model2.setParam("thick_shell3", 200)
        self.model2.setParam("sld_out_shell3", 1e-006)
        self.model2.setParam("sld_in_shell3", 4e-006)
        self.model2.setParam("A_shell3", -4)
        self.model2.setParam("sld_solv", 1e-006)
        
        #sphericalsld model runs
        model_run_0_1 = self.model.run(0.1)
        model_run_0_01 = self.model.run(0.01)
        model_run_0_001 = self.model.run(0.001)
        #onionexp model runs
        model2_run_0_1 = self.model2.run(0.1)
        model2_run_0_01 = self.model2.run(0.01)
        model2_run_0_001 = self.model2.run(0.001)
        import time
        st = time.time()
        qs = []
        qs = [i/10000 for i in range(1,1000)]
        out = map(self.model.run,qs)
        print time.time()-st
        #Compare exp(A=0) to flat (where A_shell is null) function
        self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4)
        self.assertAlmostEqual(self.model.run(0.01),self.model2.run(0.01),0)
        self.assertAlmostEqual(self.model.run(0.001),self.model2.run(0.001),-3)
class TestSphericalSLDModel(unittest.TestCase):
    """ 
        Unit tests for OnionExpShellModel
    """
    def setUp(self):

        from sas.models.SphericalSLDModel import SphericalSLDModel
        from sas.models.OnionExpShellModel import OnionExpShellModel

        # intit models and the multifactor
        # layer
        self.model = SphericalSLDModel(1)
        self.model2 = OnionExpShellModel(3)

    def test_compare_SphericalSLD_OnionExpShell(self):
        """
        Check if SphericalSLD equals (up to 1%) to 
        OnionExpShellModel with an equivalent SLD profile 
        """
        note = "\n*****Note: This test was passes since Nov. 1st, 2010..."
        print note
        # set params
        self.model.setParam("npts_inter", 35)
        self.model.setParam("rad_core0", 100)
        self.model.setParam("thick_inter0", 200)
        self.model.setParam("nu_inter0", 4)
        # Rexp func
        self.model.setParam("func_inter0", 3)
        self.model.setParam("thick_inter1", 200)
        self.model.setParam("nu_inter1", 4)
        self.model.setParam("func_inter1", 3)
        # set A_shell=1
        self.model2.setParam("sld_core0", 2.07e-006)
        # change the function to flat function
        self.model2.setParam("rad_core0", 100)
        self.model2.setParam("thick_shell1", 200)
        self.model2.setParam("sld_out_shell1", 4e-006)
        self.model2.setParam("sld_in_shell1", 2.07e-006)
        self.model2.setParam("A_shell1", -4)
        self.model2.setParam("thick_shell2", 100)
        self.model2.setParam("sld_out_shell2", 4e-006)
        self.model2.setParam("sld_in_shell2", 4e-006)
        self.model2.setParam("A_shell2", 0)
        self.model2.setParam("thick_shell3", 200)
        self.model2.setParam("sld_out_shell3", 1e-006)
        self.model2.setParam("sld_in_shell3", 4e-006)
        self.model2.setParam("A_shell3", -4)
        self.model2.setParam("sld_solv", 1e-006)

        #sphericalsld model runs
        model_run_0_1 = self.model.run(0.1)
        model_run_0_01 = self.model.run(0.01)
        model_run_0_001 = self.model.run(0.001)
        #onionexp model runs
        model2_run_0_1 = self.model2.run(0.1)
        model2_run_0_01 = self.model2.run(0.01)
        model2_run_0_001 = self.model2.run(0.001)
        import time
        st = time.time()
        qs = []
        qs = [i / 10000 for i in range(1, 1000)]
        out = map(self.model.run, qs)
        print time.time() - st
        #Compare exp(A=0) to flat (where A_shell is null) function
        self.assertAlmostEqual(self.model.run(0.1), self.model2.run(0.1), 4)
        self.assertAlmostEqual(self.model.run(0.01), self.model2.run(0.01), 0)
        self.assertAlmostEqual(self.model.run(0.001), self.model2.run(0.001),
                               -3)