Changeset 442f42f in sasview for DataLoader/test
- Timestamp:
- Aug 29, 2008 5:20:02 PM (16 years ago)
- 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:
- b88c6e0
- Parents:
- 579ba85
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/test/utest_manipulations.py
r9198b83 r442f42f 2 2 Unit tests for data manipulations 3 3 """ 4 #TODO: what happens if you add a Data1D to a Data2D? 4 5 5 6 import unittest 6 7 import numpy, math 7 8 from DataLoader.loader import Loader 8 from DataLoader.data_info import Data1D 9 from DataLoader.data_info import Data1D, Data2D 9 10 10 11 import os.path … … 128 129 self.assertEqual(result.dy[i], 6.0*0.5/4.0) 129 130 131 class manip_2D(unittest.TestCase): 132 133 def setUp(self): 134 # Create two data sets to play with 135 x_0 = 2.0*numpy.ones([5,4]) 136 dx_0 = 0.5*numpy.ones([5,4]) 137 self.data = Data2D(x_0, dx_0) 138 139 y = numpy.ones([5,4]) 140 dy = numpy.ones([5,4]) 141 self.data2 = Data2D(y, dy) 142 143 144 def test_load(self): 145 """ 146 Test whether the test file was loaded properly 147 """ 148 # There should be 5 entries in the file 149 self.assertEqual(numpy.size(self.data.data, 0), 5) 150 self.assertEqual(numpy.size(self.data.data, 1), 4) 151 152 for i in range(5): 153 for j in range(4): 154 # All y-error values should be 0.5 155 self.assertEqual(self.data.err_data[i][j], 0.5) 156 157 # All y values should be 2.0 158 self.assertEqual(self.data.data[i][j], 2.0) 159 160 def test_add(self): 161 result = self.data2+self.data 162 for i in range(5): 163 for j in range(4): 164 self.assertEqual(result.data[i][j], 3.0) 165 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 166 167 def test_sub(self): 168 result = self.data2-self.data 169 for i in range(5): 170 for j in range(4): 171 self.assertEqual(result.data[i][j], -1.0) 172 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 173 174 def test_mul(self): 175 result = self.data2*self.data 176 for i in range(5): 177 for j in range(4): 178 self.assertEqual(result.data[i][j], 2.0) 179 self.assertEqual(result.err_data[i][j], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 180 181 def test_div(self): 182 result = self.data2/self.data 183 for i in range(5): 184 for j in range(4): 185 self.assertEqual(result.data[i][j], 0.5) 186 self.assertEqual(result.err_data[i][j], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 187 188 def test_radd(self): 189 result = self.data+3.0 190 for i in range(5): 191 for j in range(4): 192 self.assertEqual(result.data[i][j], 5.0) 193 self.assertEqual(result.err_data[i][j], 0.5) 194 195 result = 3.0+self.data 196 for i in range(5): 197 for j in range(4): 198 self.assertEqual(result.data[i][j], 5.0) 199 self.assertEqual(result.err_data[i][j], 0.5) 200 201 def test_rsub(self): 202 result = self.data-3.0 203 for i in range(5): 204 for j in range(4): 205 self.assertEqual(result.data[i][j], -1.0) 206 self.assertEqual(result.err_data[i][j], 0.5) 207 208 result = 3.0-self.data 209 for i in range(5): 210 for j in range(4): 211 self.assertEqual(result.data[i][j], 1.0) 212 self.assertEqual(result.err_data[i][j], 0.5) 213 214 def test_rmul(self): 215 result = self.data*3.0 216 for i in range(5): 217 for j in range(4): 218 self.assertEqual(result.data[i][j], 6.0) 219 self.assertEqual(result.err_data[i][j], 1.5) 220 221 result = 3.0*self.data 222 for i in range(5): 223 for j in range(4): 224 self.assertEqual(result.data[i][j], 6.0) 225 self.assertEqual(result.err_data[i][j], 1.5) 226 227 def test_rdiv(self): 228 result = self.data/4.0 229 for i in range(5): 230 for j in range(4): 231 self.assertEqual(result.data[i][j], 0.5) 232 self.assertEqual(result.err_data[i][j], 0.125) 233 234 result = 6.0/self.data 235 for i in range(5): 236 for j in range(4): 237 self.assertEqual(result.data[i][j], 3.0) 238 self.assertEqual(result.err_data[i][j], 6.0*0.5/4.0) 239 130 240 131 241 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.