Skip to content

Commit 0b694b9

Browse files
committed
addGroup: add Block group tests
1 parent e085558 commit 0b694b9

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/TestBlock.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
funcs{end+1} = @test_has_tag;
2626
funcs{end+1} = @test_set_metadata;
2727
funcs{end+1} = @test_open_metadata;
28+
funcs{end+1} = @test_create_group;
29+
funcs{end+1} = @test_delete_group;
30+
funcs{end+1} = @test_has_group;
2831
end
2932

3033
function [] = test_attrs( varargin )
@@ -371,3 +374,63 @@
371374

372375
assert(strcmp(b.open_metadata.name, 'testSection'));
373376
end
377+
378+
%% Test: Create Group
379+
function [] = test_create_group( varargin )
380+
fileName = 'testRW.h5';
381+
groupName = 'testGroup';
382+
groupType = 'nixGroup';
383+
384+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
385+
b = f.createBlock('grouptest', 'nixBlock');
386+
387+
assert(isempty(b.groups));
388+
389+
g = b.create_group(groupName, groupType);
390+
assert(strcmp(g.name, groupName));
391+
assert(strcmp(g.type, groupType));
392+
assert(~isempty(b.groups));
393+
394+
clear g b f;
395+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
396+
assert(~isempty(f.blocks{1}.groups));
397+
assert(strcmp(f.blocks{1}.groups{1}.name, groupName));
398+
end
399+
400+
%% Test: delete group by entity and id
401+
function [] = test_delete_group( varargin )
402+
fileName = 'testRW.h5';
403+
groupType = 'nixGroup';
404+
405+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
406+
b = f.createBlock('grouptest', 'nixBlock');
407+
g1 = b.create_group('testGroup1', groupType);
408+
g2 = b.create_group('testGroup2', groupType);
409+
410+
assert(size(b.groups, 1) == 2);
411+
assert(b.delete_group(b.groups{2}.id));
412+
assert(size(b.groups, 1) == 1);
413+
assert(b.delete_group(b.groups{1}));
414+
assert(isempty(b.groups));
415+
416+
assert(~b.delete_group('I do not exist'));
417+
418+
clear g b f;
419+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
420+
assert(isempty(f.blocks{1}.groups));
421+
end
422+
423+
%% Test: Block has Group by entity
424+
function [] = test_has_group( varargin )
425+
%{
426+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5', nix.FileMode.Overwrite));
427+
b = f.createBlock('grouptest', 'nixBlock');
428+
429+
g = b.create_group('testGroup', 'nixGroup');
430+
assert(b.has_group(b.groups{1}));
431+
432+
b.delete_group(b.groups{1});
433+
assert(~b.has_group(g));
434+
%}
435+
disp('Test Block.has_group ... TODO (function not working at the moment)');
436+
end

0 commit comments

Comments
 (0)