[65f11e]: t / ztotal_index.t  Maximize  Restore  History

Download this file

234 lines (184 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use PDL;
use PDL::Char;
use PDL::IO::HDF5;
use PDL::Types;
# Script to test the attribute index functionality of the PDL::IO::HDF5 Class
use Data::Dumper;
print "1..7\n";
my $testNo = 1;
# New File Check:
my $filename = "newFile.hd5";
my $hdfobj;
ok($testNo++,$hdfobj = new PDL::IO::HDF5("newFile.hd5"));
# It is normally a no-no to call a internal method, but we
# are just testing here:
$hdfobj->_buildAttrIndex;
my $result = recursiveDump($hdfobj->{attrIndex});
my $baseline =
q!{
/ => {
attr1 => dudeman23,
attr2 => What??,
}
/dude2 => {
attr1 => dudeman23,
attr2 => What??,
}
/mygroup => {
attr1 => dudeman23,
attr2 => What??,
}
/mygroup/subgroup => {
attr1 => dudeman23,
attr2 => What??,
}
}
!;
# print $result;
ok($testNo++,$baseline eq $result );
# die;
my @values = $hdfobj->allAttrValues('attr1');
$baseline =
q![
dudeman23,
dudeman23,
dudeman23,
dudeman23,
]
!;
#print recursiveDump(\@values);
$result = recursiveDump(\@values);
ok($testNo++,$baseline eq $result );
@values = $hdfobj->allAttrValues('attr1','attr2');
$baseline =
q![
[
dudeman23,
What??,
]
[
dudeman23,
What??,
]
[
dudeman23,
What??,
]
[
dudeman23,
What??,
]
]
!;
#print recursiveDump(\@values);
$result = recursiveDump(\@values);
ok($testNo++,$baseline eq $result );
my @names = $hdfobj->allAttrNames;
$baseline =
q![
attr1,
attr2,
]
!;
#print recursiveDump(\@names);
$result = recursiveDump(\@names);
ok($testNo++,$baseline eq $result );
# Test building the groupIndex
$hdfobj->_buildGroupIndex('attr1','attr2');
$hdfobj->_buildGroupIndex('attr2');
$hdfobj->_buildGroupIndex('attr1','attr3');
$baseline =
"{
attr1$;attr2 => {
dudeman23$;What?? => [
/,
/dude2,
/mygroup,
/mygroup/subgroup,
]
}
attr1$;attr3 => {
dudeman23$; => [
/,
/dude2,
/mygroup,
/mygroup/subgroup,
]
}
attr2 => {
What?? => [
/,
/dude2,
/mygroup,
/mygroup/subgroup,
]
}
}
";
#print $baseline;
#print recursiveDump($hdfobj->{groupIndex});
$result = recursiveDump($hdfobj->{groupIndex});
ok($testNo++,$baseline eq $result );
my @groups = $hdfobj->getGroupsByAttr( 'attr1' => 'dudeman23',
'attr2' => 'What??');
$baseline =
q![
/,
/dude2,
/mygroup,
/mygroup/subgroup,
]
!;
#print recursiveDump(\@groups);
$result = recursiveDump(\@groups);
ok($testNo++,$baseline eq $result );
print "completed\n";
# Testing utility functions:
sub ok {
my $no = shift ;
my $result = shift ;
print "not " unless $result ;
print "ok $no\n" ;
}
# Dump of recursive array/hash.
# We Could use Data:Dumper for this but it doesn't
# order the keys, which causes problems
# in regression testing on different platforsm
sub recursiveDump{
my ($ref, $level) = @_;
$level = 1 unless( defined($level));
my $returnString; # String to return
my $levelspace = ' '; # Space used to indent
my $indent = $levelspace x $level;
my $unindent = $levelspace x ($level-1) ;
my $displayedData = $ref;
my $arrayFlag = 0;
my @sortedKeys;
if( ref $ref eq 'ARRAY'){ # arrays are converted to hashes with indexes numbers
# as keys for display
$displayedData = {};
@$displayedData{0..$#$ref} = @$ref;
$returnString = $unindent."[\n";
$arrayFlag = 1;
@sortedKeys = (0..$#$ref);
}
else{
$returnString = $unindent."{\n";
@sortedKeys = sort keys %$displayedData;
}
my $value;
foreach my $key(@sortedKeys){
$value = $displayedData->{$key};
if( ref( $value) ){
$returnString .= $indent.$key." => " unless( $arrayFlag); # dumping hash Ref
$returnString .= recursiveDump($value,$level+1);
}
else{
$returnString .= $indent.$value.",\n" if( $arrayFlag); # dumping array Ref
$returnString .= $indent.$key.' => '.$value.",\n" unless( $arrayFlag); # dumping hash Ref
}
}
$returnString .= $unindent."}\n" unless($arrayFlag); # Dumping hash ref
$returnString .= $unindent."]\n" if($arrayFlag); # Dumping aray ref
$returnString;
}