Index: Invariant/test/utest_data_handling.py
===================================================================
--- Invariant/test/utest_data_handling.py	(revision aafa962bf871a37b5ba098610635d93c7a8f200f)
+++ Invariant/test/utest_data_handling.py	(revision 97603c0a5ab6dd3ea8294d338e6c4057b954bc9f)
@@ -13,4 +13,5 @@
 from DataLoader.data_info import Data1D
 from sans.invariant import invariant
+from DataLoader.qsmearing import smear_selection
     
 class TestLinearFit(unittest.TestCase):
@@ -206,3 +207,120 @@
         self.assertEqual(len(y_out), 3)
         self.assertEqual(len(dy_out), 3)
-    
+
+    
+class TestDataExtraLow(unittest.TestCase):
+    """
+        Generate a Guinier distribution and verify that the extrapolation
+        produce the correct ditribution. Tested if the data generated by the 
+        invariant calculator is correct
+    """
+    
+    def setUp(self):
+        """
+            Generate a Guinier distribution. After extrapolating, we will
+            verify that we obtain the scale and rg parameters
+        """
+        self.scale = 1.5
+        self.rg = 30.0
+        x = numpy.arange(0.0001, 0.1, 0.0001)
+        y = numpy.asarray([self.scale * math.exp( -(q*self.rg)**2 / 3.0 ) for q in x])
+        dy = y*.1
+        self.data = Data1D(x=x, y=y, dy=dy)
+        
+    def test_low_q(self):
+        """
+            Invariant with low-Q extrapolation with no slit smear
+        """
+        # Create invariant object. Background and scale left as defaults.
+        inv = invariant.InvariantCalculator(data=self.data)
+        # Set the extrapolation parameters for the low-Q range
+        inv.set_extrapolation(range='low', npts=20, function='guinier')
+        
+        self.assertEqual(inv._low_extrapolation_npts, 20)
+        self.assertEqual(inv._low_extrapolation_function.__class__, invariant.Guinier)
+        
+        # Data boundaries for fiiting
+        qmin = inv._data.x[0]
+        qmax = inv._data.x[inv._low_extrapolation_npts - 1]
+        
+        # Extrapolate the low-Q data
+        a, b = inv._fit(model=inv._low_extrapolation_function,
+                          qmin=qmin,
+                          qmax=qmax,
+                          power=inv._low_extrapolation_power)
+        self.assertAlmostEqual(self.scale, a, 6)
+        self.assertAlmostEqual(self.rg, b, 6)
+        
+        qstar = inv.get_qstar(extrapolation='low')
+        reel_y = self.data.y
+        test_y = inv._low_extrapolation_function.evaluate_model(x=self.data.x)
+        for i in range(len(self.data.x)):
+            value  = math.fabs(test_y[i]-reel_y[i])/reel_y[i]
+            self.assert_(value < 0.001)
+            
+class TestDataExtraLowSlit(unittest.TestCase):
+    """
+        Generate a Guinier distribution and verify that the extrapolation
+        produce the correct ditribution. Tested if the data generated by the 
+        invariant calculator is correct
+    """
+    
+    def setUp(self):
+        """
+            Generate a Guinier distribution. After extrapolating, we will
+            verify that we obtain the scale and rg parameters
+        """
+        list = Loader().load("latex_smeared.xml")
+        self.data = list[0]
+        self.data.dxl = list[0].dxl
+        self.data.dxw = list[0].dxw
+        
+    def test_low_q(self):
+        """
+            Invariant with low-Q extrapolation with slit smear
+        """
+        # Create invariant object. Background and scale left as defaults.
+        inv = invariant.InvariantCalculator(data=self.data)
+        # Set the extrapolation parameters for the low-Q range
+        inv.set_extrapolation(range='low', npts=20, function='guinier')
+        
+        self.assertEqual(inv._low_extrapolation_npts, 20)
+        self.assertEqual(inv._low_extrapolation_function.__class__, invariant.Guinier)
+        
+        # Data boundaries for fiiting
+        qmin = inv._data.x[0]
+        qmax = inv._data.x[inv._low_extrapolation_npts - 1]
+        
+        # Extrapolate the low-Q data
+        a, b = inv._fit(model=inv._low_extrapolation_function,
+                          qmin=qmin,
+                          qmax=qmax,
+                          power=inv._low_extrapolation_power)
+      
+        
+        qstar = inv.get_qstar(extrapolation='low')
+        reel_y = self.data.y
+        #Compution the y 's coming out of the invariant when computing extrapolated
+        #low data . expect the fit engine to have been already called and the guinier
+        # to have the radius and the scale fitted
+        
+        test_y = numpy.zeros(len(self.data.x))
+        smearer = smear_selection(self.data)
+        first_bin, last_bin = smearer.get_bin_range(min(self.data.x),
+                                                         max(self.data.x))
+        test_y[first_bin:last_bin] = inv._low_extrapolation_function.evaluate_model(self.data.x[first_bin:last_bin])
+        test_y = smearer(test_y, first_bin, last_bin) 
+        
+        for i in range(len(self.data.x)):
+            value  = math.fabs(test_y[i]-reel_y[i])/reel_y[i]
+            self.assert_(value < 0.001)
+            
+        # test data coming out of the invariant 
+        test_y = inv._low_extrapolation_function.evaluate_model(x=self.data.x)
+        for i in range(len(self.data.x)):
+            value  = math.fabs(test_y[i]-reel_y[i])/reel_y[i]
+            self.assert_(value < 0.001)
+            
+            
+                    
+            
