comparison _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
comparison
equal deleted inserted replaced
218:df3fae88ab46 219:5b3afda2f1ad
90 b=a.apply_function(lambda x,y: x+y,x+1, ['x','y'], ['x+y','x+1'], False,False,False) 90 b=a.apply_function(lambda x,y: x+y,x+1, ['x','y'], ['x+y','x+1'], False,False,False)
91 print b.fieldNames() 91 print b.fieldNames()
92 print b('x+y') 92 print b('x+y')
93 93
94 94
95 # to be used with a any new dataset
96 class T_dataset_tester(object):
97 """
98 This class' goal is to test any new dataset that is created
99 """
100
101
102 def __init__(self,ds,runall=True) :
103 """if interested in only a subset of test, init with runall=False"""
104 self.ds = ds
105
106 if runall :
107 self.test1_basicstats(ds)
108 self.test2_slicing(ds)
109
110 def test1_basicstats(self,ds) :
111 """print basics stats on a dataset, like length"""
112
113 print 'len(ds) = ',len(ds)
114 print 'num fields = ', len(ds.fieldNames())
115 print 'types of field: ',
116 for k in ds.fieldNames() :
117 print type(ds[0](k)[0]),
118 print ''
119
120 def test2_slicing(self,ds) :
121 """test if slicing works properly"""
122 print 'testing slicing...',
123 sys.stdout.flush()
124 middle = len(ds) / 2
125 tenpercent = int(len(ds) * .1)
126 set1 = ds[:middle+tenpercent]
127 set2 = ds[middle-tenpercent:]
128
129
130 ###################################################################
131 # main
95 if __name__ == '__main__': 132 if __name__ == '__main__':
96 unittest.main() 133 unittest.main()
97 134