diff test_dataset.py @ 86:fdf72ea4f2bc

added function test_ds in test_ArrayDataSet who test a sub dataset
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 05 May 2008 14:37:34 -0400
parents aa9e786ee849
children 3fd6879e0f76
line wrap: on
line diff
--- a/test_dataset.py	Mon May 05 13:37:39 2008 -0400
+++ b/test_dataset.py	Mon May 05 14:37:34 2008 -0400
@@ -40,7 +40,8 @@
 
     print "test_ArrayDataSet"
     a = numpy.random.rand(10,4)
-    ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})
+    ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested
+
     assert len(ds)==10
     #assert ds==a? should this work?
     for i in range(len(ds)):
@@ -86,42 +87,41 @@
 
     assert ds == ds.fields().examples()
 
+    def test_ds(orig,ds,index):
+        i=0
+        assert len(ds)==len(index)
+        for x,z,y in ds('x','z','y'):
+            print x,y,z
+            assert orig[index[i]]['x'].all()==a[index[i]][:3].all()
+            assert orig[index[i]]['x'].all()==x.all()
+            assert orig[index[i]]['y']==a[index[i]][3]
+            assert orig[index[i]]['y']==y
+            assert orig[index[i]]['z'].all()==a[index[i]][0:3:2].all()
+            assert orig[index[i]]['z'].all()==z.all()
+            i+=1
+        del i
 
     #ds[:n] returns a dataset with the n first examples.
-    assert len(ds[:3])==3
-    i=0
-    for x,z,y in ds[:3]('x','z','y'):
-        assert ds[i]['x'].all()==a[i][:3].all()
-        assert ds[i]['x'].all()==x.all()
-        assert ds[i]['y']==a[i][3]
-        assert ds[i]['y']==y
-        assert ds[i]['z'].all()==a[i][0:3:2].all()
-        assert ds[i]['z'].all()==z.all()
-        i+=1
-    i=0
-    for x,z in ds[:3]('x','z'):
-        assert ds[i]['z'].all()==a[i][0:3:2].all()
-        i+=1
+    ds2=ds[:3]
+    test_ds(ds,ds2,index=[0,1,2])
 
     #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s.
-    ds[1:7:2][1]
-    assert len(ds[1:7:2])==3 # should be number example 1,3 and 5
-    i=0
-    index=[1,3,5]
-    for z,y,x in ds[1:7:2]('z','y','x'):
-        assert ds[index[i]]['x'].all()==a[index[i]][:3].all()
-        assert ds[index[i]]['x'].all()==x.all()
-        assert ds[index[i]]['y']==a[index[i]][3]
-        assert ds[index[i]]['y']==y
-        assert ds[index[i]]['z'].all()==a[index[i]][0:3:2].all()
-        assert ds[index[i]]['z'].all()==z.all()
-        i+=1
-
+    ds2=ds[1:7:2]
+    ds2[1]
+    test_ds(ds,ds2,[1,3,5])
     #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in.
-    i=0
-    for x in ds[[1,2]]:
-        assert numpy.append(x['x'],x['y']).all()==a[i].all()
-        i+=1
+#   ds2=ds[[4,7,2,8]]# fail
+#   assert len(ds2)==4
+#   i=0
+#   index=[4,7,2,8]
+#    for x in ds2:
+#        assert ds[index[i]]['x'].all()==a[index[i]][:3].all()
+#        assert ds[index[i]]['x'].all()==x.all()
+#        assert ds[index[i]]['y']==a[index[i]][3]
+#        assert ds[index[i]]['y']==y
+#        assert ds[index[i]]['z'].all()==a[index[i]][0:3:2].all()
+#        assert ds[index[i]]['z'].all()==z.all()
+#        i+=1
     #ds[i1,i2,...]# should we accept????
     #ds[fieldname]# an iterable over the values of the field fieldname across
       #the ds (the iterable is obtained by default by calling valuesVStack