File: total.t

package info (click to toggle)
libpdl-io-hdf5-perl 1%3A0.75-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 336 kB
  • sloc: perl: 1,544; makefile: 9
file content (174 lines) | stat: -rwxr-xr-x 4,350 bytes parent folder | download
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
# Script to test the PDL::IO::HDF5 objects together in the
#   way they would normally be used
#
#  i.e. the way they would normally be used as described
#  in the PDL::IO::HDF5 synopsis

use strict;
use warnings;
use PDL;
use PDL::Char;
use PDL::IO::HDF5;
use Test::More;

# New File Check:
my $filename = "total.hdf5";
# get rid of filename if it already exists
unlink $filename if( -e $filename);

ok(my $hdfobj = new PDL::IO::HDF5($filename));

# Set attribute for file (root group)
ok($hdfobj->attrSet( 'attr1' => 'dudeman', 'attr2' => 'What??'));

# Try Setting attr for an existing attr
ok($hdfobj->attrSet( 'attr1' => 'dudeman23'));


# Add a attribute and then delete it
ok($hdfobj->attrSet( 'dummyAttr' => 'dummyman', 
				'dummyAttr2' => 'dummyman'));
				
ok($hdfobj->attrDel( 'dummyAttr', 'dummyAttr2' ));

# Get list of attributes
my @attrs = $hdfobj->attrs;
is(join(",",sort @attrs), 'attr1,attr2' );

# Get a list of attribute values
my @attrValues = $hdfobj->attrGet(sort @attrs);

is(join(",",@attrValues), 'dudeman23,What??' );

##############################################

# Create a dataset in the root group
my $dataset = $hdfobj->dataset('rootdataset');

my $pdl = sequence(5,4);

ok($dataset->set($pdl, unlimited => 1) );

# Create String dataset using PDL::Char
my $dataset2 = $hdfobj->dataset('charData');

my $pdlChar = new PDL::Char( [ ["abccc", "def", "ghi"],["jkl", "mno", 'pqr'] ] );
 
ok($dataset2->set($pdlChar, unlimited => 1));

my $pdl2 = $dataset->get;
ok((($pdl - $pdl2)->sum) < .001 );

my @dims = $dataset->dims;

is( join(", ",@dims), '5, 4' );

# Get a list of datasets (should be two)
my @datasets = $hdfobj->datasets;

is( scalar(@datasets), 2 );


#############################################

my $group = $hdfobj->group("mygroup");

my $subgroup = $group->group("subgroup");

### Try a non-deault data-set type (float) ####
# Create a dataset in the subgroup
$dataset = $subgroup->dataset('my dataset');

$pdl = sequence(5,4)->float; # Try a non-default data type


ok( $dataset->set($pdl, unlimited => 1) );

$pdl2 = $dataset->get;

ok( (($pdl - $pdl2)->sum) < .001 );

# Check for the PDL returned being a float
is( $pdl->type, 'float' );

# Get a hyperslab
$pdl = $dataset->get(pdl([0,0]), pdl([4,0]));  # Get the first vector of the PDL

# Check to see if the dims are as expected.
my @pdlDims = $pdl->dims;
is_deeply( \@pdlDims, [5, 1] );


### Try a non-default data-set type (int/long) ####
# Create a dataset in the subgroup
$dataset = $subgroup->dataset('my dataset2');

$pdl = sequence(5,4)->long; # Try a non-default data type


ok( $dataset->set($pdl, unlimited => 1) );

$pdl2 = $dataset->get;

ok( (($pdl - $pdl2)->sum) < .001 );

# Check for the PDL returned being a int/long
is( $pdl->type, 'long' );

################ Set Attributes at the Dataset Level ###############
# Set attribute for group
ok( $dataset->attrSet( 'attr1' => 'DSdudeman', 'attr2' => 'DSWhat??'));

# Try Setting attr for an existing attr
ok($dataset->attrSet( 'attr1' => 'DSdudeman23'));


# Add a attribute and then delete it
ok( $dataset->attrSet( 'dummyAttr' => 'dummyman', 
				'dummyAttr2' => 'dummyman'));
ok( $dataset->attrDel( 'dummyAttr', 'dummyAttr2' ));

# Get list of attributes
@attrs = $dataset->attrs;
is( join(",",sort @attrs), 'attr1,attr2' );

# Get a list of attribute values
@attrValues = $dataset->attrGet(sort @attrs);

is( join(",",@attrValues), 'DSdudeman23,DSWhat??' );

################ Set Attributes at the Group Level ###############
# Set attribute for group
ok( $group->attrSet( 'attr1' => 'dudeman', 'attr2' => 'What??'));

# Try Setting attr for an existing attr
ok($group->attrSet( 'attr1' => 'dudeman23'));

# Add a attribute and then delete it
ok( $group->attrSet( 'dummyAttr' => 'dummyman', 
				'dummyAttr2' => 'dummyman'));
ok( $group->attrDel( 'dummyAttr', 'dummyAttr2' ));

# Get list of attributes
@attrs = $group->attrs;
is( join(",",sort @attrs), 'attr1,attr2' );

# Get a list of datasets (should be none)
@datasets = $group->datasets;

is( scalar(@datasets), 0 );

# Create another group
my $group2 = $hdfobj->group("dude2");

# Get a list of groups in the root group
my @groups = $hdfobj->groups;

is( join(",",sort @groups), 'dude2,mygroup' );

# Get a list of groups in group2 (should be none)
@groups = $group2->groups;

is( scalar(@groups), 0 );

done_testing;