diff _test_dataset.py @ 342:2259f6fa4959

fix test for __getitem__
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Tue, 17 Jun 2008 14:32:03 -0400
parents 9c08e3af975e
children 394b4e849c1b 9de4274ad5ba
line wrap: on
line diff
--- a/_test_dataset.py	Tue Jun 17 13:33:17 2008 -0400
+++ b/_test_dataset.py	Tue Jun 17 14:32:03 2008 -0400
@@ -274,14 +274,17 @@
 def test_getitem(array,ds):
     def test_ds(orig,ds,index):
         i=0
-        assert len(ds)==len(index)
-        for x,z,y in ds('x','z','y'):
-            assert (orig[index[i]]['x']==array[index[i]][:3]).all()
-            assert (orig[index[i]]['x']==x).all()
-            assert orig[index[i]]['y']==array[index[i]][3]
-            assert (orig[index[i]]['y']==y).all() # why does it crash sometimes?
-            assert (orig[index[i]]['z']==array[index[i]][0:3:2]).all()
-            assert (orig[index[i]]['z']==z).all()
+        assert isinstance(ds,LookupList)
+        assert len(ds)==3
+        assert len(ds[0])==len(index)
+#        for x,z,y in ds('x','z','y'):
+        for idx in index:
+            assert (orig[idx]['x']==array[idx][:3]).all()
+            assert (orig[idx]['x']==ds['x'][i]).all()
+            assert orig[idx]['y']==array[idx][3]
+            assert (orig[idx]['y']==ds['y'][i]).all() # why does it crash sometimes?
+            assert (orig[idx]['z']==array[idx][0:3:2]).all()
+            assert (orig[idx]['z']==ds['z'][i]).all()
             i+=1
         del i
         ds[0]
@@ -294,19 +297,22 @@
         for x in ds:
             pass
 
-#ds[:n] returns a dataset with the n first examples.
+#ds[:n] returns a LookupList with the n first examples.
     ds2=ds[:3]
-    assert isinstance(ds2,LookupList)
     test_ds(ds,ds2,index=[0,1,2])
     del ds2
 
-#ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s.
-    ds2=ds.subset[1:7:2]
-    assert isinstance(ds2,DataSet)
+#ds[i:j] returns a LookupList with examples i,i+1,...,j-1.
+    ds2=ds[1:3]
+    test_ds(ds,ds2,index=[1,2])
+    del ds2
+
+#ds[i1:i2:s] returns a LookupList with the examples i1,i1+s,...i2-s.
+    ds2=ds[1:7:2]
     test_ds(ds,ds2,[1,3,5])
     del ds2
 
-#ds[i]
+#ds[i] returns the (i+1)-th example of the dataset.
     ds2=ds[5]
     assert isinstance(ds2,Example)
     assert have_raised("var['ds']["+str(len(ds))+"]",ds=ds)  # index not defined
@@ -314,8 +320,8 @@
     del ds2
 
 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in.
-    ds2=ds.subset[[4,7,2,8]]
-    assert isinstance(ds2,DataSet)
+    ds2=ds[[4,7,2,8]]
+#    assert isinstance(ds2,DataSet)
     test_ds(ds,ds2,[4,7,2,8])
     del ds2