Index: sansguiframe/test/cansas1d.xml
===================================================================
--- sansguiframe/test/cansas1d.xml	(revision 09b73a3821013d4d64c4e69555954fb456c939db)
+++ sansguiframe/test/cansas1d.xml	(revision 09b73a3821013d4d64c4e69555954fb456c939db)
@@ -0,0 +1,141 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="example.xsl" ?>
+<SASroot version="1.0"
+    xmlns="cansas1d/1.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="cansas1d/1.0 http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd"
+    >
+	<SASentry>
+		<Title>Test title</Title>
+		<Run name='run name'>1234</Run>
+		<SASdata>
+			<Idata>
+				<Q unit="1/A">0.02</Q>
+				<I unit="1/cm">1000</I>
+				<Idev unit="1/cm">3</Idev>
+				<Qdev unit="1/A">0.01</Qdev>
+				<Qmean unit="1/A"><!-- Qmean is optional --></Qmean>
+				<Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor>
+			</Idata>
+			<Idata>
+				<Q unit="1/A">0.03</Q>
+				<I unit="1/cm">1001</I>
+				<Idev unit="1/cm">4</Idev>
+				<Qdev unit="1/A">0.02</Qdev>
+				<Qmean unit="1/A"><!-- Qmean is optional --></Qmean>
+				<Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor>
+			</Idata>
+		</SASdata>
+		<SASsample name='my sample'>
+			<ID>SI600-new-long</ID>
+			<thickness unit="mm">1.03</thickness>
+			<transmission>0.327</transmission>
+			<temperature unit="C">0.0000</temperature>
+			<position>
+				<x unit="mm">10.00</x>
+				<y unit="mm">0.00</y>
+			</position>
+			<orientation>
+				<roll unit="degree">22.5<!-- was: sample_orientation --></roll>
+				<pitch unit="degree">0.020<!-- was: sample_offset_angle --></pitch>
+			</orientation>
+			<details>
+				<!-- was: sample_prep -->
+				http://chemtools.chem.soton.ac.uk/projects/blog/blogs.php/bit_id/2720
+			</details>
+			<details>
+				Some text here
+			</details>
+			
+		</SASsample>
+		<SASinstrument name="TEST instrument">
+			<name>canSAS instrument</name>
+			<SASsource name="source name">
+				<radiation>neutron</radiation>
+				<beam_size name='bm'>
+					<x unit="mm">12.00</x>
+					<y unit="mm">13.00</y>
+				</beam_size>
+				<beam_shape>disc</beam_shape>
+				<wavelength unit="A">6.00</wavelength>
+				<wavelength_min unit="nm">0.22</wavelength_min>
+				<wavelength_max unit="nm">1.00</wavelength_max>
+				<wavelength_spread unit="percent">
+					14.3
+				</wavelength_spread>
+			</SASsource>
+			<SAScollimation name="test coll name">
+				<length unit='mm'> 123.0</length>
+				<aperture name="source" type="radius">
+					<size>
+						<x unit="mm">50</x>
+					</size>
+					<distance unit="m">11.000<!-- was: distance_coll --></distance>
+				</aperture>
+				<aperture name="sample" type="radius">
+					<size name='size name'>
+						<x unit="mm">1</x>
+					</size>
+				</aperture>
+			</SAScollimation>
+			<SASdetector>
+				<name>fictional hybrid</name>
+				<SDD unit="m">
+					<!-- sample-to-detector distance -->
+					4.150
+				</SDD>
+				<orientation>
+					<roll unit="degree">1.00</roll>
+					<pitch unit="degree">0.00</pitch>
+					<yaw unit="degree">0.00</yaw>
+				</orientation>
+				<offset>
+					<x unit="mm">1</x>
+					<y unit="mm">2</y>
+				</offset>
+				<beam_center>
+					<x unit="mm">322.64</x>
+					<y unit="mm">327.68</y>
+				</beam_center>
+				<pixel_size>
+					<x unit="mm">5.00</x>
+					<y unit="mm">5.00</y>
+				</pixel_size>
+			</SASdetector>
+		</SASinstrument>
+		<SASprocess>
+			<name>spol</name>
+			<date>04-Sep-2007 18:35:02</date>
+			<term name="radialstep" unit="mm">10.000</term>
+			<term name="sector_width" unit="degree">180.0</term>
+			<term name="sector_orient" unit="degree">0.0</term>
+			<term name="MASK_file">USER:MASK.COM</term>
+			<SASprocessnote>
+				AvA1 0.0000E+00 AsA2 1.0000E+00 XvA3 1.0526E+03 XsA4
+				5.2200E-02 XfA5 0.0000E+00
+			</SASprocessnote>
+			<SASprocessnote>
+				S... 13597 0 2.26E+02 2A 5mM 0%D2O Sbak 13594 0 1.13E+02
+				H2O Buffer
+			</SASprocessnote>
+			<SASprocessnote>V... 13552 3 1.00E+00 H2O5m</SASprocessnote>
+		</SASprocess>
+		<SASprocess>
+			<name>NCNR-IGOR</name>
+			<date>03-SEP-2006 11:42:47</date>
+			<description />
+			<term name="average_type">Circular</term>
+			<term name="SAM_file">SEP06064.SA3_AJJ_L205</term>
+			<term name="BKD_file">SEP06064.SA3_AJJ_L205</term>
+			<term name="EMP_file">SEP06064.SA3_AJJ_L205</term>
+			<term name="DIV_file">SEP06064.SA3_AJJ_L205</term>
+			<term name="MASK_file">SEP06064.SA3_AJJ_L205</term>
+			<term name="ABS:TSTAND">1</term>
+			<term name="ABS:DSTAND" unit="mm">1</term>
+			<term name="ABS:IZERO">230.09</term>
+			<term name="ABS:XSECT" unit="mm">1</term>
+			<SASprocessnote/>
+		</SASprocess>
+		<SASnote />
+	</SASentry>
+</SASroot>
Index: sansguiframe/test/utest_manipulations.py
===================================================================
--- sansguiframe/test/utest_manipulations.py	(revision 09b73a3821013d4d64c4e69555954fb456c939db)
+++ sansguiframe/test/utest_manipulations.py	(revision 09b73a3821013d4d64c4e69555954fb456c939db)
@@ -0,0 +1,262 @@
+"""
+    Unit tests for data manipulations
+"""
+#TODO: what happens if you add a Data1D to a Data2D?
+
+import unittest
+import numpy, math
+from DataLoader.loader import  Loader
+from sans.guiframe.dataFitting import Theory1D, Data1D, Data2D
+ 
+import os.path
+
+class data_info_tests(unittest.TestCase):
+    
+    def setUp(self):
+        self.data = Loader().load("cansas1d.xml")
+        
+    def test_clone1D(self):
+        """
+            Test basic cloning
+        """
+        clone = self.data.clone_without_data()
+        
+        for i in range(len(self.data.detector)):
+            self.assertEqual(self.data.detector[i].distance, clone.detector[i].distance)
+            
+class theory1d_tests(unittest.TestCase):
+    
+    def setUp(self):
+        self.data = Loader().load("cansas1d.xml")
+        
+    def test_clone_theory1D(self):
+        """
+            Test basic cloning
+        """
+        theory = Theory1D(x=[], y=[], dy=None)
+        theory.clone_without_data(clone=self.data)
+        theory.copy_from_datainfo(data1d=self.data)
+        for i in range(len(self.data.detector)):
+            self.assertEqual(self.data.detector[i].distance, theory.detector[i].distance)
+            
+        for i in range(len(self.data.x)):
+            self.assertEqual(self.data.x[i], theory.x[i])
+            self.assertEqual(self.data.y[i], theory.y[i])
+            self.assertEqual(self.data.dy[i], theory.dy[i])
+
+class manip_tests(unittest.TestCase):
+    
+    def setUp(self):
+        # Create two data sets to play with
+        x_0 = numpy.ones(5)
+        for i in range(5):
+            x_0[i] = x_0[i]*(i+1.0)
+            
+        y_0 = 2.0*numpy.ones(5)
+        dy_0 = 0.5*numpy.ones(5)
+        self.data = Data1D(x_0, y_0, dy=dy_0)
+        
+        x = self.data.x
+        y = numpy.ones(5)
+        dy = numpy.ones(5)
+        self.data2 = Data1D(x, y, dy=dy)
+        
+        
+    def test_load(self):
+        """
+            Test whether the test file was loaded properly
+        """
+        # There should be 5 entries in the file
+        self.assertEqual(len(self.data.x), 5)
+        
+        for i in range(5):
+            # The x values should be from 1 to 5
+            self.assertEqual(self.data.x[i], float(i+1))
+        
+            # All y-error values should be 0.5
+            self.assertEqual(self.data.dy[i], 0.5)    
+            
+            # All y values should be 2.0
+            self.assertEqual(self.data.y[i], 2.0)    
+        
+    def test_add(self):
+        result = self.data2+self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 3.0)
+            self.assertEqual(result.dy[i], math.sqrt(0.5**2+1.0))
+        
+    def test_sub(self):
+        result = self.data2-self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], -1.0)
+            self.assertEqual(result.dy[i], math.sqrt(0.5**2+1.0))
+        
+    def test_mul(self):
+        result = self.data2*self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 2.0)
+            self.assertEqual(result.dy[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2))
+        
+    def test_div(self):
+        result = self.data2/self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 0.5)
+            self.assertEqual(result.dy[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2))
+        
+    def test_radd(self):
+        result = self.data+3.0
+        for i in range(5):
+            self.assertEqual(result.y[i], 5.0)
+            self.assertEqual(result.dy[i], 0.5)
+            
+        result = 3.0+self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 5.0)
+            self.assertEqual(result.dy[i], 0.5)
+            
+    def test_rsub(self):
+        result = self.data-3.0
+        for i in range(5):
+            self.assertEqual(result.y[i], -1.0)
+            self.assertEqual(result.dy[i], 0.5)
+            
+        result = 3.0-self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 1.0)
+            self.assertEqual(result.dy[i], 0.5)
+            
+    def test_rmul(self):
+        result = self.data*3.0
+        for i in range(5):
+            self.assertEqual(result.y[i], 6.0)
+            self.assertEqual(result.dy[i], 1.5)
+            
+        result = 3.0*self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 6.0)
+            self.assertEqual(result.dy[i], 1.5)
+            
+    def test_rdiv(self):
+        result = self.data/4.0
+        for i in range(5):
+            self.assertEqual(result.y[i], 0.5)
+            self.assertEqual(result.dy[i], 0.125)
+            
+        result = 6.0/self.data
+        for i in range(5):
+            self.assertEqual(result.y[i], 3.0)
+            self.assertEqual(result.dy[i], 6.0*0.5/4.0)
+            
+class manip_2D(unittest.TestCase):
+    
+    def setUp(self):
+        # Create two data sets to play with
+        x_0 = 2.0*numpy.ones([5,4])
+        dx_0 = 0.5*numpy.ones([5,4])
+        self.data = Data2D(x_0, dx_0)
+        
+        y = numpy.ones([5,4])
+        dy = numpy.ones([5,4])
+        self.data2 = Data2D(y, dy)
+        
+        
+    def test_load(self):
+        """
+            Test whether the test file was loaded properly
+        """
+        # There should be 5 entries in the file
+        self.assertEqual(numpy.size(self.data.data, 0), 5)
+        self.assertEqual(numpy.size(self.data.data, 1), 4)
+        
+        for i in range(5):
+            for j in range(4):
+                # All y-error values should be 0.5
+                self.assertEqual(self.data.err_data[i][j], 0.5)    
+                
+                # All y values should be 2.0
+                self.assertEqual(self.data.data[i][j], 2.0)    
+        
+    def test_add(self):
+        result = self.data2+self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 3.0)
+                self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0))
+        
+    def test_sub(self):
+        result = self.data2-self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], -1.0)
+                self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0))
+        
+    def test_mul(self):
+        result = self.data2*self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 2.0)
+                self.assertEqual(result.err_data[i][j], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2))
+        
+    def test_div(self):
+        result = self.data2/self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 0.5)
+                self.assertEqual(result.err_data[i][j], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2))
+        
+    def test_radd(self):
+        result = self.data+3.0
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 5.0)
+                self.assertEqual(result.err_data[i][j], 0.5)
+            
+        result = 3.0+self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 5.0)
+                self.assertEqual(result.err_data[i][j], 0.5)
+            
+    def test_rsub(self):
+        result = self.data-3.0
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], -1.0)
+                self.assertEqual(result.err_data[i][j], 0.5)
+            
+        result = 3.0-self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 1.0)
+                self.assertEqual(result.err_data[i][j], 0.5)
+            
+    def test_rmul(self):
+        result = self.data*3.0
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 6.0)
+                self.assertEqual(result.err_data[i][j], 1.5)
+            
+        result = 3.0*self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 6.0)
+                self.assertEqual(result.err_data[i][j], 1.5)
+            
+    def test_rdiv(self):
+        result = self.data/4.0
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 0.5)
+                self.assertEqual(result.err_data[i][j], 0.125)
+            
+        result = 6.0/self.data
+        for i in range(5):
+            for j in range(4):
+                self.assertEqual(result.data[i][j], 3.0)
+                self.assertEqual(result.err_data[i][j], 6.0*0.5/4.0)
+            
+
+if __name__ == '__main__':
+    unittest.main()
+   
