@@ -170,5 +170,84 @@ is( join(",",sort @groups), 'dude2,mygroup' );
170
170
@groups = $group2 -> groups;
171
171
172
172
is( scalar (@groups ), 0 );
173
+ undef $hdfobj ;
174
+
175
+ {
176
+ # Script to test the attribute index functionality of the PDL::IO::HDF5 Class
177
+ # New File Check:
178
+ my $filename = " total.hdf5" ;
179
+ ok(my $hdfobj = PDL::IO::HDF5-> new($filename ));
180
+
181
+ # It is normally a no-no to call a internal method, but we
182
+ # are just testing here:
183
+ $hdfobj -> _buildAttrIndex;
184
+
185
+ my $baseline = {
186
+ ' /' => {
187
+ attr1 => ' dudeman23' ,
188
+ attr2 => ' What??' ,
189
+ },
190
+ ' /dude2' => {
191
+ attr1 => ' dudeman23' ,
192
+ attr2 => ' What??' ,
193
+ },
194
+ ' /mygroup' => {
195
+ attr1 => ' dudeman23' ,
196
+ attr2 => ' What??' ,
197
+ },
198
+ ' /mygroup/subgroup' => {
199
+ attr1 => ' dudeman23' ,
200
+ attr2 => ' What??' ,
201
+ },
202
+ };
203
+ is_deeply($hdfobj -> {attrIndex }, $baseline );
204
+
205
+ my @values = $hdfobj -> allAttrValues(' attr1' );
206
+ $baseline = [ ' dudeman23' , ' dudeman23' , ' dudeman23' , ' dudeman23' ];
207
+ is_deeply \@values , $baseline ;
208
+
209
+ @values = $hdfobj -> allAttrValues(' attr1' ,' attr2' );
210
+ $baseline = [
211
+ [ ' dudeman23' , ' What??' , ], [ ' dudeman23' , ' What??' , ],
212
+ [ ' dudeman23' , ' What??' , ], [ ' dudeman23' , ' What??' , ]
213
+ ];
214
+ is_deeply \@values , $baseline ;
215
+
216
+ my @names = $hdfobj -> allAttrNames;
217
+ is_deeply \@names , [ ' attr1' , ' attr2' , ];
218
+
219
+ # Test building the groupIndex
220
+ $hdfobj -> _buildGroupIndex(' attr1' ,' attr2' );
221
+ $hdfobj -> _buildGroupIndex(' attr2' );
222
+ $hdfobj -> _buildGroupIndex(' attr1' ,' attr3' );
223
+
224
+ $baseline = {
225
+ ' attr1attr2' => {
226
+ ' dudeman23What??' => [ ' /' , ' /dude2' , ' /mygroup' , ' /mygroup/subgroup' ]
227
+ },
228
+ ' attr1attr3' => {
229
+ ' dudeman23_undef_' => [ ' /' , ' /dude2' , ' /mygroup' , ' /mygroup/subgroup' ]
230
+ },
231
+ ' attr2' => {
232
+ ' What??' => [ ' /' , ' /dude2' , ' /mygroup' , ' /mygroup/subgroup' ]
233
+ }
234
+ };
235
+
236
+ my $result = $hdfobj -> {groupIndex };
237
+ is_deeply $result , $baseline or diag explain $result ;
238
+
239
+ my @groups = $hdfobj -> getGroupsByAttr( ' attr1' => ' dudeman23' ,
240
+ ' attr2' => ' What??' );
241
+ $baseline = [
242
+ ' /' ,
243
+ ' /dude2' ,
244
+ ' /mygroup' ,
245
+ ' /mygroup/subgroup' ,
246
+ ];
247
+ is_deeply \@groups , $baseline ;
248
+
249
+ # clean up file
250
+ }
251
+ unlink $filename if ( -e $filename );
173
252
174
253
done_testing;
0 commit comments