diff _test_dataset.py @ 219:5b3afda2f1ad

added a class to test any new dataset
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Fri, 23 May 2008 13:16:42 -0400
parents 46c5c90019c2
children 1f527fe65e22
line wrap: on
line diff
--- a/_test_dataset.py	Fri May 23 12:22:54 2008 -0400
+++ b/_test_dataset.py	Fri May 23 13:16:42 2008 -0400
@@ -92,6 +92,43 @@
         print b('x+y')
         
 
+# to be used with a any new dataset
+class T_dataset_tester(object):
+    """
+    This class' goal is to test any new dataset that is created
+    """
+
+
+    def __init__(self,ds,runall=True) :
+        """if interested in only a subset of test, init with runall=False"""
+        self.ds = ds
+        
+        if runall :
+            self.test1_basicstats(ds)
+            self.test2_slicing(ds)
+
+    def test1_basicstats(self,ds) :
+        """print basics stats on a dataset, like length"""
+
+        print 'len(ds) = ',len(ds)
+        print 'num fields = ', len(ds.fieldNames())
+        print 'types of field: ',
+        for k in ds.fieldNames() :
+            print type(ds[0](k)[0]),
+        print ''
+
+    def test2_slicing(self,ds) :
+        """test if slicing works properly"""
+        print 'testing slicing...',
+        sys.stdout.flush()
+        middle = len(ds) / 2
+        tenpercent = int(len(ds) * .1)
+        set1 = ds[:middle+tenpercent]
+        set2 = ds[middle-tenpercent:]
+
+
+###################################################################
+# main
 if __name__ == '__main__':
     unittest.main()