Mercurial > pylearn
comparison _test_dataset.py @ 220:1f527fe65e22
test on simple slicing works
author | Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca> |
---|---|
date | Fri, 23 May 2008 13:44:25 -0400 |
parents | 5b3afda2f1ad |
children | 58e17421c69c |
comparison
equal
deleted
inserted
replaced
219:5b3afda2f1ad | 220:1f527fe65e22 |
---|---|
1 from dataset import * | 1 from dataset import * |
2 from math import * | 2 from math import * |
3 import unittest | 3 import unittest |
4 import sys | |
5 import numpy as N | |
4 | 6 |
5 def _sum_all(a): | 7 def _sum_all(a): |
6 s=a | 8 s=a |
7 while isinstance(s,numpy.ndarray): | 9 while isinstance(s,numpy.ndarray): |
8 s=sum(s) | 10 s=sum(s) |
90 b=a.apply_function(lambda x,y: x+y,x+1, ['x','y'], ['x+y','x+1'], False,False,False) | 92 b=a.apply_function(lambda x,y: x+y,x+1, ['x','y'], ['x+y','x+1'], False,False,False) |
91 print b.fieldNames() | 93 print b.fieldNames() |
92 print b('x+y') | 94 print b('x+y') |
93 | 95 |
94 | 96 |
97 | |
98 | |
95 # to be used with a any new dataset | 99 # to be used with a any new dataset |
96 class T_dataset_tester(object): | 100 class T_dataset_tester(object): |
97 """ | 101 """ |
98 This class' goal is to test any new dataset that is created | 102 This class' goal is to test any new dataset that is created |
103 Tests are (will be!) designed to check the normal behaviours | |
104 of a dataset, as defined in dataset.py | |
99 """ | 105 """ |
100 | 106 |
101 | 107 |
102 def __init__(self,ds,runall=True) : | 108 def __init__(self,ds,runall=True) : |
103 """if interested in only a subset of test, init with runall=False""" | 109 """if interested in only a subset of test, init with runall=False""" |
119 | 125 |
120 def test2_slicing(self,ds) : | 126 def test2_slicing(self,ds) : |
121 """test if slicing works properly""" | 127 """test if slicing works properly""" |
122 print 'testing slicing...', | 128 print 'testing slicing...', |
123 sys.stdout.flush() | 129 sys.stdout.flush() |
130 | |
124 middle = len(ds) / 2 | 131 middle = len(ds) / 2 |
125 tenpercent = int(len(ds) * .1) | 132 tenpercent = int(len(ds) * .1) |
126 set1 = ds[:middle+tenpercent] | 133 set1 = ds[:middle+tenpercent] |
127 set2 = ds[middle-tenpercent:] | 134 set2 = ds[middle-tenpercent:] |
135 for k in range(tenpercent + tenpercent -1): | |
136 for k2 in ds.fieldNames() : | |
137 if type(set1[middle-tenpercent+k](k2)[0]) == N.ndarray : | |
138 for k3 in range(len(set1[middle-tenpercent+k](k2)[0])) : | |
139 assert set1[middle-tenpercent+k](k2)[0][k3] == set2[k](k2)[0][k3] | |
140 else : | |
141 assert set1[middle-tenpercent+k](k2)[0] == set2[k](k2)[0] | |
142 | |
143 print 'done' | |
128 | 144 |
129 | 145 |
130 ################################################################### | 146 ################################################################### |
131 # main | 147 # main |
132 if __name__ == '__main__': | 148 if __name__ == '__main__': |