Skip to content

Commit aefad5c

Browse files
committed
refactor multitag tests
1 parent 072342d commit aefad5c

File tree

1 file changed

+35
-41
lines changed

1 file changed

+35
-41
lines changed

tests/TestMultiTag.m

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@
174174

175175
%% Test: fetch features
176176
function [] = test_fetch_features( varargin )
177-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
178-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
179-
getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
177+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
178+
b = test_file.createBlock('featureTest', 'nixBlock');
179+
tmp = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2]);
180+
getMTag = b.create_multi_tag('featuretest', 'nixMultiTag', b.dataArrays{1});
180181

181-
%-- ToDo get testfile with tag referencing a source
182-
assert(size(getMultiTag.features(), 1) == 0);
183-
disp('Test MultiTag: fetch features ... TODO (proper testfile)');
182+
assert(isempty(getMTag.features));
183+
tmp = b.create_data_array('featTestDA', 'nixDataArray', 'double', [1 2]);
184+
tmp = getMTag.add_feature(b.dataArrays{2}, nix.LinkType.Tagged);
185+
assert(size(getMTag.features, 1) == 1);
184186
end
185187

186188
%% Test: Open source by ID or name
@@ -205,23 +207,19 @@
205207
assert(isempty(getSource));
206208
end
207209

208-
%% Test: Open feature by ID or name
210+
%% Test: Open feature by ID
209211
function [] = test_open_feature( varargin )
210-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
211-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
212-
getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
213-
214-
%-- TODO: implement testfile with feature referenced from a tag
215-
%getFeatByID = getMultiTag.open_feature(getMultiTag.features{1,1}.id);
216-
%assert(strcmp(getFeatByID.id, ''));
217-
disp('Test MultiTag: open feature by ID ... TODO (proper testfile)');
218-
219-
%getFeatByName = getTag.open_feature(getTag.features{1,1}.name);
220-
%assert(strcmp(getFeatByName.id, ''));
221-
disp('Test MultiTag: open feature by name ... TODO (proper testfile)');
222-
212+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
213+
b = test_file.createBlock('featureTest', 'nixBlock');
214+
tmp = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2]);
215+
getMTag = b.create_multi_tag('featuretest', 'nixMultiTag', b.dataArrays{1});
216+
217+
tmp = b.create_data_array('featTestDA', 'nixDataArray', 'double', [1 2]);
218+
tmp = getMTag.add_feature(b.dataArrays{2}, nix.LinkType.Tagged);
219+
assert(~isempty(getMTag.open_feature(getMTag.features{1}.id)));
220+
223221
%-- test open non existing feature
224-
getFeat = getMultiTag.open_feature('I dont exist');
222+
getFeat = getMTag.open_feature('I do not exist');
225223
assert(isempty(getFeat));
226224
end
227225

@@ -265,36 +263,32 @@
265263

266264
%% Test: Has positions
267265
function [] = test_has_positions( varargin )
268-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
269-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
266+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
267+
b = test_file.createBlock('positionsTest', 'nixBlock');
268+
tmp = b.create_data_array('positionsTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
269+
getMTag = b.create_multi_tag('positionstest', 'nixMultiTag', b.dataArrays{1});
270+
tmp = b.create_data_array('positionsTest1', 'nixDataArray', 'double', [0 1]);
270271

271-
%-- ToDo implement test for non existing positions
272-
%getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
273-
%assert(~getMultiTag.hasPositions);
274-
disp('Test MultiTag: has no existing positions ... TODO (proper testfile)');
275-
276-
getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
277-
assert(getMultiTag.has_positions);
272+
getMTag.add_positions(b.dataArrays{2}.id);
273+
assert(getMTag.has_positions);
278274
end
279275

280276
%% Test: Open positions
281277
function [] = test_open_positions( varargin )
282-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
283-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
278+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
279+
b = test_file.createBlock('positionsTest', 'nixBlock');
280+
tmp = b.create_data_array('positionsTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
281+
getMTag = b.create_multi_tag('positionstest', 'nixMultiTag', b.dataArrays{1});
282+
tmp = b.create_data_array('positionsTest1', 'nixDataArray', 'double', [0 1]);
284283

285-
%-- ToDo implement test for non existing positions
286-
%getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
287-
%assert(isempty(getMultiTag.open_positions));
288-
disp('Test MultiTag: open non existing positions ... TODO (proper testfile)');
289-
290-
getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
291-
assert(~isempty(getMultiTag.open_positions));
284+
getMTag.add_positions(b.dataArrays{2}.id);
285+
assert(~isempty(getMTag.open_positions));
292286
end
293287

294288
%% Test: Add extents by entity and id
295289
function [] = test_add_extents ( varargin )
296-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
297-
b = test_file.createBlock('extentsTest', 'nixBlock');
290+
% test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
291+
% b = test_file.createBlock('extentsTest', 'nixBlock');
298292
% tmp = b.create_data_array('extentsTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6; 1 2 3 4 5 6]);
299293
% getMTag = b.create_multi_tag('extentstest', 'nixMultiTag', b.dataArrays{1});
300294

0 commit comments

Comments
 (0)