Index: sansmodels/src/sans/models/test/utest_nonshape.py
===================================================================
--- sansmodels/src/sans/models/test/utest_nonshape.py	(revision 829eee9c87a25f8870f8613d915daf0cfa4c4d05)
+++ sansmodels/src/sans/models/test/utest_nonshape.py	(revision f629e346291dbccc6f799045adc85db8e542bdf8)
@@ -5,5 +5,5 @@
 
 import unittest, time, math
-from scipy.special import erf,gamma
+from scipy.special import erf,gammaln
 
 # Disable "missing docstring" complaint
@@ -24,28 +24,28 @@
     """
     def _func(self, a, b, x):
-        return math.exp(a+b*x**2)
-    
-    def setUp(self):
-        from GuinierModel import GuinierModel
+        return a*math.exp(-(b*x)**2/3.0)
+    
+    def setUp(self):
+        from sans.models.GuinierModel import GuinierModel
         self.model= GuinierModel()
         
     def test1D(self):
-        self.model.setParam('A', 2.0)
-        self.model.setParam('B', 1.0)
-        
-        self.assertEqual(self.model.run(0.0), math.exp(2.0))
-        self.assertEqual(self.model.run(2.0), math.exp(2.0+1.0*(2.0)**2))
-        
-    def test2D(self):
-        self.model.setParam('A', 2.0)
-        self.model.setParam('B', 1.0)
+        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))
+        
+    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)
-        self.assertEqual(self.model.runXY([0.0,0.0]), math.exp(2.0)*math.exp(2.0))
-        self.assertEqual(self.model.runXY([1.0,2.0]), value)
-        
-    def test2Dphi(self):
-        self.model.setParam('A', 2.0)
-        self.model.setParam('B', 1.0)
+        self.assertEqual(self.model.runXY([0.0,0.0]), 2.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
@@ -64,15 +64,15 @@
         Unit tests for Porod function
         
-        F(x) = exp[ [C]/Q**4 ]
+        F(x) = C/Q**4 
         
         The model has one parameter: C
     """
     def _func(self, c, x):
-        return math.exp(c/(x*x*x*x))
-    
-    def setUp(self):
-        from PorodModel import PorodModel
+        return c/(x**4)
+    
+    def setUp(self):
+        from sans.models.PorodModel import PorodModel
         self.model= PorodModel()
-        self.model.setParam('c', 2.0)        
+        self.model.setParam('scale', 2.0)        
         
     def test1D(self):
@@ -109,9 +109,9 @@
     
     def setUp(self):
-        from DebyeModel import DebyeModel
+        from sans.models.DebyeModel import DebyeModel
         self.model= DebyeModel()
         self.model.setParam('Rg', 50.0)    
         self.model.setParam('scale',1.0) 
-        self.model.setParam('bkd',0.001)   
+        self.model.setParam('background',0.001)   
         
     def test1D(self):
@@ -119,7 +119,7 @@
         self.assertEqual(self.model.run(2.0), value)
         
-        #user enter zero as a value of x
-        self.assertEqual(self.model.run(0.0),False)
-       
+        # User enter zero as a value of x
+        # An exceptio is raised
+        self.assertRaises(ZeroDivisionError, self.model.run, 0.0)
         
     def test2D(self):
@@ -148,14 +148,15 @@
             bkd    =  incoherent background
     """
-    def _func(self,scale,L,bkd,x):
-         return scale/( 1 + (x*L)**2 ) + bkd 
-    def setUp(self):
-        from LorentzModel import LorentzModel
+    def _func(self, I0 , L, bgd, qval):
+        return I0/(1.0 + (qval*L)*(qval*L)) + bgd
+    
+    def setUp(self):
+        from sans.models.LorentzModel import LorentzModel
         self.model= LorentzModel()
         
     def test1D(self):
         self.model.setParam('scale', 100.0)
-        self.model.setParam('L', 50.0)
-        self.model.setParam('bkd', 1.0)
+        self.model.setParam('Length', 50.0)
+        self.model.setParam('background', 1.0)
         
         self.assertEqual(self.model.run(0.0), 101.0)
@@ -164,6 +165,6 @@
     def test2D(self):
         self.model.setParam('scale', 100.0)
-        self.model.setParam('L', 50.0)
-        self.model.setParam('bkd', 1.0)
+        self.model.setParam('Length', 50.0)
+        self.model.setParam('background', 1.0)
         
         value = self._func(100.0, 50.0, 1.0, 1.0)*self._func(100.0, 50.0, 1.0, 2.0)    
@@ -172,6 +173,6 @@
     def test2Dphi(self):
         self.model.setParam('scale', 100.0)
-        self.model.setParam('L', 50.0)
-        self.model.setParam('bkd', 1.0)
+        self.model.setParam('Length', 50.0)
+        self.model.setParam('background', 1.0)
         
         x = 1.0
@@ -194,15 +195,15 @@
             bkd    =  incoherent background
     """
-    def _func(self, a, b,c, x):
-        return a/(( 1 + ( x * b )**2 ))**2 + c
-    
-    def setUp(self):
-        from DABModel import DABModel
+    def _func(self, Izero, range, incoh, qval):
+        return Izero/pow((1.0 + (qval*range)*(qval*range)),2) + incoh
+    
+    def setUp(self):
+        from sans.models.DABModel import DABModel
         self.model= DABModel()
         
     def test1D(self):
         self.model.setParam('scale', 10.0)
-        self.model.setParam('L', 40.0)
-        self.model.setParam('bkd', 0.0)
+        self.model.setParam('Length', 40.0)
+        self.model.setParam('background', 0.0)
         
         self.assertEqual(self.model.run(0.0), 10.0)
@@ -211,6 +212,6 @@
     def test2D(self):
         self.model.setParam('scale', 10.0)
-        self.model.setParam('L', 40.0)
-        self.model.setParam('bkd', 0.0)
+        self.model.setParam('Length', 40.0)
+        self.model.setParam('background', 0.0)
         
         value = self._func(10.0, 40.0, 0.0, 1.0)*self._func(10.0, 40.0, 0.0, 2.0)    
@@ -219,6 +220,6 @@
     def test2Dphi(self):
         self.model.setParam('scale', 10.0)
-        self.model.setParam('L', 40.0)
-        self.model.setParam('bkd', 0.0)
+        self.model.setParam('Length', 40.0)
+        self.model.setParam('background', 0.0)
         
         x = 1.0
@@ -241,9 +242,10 @@
             bkd    =  incoherent background
     """
-    def _func(self, a, m,c, x):
-        return a*(x )**m + c
-    
-    def setUp(self):
-        from PowerLawModel import PowerLawModel
+    def _func(self, a, m, bgd, qval):
+        return a*math.pow(qval,-m) + bgd
+    
+    
+    def setUp(self):
+        from sans.models.PowerLawModel import PowerLawModel
         self.model= PowerLawModel()
         
@@ -251,13 +253,20 @@
         self.model.setParam('scale', math.exp(-6))
         self.model.setParam('m', 4.0)
-        self.model.setParam('bkd', 1.0)
+        self.model.setParam('background', 1.0)
+        
+        #self.assertEqual(self.model.run(0.0), 1.0)
+        self.assertEqual(self.model.run(2.0), self._func(math.exp(-6), 4.0, 1.0, 2.0))
+    
+    def testlimit(self):
+        self.model.setParam('scale', math.exp(-6))
+        self.model.setParam('m', -4.0)
+        self.model.setParam('background', 1.0)
         
         self.assertEqual(self.model.run(0.0), 1.0)
-        self.assertEqual(self.model.run(2.0), self._func(math.exp(-6), 4.0, 1.0, 2.0))
         
     def test2D(self):
         self.model.setParam('scale', math.exp(-6))
         self.model.setParam('m', 4.0)
-        self.model.setParam('bkd', 1.0)
+        self.model.setParam('background', 1.0)
         
         value = self._func(math.exp(-6), 4.0, 1.0, 1.0)\
@@ -269,5 +278,5 @@
         self.model.setParam('scale', math.exp(-6))
         self.model.setParam('m', 4.0)
-        self.model.setParam('bkd', 1.0)
+        self.model.setParam('background', 1.0)
         
         x = 1.0
@@ -292,9 +301,13 @@
             bkd    =  incoherent background
     """
-    def _func(self, a,c1,c2,b, x):
-        return 1/( a + c1*(x)**(2)+  c2*(x)**(4)) + b
-    
-    def setUp(self):
-        from TeubnerStreyModel import TeubnerStreyModel
+    def _func(self, scale, c1, c2, bck, q):
+        
+        q2 = q*q;
+        q4 = q2*q2;
+    
+        return 1.0/(scale + c1*q2+c2*q4) + bck
+    
+    def setUp(self):
+        from sans.models.TeubnerStreyModel import TeubnerStreyModel
         self.model= TeubnerStreyModel()
         
@@ -304,7 +317,7 @@
         self.model.setParam('c2', 5000.0) 
         self.model.setParam('scale', 0.1)
-        self.model.setParam('bkd', 0.1)
+        self.model.setParam('background', 0.1)
         #self.assertEqual(1/(math.sqrt(4)), math.pow(4,-1/2))
-        self.assertEqual(self.model.TeubnerStreyLengths(),False )
+        #self.assertEqual(self.model.TeubnerStreyLengths(),False )
         
         self.assertEqual(self.model.run(0.0), 10.1)
@@ -315,5 +328,5 @@
         self.model.setParam('c2', 5000.0) 
         self.model.setParam('scale', 0.1)
-        self.model.setParam('bkd', 0.1)
+        self.model.setParam('background', 0.1)
         value = self._func(0.1,-30.0,5000.0,0.1, 1.0)\
         *self._func(0.1,-30.0,5000.0,0.1, 2.0)    
@@ -325,5 +338,5 @@
         self.model.setParam('c2', 5000.0) 
         self.model.setParam('scale', 0.1)
-        self.model.setParam('bkd', 0.1)
+        self.model.setParam('background', 0.1)
         
         x = 1.0
@@ -358,66 +371,54 @@
     
     def setUp(self):
-        from BEPolyelectrolyte import BEPolyelectrolyte
+        from sans.models.BEPolyelectrolyte import BEPolyelectrolyte
         self.model= BEPolyelectrolyte()
         
-    def test1D(self):
-        
-        self.model.setParam('K', 10.0) 
-        self.model.setParam('Lb', 7.1) 
-        self.model.setParam('H', 12)
-        self.model.setParam('B', 10)
-        self.model.setParam('Cs',0.0) 
-        self.model.setParam('alpha', 0.05) 
-        self.model.setParam('C', 0.7)
-        self.model.setParam('bkd', 0.001)
-        K2 = 4 * math.pi * 7.1 * (2*0.0 + 0.05*0.7)
-        Ca = 0.7 * 6.022136 * math.exp(-4)
-        r02 =1/(0.05 * math.pow(Ca,0.5)*(10/math.pow((48* math.pi *7.1),0.5)))
- 
-        
-        self.assertEqual(self.model.run(0.0), self._func( 10.0, 7.1, 12,\
-                        10.0, 0.0,0.05,0.7,0.001, r02, K2,  0.0))
-        self.assertEqual(self.model.run(2.0),  self._func( 10.0, 7.1, 12,\
-                        10.0, 0.0,0.05,0.7,0.001, r02, K2,  2.0))
-        
-    def test2D(self):
-        self.model.setParam('K', 10.0) 
-        self.model.setParam('Lb', 7.1) 
-        self.model.setParam('H', 12)
-        self.model.setParam('B', 10)
-        self.model.setParam('Cs',0.0) 
-        self.model.setParam('alpha', 0.05) 
-        self.model.setParam('C', 0.7)
-        self.model.setParam('bkd', 0.001)
-        K2 = 4 * math.pi * 7.1 * (2*0.0 + 0.05*0.7)
-        Ca = 0.7 * 6.022136 * math.exp(-4)
-        r02 =1/(0.05 * math.pow(Ca,0.5)*(10/math.pow((48* math.pi *7.1),0.5)))
- 
-        value = self._func(10.0, 7.1, 12, 10.0, 0.0,0.05,0.7,0.001, r02, K2,  1.0)\
-        *self._func(10.0, 7.1, 12,10.0, 0.0,0.05,0.7,0.001, r02, K2, 2.0)    
-        
-        self.assertAlmostEquals(self.model.runXY([1.0,2.0]), value)
-        
-    def test2Dphi(self):
-        self.model.setParam('K', 10.0) 
-        self.model.setParam('Lb', 7.1) 
-        self.model.setParam('H', 12)
-        self.model.setParam('B', 10)
-        self.model.setParam('Cs',0.0) 
-        self.model.setParam('alpha', 0.05) 
-        self.model.setParam('C', 0.7)
-        self.model.setParam('bkd', 0.001)
-        K2 = 4 * math.pi * 7.1 * (2*0.0 + 0.05*0.7)
-        Ca = 0.7 * 6.022136 * math.exp(-4)
-        r02 =1/(0.05 * math.pow(Ca,0.5)*(10/math.pow((48* math.pi *7.1),0.5)))
-        
-        x = 1.0
-        y = 2.0
-        r = math.sqrt(x**2 + y**2)
-        phi = math.atan2(y, x)
-        
-        value = self._func(10.0, 7.1, 12, 10.0, 0.0,0.05,0.7,0.001, r02, K2,  x)\
-        *self._func(10.0, 7.1, 12, 10.0, 0.0,0.05,0.7,0.001, r02, K2, y)
-        self.assertAlmostEquals(self.model.run([r, phi]), value,1)
+        self.K = 10.0
+        self.Lb = 6.5
+        self.h = 11
+        self.b = 13
+        self.Cs = 0.1
+        self.alpha = 0.05
+        self.C  = .7
+        self.Bkd =0.01
+       
+        self.model.setParam('K', self.K) 
+        self.model.setParam('Lb', self.Lb) 
+        self.model.setParam('H', self.h)
+        self.model.setParam('B', self.b)
+        self.model.setParam('Cs',self.Cs) 
+        self.model.setParam('alpha', self.alpha) 
+        self.model.setParam('C', self.C)
+        self.model.setParam('background', self.Bkd)
+        
+    def _func(self, q):
+        
+        Ca = self.C *6.022136e-4          
+        Csa = self.Cs * 6.022136e-4        
+        k2= 4*math.pi*self.Lb*(2*self.Cs+self.alpha*Ca)   
+
+        r02 = 1./self.alpha / Ca**0.5*( self.b / (48*math.pi*self.Lb)**0.5 )
+        q2 = q**2    
+        Sq = self.K*1./(4*math.pi*self.Lb*self.alpha**2) * (q2 + k2)  /  (1+(r02**2) * (q2+k2) * (q2- (12*self.h*Ca/self.b**2)) ) + self.Bkd
+        return Sq
+       
+    def test1D(self):
+        
+       
+        q = 0.001
+   
+        self.assertEqual(self.model.run(q), self._func(q))
+         
+    def test2D(self):
+        self.assertAlmostEquals(self.model.runXY([1.0,2.0]), self._func(1.0)*self._func(2.0), 8)
+        
+    def test2Dphi(self):
+
+        x = 1.0
+        y = 2.0
+        r = math.sqrt(x**2 + y**2)
+        phi = math.atan2(y, x)
+        
+        self.assertAlmostEquals(self.model.run([r, phi]), self._func(x)*self._func(y), 8)
         
 class TestFractalModel(unittest.TestCase):
@@ -434,81 +435,38 @@
             bkd     =  background
     """
-    def _func(self,p,s, bkd, x):
-        return p*s + bkd
-    
-    def setUp(self):
-        from FractalModel import FractalModel
+    def setUp(self):
+        from sans.models.FractalModel import FractalModel
         self.model= FractalModel()
         
     def test1D(self):
-        
-        self.model.setParam('scale', 0.05) 
-        self.model.setParam('Radius',5) 
-        self.model.setParam('Fdim',2)
-        self.model.setParam('L', 100)
-        self.model.setParam('SDLB',2*math.exp(-6)) 
-        self.model.setParam('SDLS', 6.35*math.exp(-6)) 
-        self.model.setParam('bkd', 0.0)
-        
-        s= 1 + (math.sin((2 - 1) * math.atan(2.0*100))* 2 * gamma(2-1))\
-           /( math.pow( (2.0*5),2)*( 1 + 1/math.pow(((2.0**2)*(100**2)),(2-1)/2))) 
-        v= (4/3)*math.pi *math.pow(5, 3)
-        f= ( math.sin(2.0*5)-(2.0*5)*math.cos(2.0*5) )/(3*math.pow(2.0*5, 3))
-        p= 0.05 *(v**2)*(((2*math.exp(-6))-(6.35*math.exp(-6)))**2)*(f**2)
+        r0 = 5.0
+        sldp = 2.0e-6
+        sldm = 6.35e-6
+        phi = 0.05
+        Df = 2
+        corr = 100.0
+        bck = 1.0
+        
+        x = 0.001
+        
+        self.model.setParam('scale', phi) 
+        self.model.setParam('Radius', r0) 
+        self.model.setParam('fractal_dim',Df)
+        self.model.setParam('corr_length', corr)
+        self.model.setParam('block_sld', sldp) 
+        self.model.setParam('solvent_sld', sldm) 
+        self.model.setParam('background', bck)
+        
+        pq = 1.0e8*phi*4.0/3.0*math.pi*r0*r0*r0*(sldp-sldm)*(sldp-sldm)*math.pow((3*(math.sin(x*r0) - x*r0*math.cos(x*r0))/math.pow((x*r0),3)),2);
+        
+        sq = Df*math.exp(gammaln(Df-1.0))*math.sin((Df-1.0)*math.atan(x*corr));
+        sq /= math.pow((x*r0),Df) * math.pow((1.0 + 1.0/(x*corr)/(x*corr)),((Df-1.0)/2.0));
+        sq += 1.0;
        
-        self.assertEqual(self.model._scatterRanDom(2.0),p )
-        self.assertEqual(self.model._Block(2.0),s )
-        self.assertEqual(self.model.run(2.0),self._func(p,s ,0.0,2.0))
-        
-class TestUnifiedPowerLaw(unittest.TestCase):
-    """
-        Unit tests for Unified PowerLaw function
-
-        F(x) =  bkd + sum(G[i]*exp(-x**2 *Rg[i]**2 /3)) \
-          + [B[i]( erf(x*Rg[i]/math.sqrt(6)))** (3*p[i])]/x**p[i] )
-        
-    """
-  
-    def setUp(self):
-        from  UnifiedPowerLaw import  UnifiedPowerLawModel
-        self.model=  UnifiedPowerLawModel()
-        
-    def _func(self,level,B,Rg,G,Pow,bkd, x):
-        return bkd + (B * math.pow(erf(x *Rg/math.sqrt(6)),3 *Pow))/math.pow(x,Pow)
-    
-    def _Sum (self,level,x):
-        self.sum = 0
-        for i in xrange(level):
-            self.sum =self.sum +self.model.getParam('G'+str(i+1))*math.exp(-(x**2)*\
-                         (self.model.getParam('Rg'+str(i+1))**2)/3)
-        return self.sum
-    
-    def test1D(self):
-        
-
-        self.model.setParam('bkd', 0.0)
-        #setValueParam(self,level,Bvalue,Rgvalue,Gvalue,Pvalue)
-        self.model.setValueParam(1,2,1,2,5)
-        self.model.setValueParam(2,3,12,8,9)
-        self.model.setValueParam(3,0,2,3,2)
-        self.model.setValueParam(4,1,4,1,-1)
-        self.model.setValueParam(5,1,4,1,-2)
-        
-        self.assertEqual(self.model.getValue('P',1),5)
-        self.assertEqual(self.model.getValue('Rg',2),12)
-   
-        value1 = self._func(1,2,1,2,5,0.0,1.0)+self._Sum(5,1.0)
-        value2 = self._func(2,3,12,8,9,0.0,1.0)+self._Sum(5,1.0)
-        value3 = self._func(3,0,2,3,2,0.0,1.0)+self._Sum(5,1.0)
-        value4 = self._func(4,1,4,1,-1,0.0,1.0)+self._Sum(5,1.0)
-        value5 = self._func(5,1,4,1,-2,0.0,1.0)+self._Sum(5,1.0)
-        self.assertEqual(self.model.run(1,1.0), value1)
-        self.assertEqual(self.model.run(2,1.0), value2)
-        self.assertEqual(self.model.run(3,1.0), value3)
-        self.assertEqual(self.model.run(4,1.0), value4)
-        self.assertEqual(self.model.run(5,1.0), value5)
-        
- 
-        
+        self.assertAlmostEqual(self.model._scatterRanDom(x),pq, 8 )
+        
+        self.assertEqual(self.model._Block(x),sq )
+        
+        self.assertEqual(self.model.run(x), pq*sq+bck)
         
 if __name__ == '__main__':
