File: group.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 (98 lines) | stat: -rw-r--r-- 2,523 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
# Script to test the group/dataset object separately.
#  i.e. not the way they would normally be used as described
#  in the PDL::IO::HDF5 synopsis

use strict;
use warnings;
use PDL;
use PDL::IO::HDF5;
use PDL::IO::HDF5::Group;
use PDL::IO::HDF5::Dataset;
use Test::More;

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

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

my $group = new PDL::IO::HDF5::Group( name => '/dude', parent => $hdfobj,
					 fileObj => $hdfobj);

# 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
my @attrs = $group->attrs;
is( join(",",sort @attrs), 'attr1,attr2' );

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

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

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

is( scalar(@datasets), 0 );

# Create another group
my $group2 = new PDL::IO::HDF5::Group( 'name'=> '/dude2', parent => $hdfobj,
				fileObj => $hdfobj);

# open the root group
my $rootGroup = new PDL::IO::HDF5::Group( 'name'=> '/', parent => $hdfobj,
					fileObj => $hdfobj);

# Get a list of groups
my @groups = $rootGroup->groups;

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


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

is( scalar(@groups), 0 );

# Create a dataset in the root group
my $dataset = new PDL::IO::HDF5::Dataset( 'name'=> 'data1', parent => $rootGroup,
					fileObj => $hdfobj);
my $pdl = sequence(5,4);

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

my $pdl2 = $dataset->get;

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

# Set attribute for dataset
ok( $dataset->attrSet( 'attr1' => 'dataset dudeman', 'attr2' => 'Huh What??'));

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

# 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' );

# clean up file
unlink $filename if( -e $filename);

done_testing;