changeset 148:a5329e719229

added test for CachedDataSet
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 12 May 2008 15:47:32 -0400
parents 933db7ece663
children feec9039b941
files test_dataset.py
diffstat 1 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test_dataset.py	Mon May 12 15:35:18 2008 -0400
+++ b/test_dataset.py	Mon May 12 15:47:32 2008 -0400
@@ -383,12 +383,41 @@
     assert example+example2==example3
     assert have_raised("var['x']+var['x']",x=example)
 
+def test_CacheDataSet():
+    print "test_CacheDataSet"
+    a2 = numpy.random.rand(10,4)
+    ds1 = ArrayDataSet(a2,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested
+    ds2 = CachedDataSet(ds1)
+    ds3 = CachedDataSet(ds1,cache_all_upon_construction=True)
+    assert len(ds2)==10
+
+    test_iterate_over_examples(a2, ds2)
+    test_getitem(a2, ds2)
+
+#     - for val1,val2,val3 in dataset(field1, field2,field3):
+    test_ds_iterator(a2,ds2('x','y'),ds2('y','z'),ds(2'x','y','z'))
+
+
+    assert len(ds2.fields())==3
+    for field in ds2.fields():
+        for field_value in field: # iterate over the values associated to that field for all the ds examples
+            pass
+    for field in ds2('x','z').fields():
+        pass
+    for field in ds2.fields('x','y'):
+        pass
+    for field_examples in ds2.fields():
+        for example_value in field_examples:
+            pass
+
+    assert ds2 == ds2.fields().examples()
+#    for ((x,y),a_v) in (ds('x','y'),a): #???don't work # haven't found a variant that work.# will not work
+#        assert numpy.append(x,y)==z
+
+
 def test_ApplyFunctionDataSet():
     print "test_ApplyFunctionDataSet"
     raise NotImplementedError()
-def test_CacheDataSet():
-    print "test_CacheDataSet"
-    raise NotImplementedError()
 def test_FieldsSubsetDataSet():
     print "test_FieldsSubsetDataSet"
     raise NotImplementedError()
@@ -411,4 +440,5 @@
 test1()
 test_LookupList()
 test_ArrayDataSet()
+test_CacheDataSet()
 #test pmat.py