Skip to content

Commit 22c7697

Browse files
committed
completify: add missing MultiTag functions and tests
1 parent 14f0483 commit 22c7697

File tree

5 files changed

+118
-51
lines changed

5 files changed

+118
-51
lines changed

+nix/MultiTag.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
add_this, 'nix.DataArray', 'MultiTag::addReference', obj.referencesCache);
3030
end;
3131

32+
function hasRef = has_reference(obj, id_or_name)
33+
hasRef = nix_mx('MultiTag::hasReference', obj.nix_handle, id_or_name);
34+
end;
35+
3236
function delCheck = remove_reference(obj, del)
3337
[delCheck, obj.referencesCache] = nix.Utils.delete_entity(obj, ...
3438
del, 'nix.DataArray', 'MultiTag::removeReference', obj.referencesCache);
@@ -65,6 +69,10 @@
6569
obj.featuresCache.lastUpdate = 0;
6670
end;
6771

72+
function hasFeature = has_feature(obj, id_or_name)
73+
hasFeature = nix_mx('MultiTag::hasFeature', obj.nix_handle, id_or_name);
74+
end;
75+
6876
function delCheck = remove_feature(obj, del)
6977
[delCheck, obj.featuresCache] = nix.Utils.delete_entity(obj, ...
7078
del, 'nix.Feature', 'MultiTag::deleteFeature', obj.featuresCache);
@@ -124,14 +132,18 @@
124132
end;
125133
end;
126134

127-
function [] = add_extents(obj, add_this)
128-
if(strcmp(class(add_this), 'nix.DataArray'))
129-
addID = add_this.id;
135+
function [] = set_extents(obj, add_this)
136+
if(isempty(add_this))
137+
nix_mx('MultiTag::set_none_extents', obj.nix_handle, 0);
130138
else
131-
addID = add_this;
139+
if(strcmp(class(add_this), 'nix.DataArray'))
140+
addID = add_this.id;
141+
else
142+
addID = add_this;
143+
end;
144+
nix_mx('MultiTag::set_extents', obj.nix_handle, addID);
132145
end;
133-
nix_mx('MultiTag::addExtents', obj.nix_handle, addID);
134146
end;
135147

136148
end;
137-
end
149+
end

nix_mx.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,18 @@ void mexFunction(int nlhs,
212212
.reg("features", &nix::MultiTag::features)
213213
.reg("sources", FILTER(std::vector<nix::Source>, nix::MultiTag, std::function<bool(const nix::Source &)>, sources))
214214
.reg("hasPositions", GETCONTENT(bool, nix::MultiTag, hasPositions))
215+
.reg("hasReference", GETBYSTR(bool, nix::MultiTag, hasReference))
216+
.reg("hasFeature", GETBYSTR(bool, nix::MultiTag, hasFeature))
215217
.reg("openPositions", GETCONTENT(nix::DataArray, nix::MultiTag, positions))
216218
.reg("openExtents", GETCONTENT(nix::DataArray, nix::MultiTag, extents))
217219
.reg("openReferences", GETBYSTR(nix::DataArray, nix::MultiTag, getReference))
218220
.reg("openFeature", GETBYSTR(nix::Feature, nix::MultiTag, getFeature))
219221
.reg("openSource", GETBYSTR(nix::Source, nix::MultiTag, getSource))
220222
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::MultiTag, metadata))
223+
.reg("set_units", SETTER(const std::vector<std::string>&, nix::MultiTag, units))
224+
.reg("set_none_units", SETTER(const boost::none_t, nix::MultiTag, units))
225+
.reg("set_extents", SETTER(const std::string&, nix::MultiTag, extents))
226+
.reg("set_none_extents", SETTER(const boost::none_t, nix::MultiTag, extents))
221227
.reg("set_metadata", SETTER(const std::string&, nix::MultiTag, metadata))
222228
.reg("set_none_metadata", SETTER(const boost::none_t, nix::MultiTag, metadata))
223229
.reg("removeReference", REMOVER(nix::DataArray, nix::MultiTag, removeReference))
@@ -229,7 +235,6 @@ void mexFunction(int nlhs,
229235
methods->add("MultiTag::addSource", nixmultitag::add_source);
230236
methods->add("MultiTag::createFeature", nixmultitag::create_feature);
231237
methods->add("MultiTag::addPositions", nixmultitag::add_positions);
232-
methods->add("MultiTag::addExtents", nixmultitag::add_extents);
233238

234239
classdef<nix::Section>("Section", methods)
235240
.desc(&nixsection::describe)

src/nixmultitag.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,4 @@ namespace nixmultitag {
6868
currObj.positions(input.str(2));
6969
}
7070

71-
void add_extents(const extractor &input, infusor &output)
72-
{
73-
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
74-
currObj.extents(input.str(2));
75-
}
76-
77-
void remove_extents(const extractor &input, infusor &output);
78-
7971
} // namespace nixmultitag

src/nixmultitag.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ namespace nixmultitag {
1919

2020
void add_positions(const extractor &input, infusor &output);
2121

22-
void add_extents(const extractor &input, infusor &output);
23-
2422
} // namespace nixmultitag
2523

26-
#endif
24+
#endif

tests/TestMultiTag.m

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
funcs{end+1} = @test_add_source;
77
funcs{end+1} = @test_remove_source;
88
funcs{end+1} = @test_add_reference;
9+
funcs{end+1} = @test_has_reference;
910
funcs{end+1} = @test_remove_reference;
1011
funcs{end+1} = @test_add_feature;
12+
funcs{end+1} = @test_has_feature;
1113
funcs{end+1} = @test_remove_feature;
1214
funcs{end+1} = @test_fetch_references;
1315
funcs{end+1} = @test_fetch_sources;
@@ -18,12 +20,12 @@
1820
funcs{end+1} = @test_add_positions;
1921
funcs{end+1} = @test_has_positions;
2022
funcs{end+1} = @test_open_positions;
21-
funcs{end+1} = @test_add_extents;
22-
funcs{end+1} = @test_open_extents;
23+
funcs{end+1} = @test_set_open_extents;
2324
funcs{end+1} = @test_set_metadata;
2425
funcs{end+1} = @test_open_metadata;
2526
funcs{end+1} = @test_retrieve_data;
2627
funcs{end+1} = @test_retrieve_feature_data;
28+
funcs{end+1} = @test_set_units;
2729
end
2830

2931
%% Test: Add sources by entity and id
@@ -286,41 +288,37 @@
286288
assert(~isempty(getMTag.open_positions));
287289
end
288290

289-
%% Test: Add extents by entity and id
290-
function [] = test_add_extents ( varargin )
291-
% test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
292-
% b = test_file.createBlock('extentsTest', 'nixBlock');
293-
% tmp = b.create_data_array('extentsTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6; 1 2 3 4 5 6]);
294-
% getMTag = b.create_multi_tag('extentstest', 'nixMultiTag', b.dataArrays{1});
291+
%% Test: Set extents by entity and ID, open and reset extents
292+
function [] = test_set_open_extents ( varargin )
293+
fileName = 'testRW.h5';
294+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
295+
b = f.createBlock('extentsTest', 'nixBlock');
296+
da = b.create_data_array('extentsTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6; 1 2 3 4 5 6]);
297+
getMTag = b.create_multi_tag('extentstest', 'nixMultiTag', da);
295298

296-
% tmp = b.create_data_array('positionsTest1', 'nixDataArray', 'double', [1, 1]);
297-
% tmp = b.create_data_array('positionsTest2', 'nixDataArray', 'double', [1, 3]);
299+
tmp = b.create_data_array('positionsTest1', 'nixDataArray', 'double', [1, 1]);
300+
tmp = b.create_data_array('positionsTest2', 'nixDataArray', 'double', [1, 3]);
298301

299-
% tmp = b.create_data_array('extentsTest1', 'nixDataArray', 'double', [1, 1]);
300-
% tmp = b.create_data_array('extentsTest2', 'nixDataArray', 'double', [1, 1]);
302+
extName1 = 'extentsTest1';
303+
extName2 = 'extentsTest2';
304+
tmp = b.create_data_array(extName1, 'nixDataArray', 'double', [1, 1]);
305+
tmp = b.create_data_array(extName2, 'nixDataArray', 'double', [1, 3]);
301306

302-
% getMTag.add_positions(b.dataArrays{2});
303-
% getMTag.add_extents(b.dataArrays{4}.id);
304-
% assert(strcmp(getMTag.open_extents.name, 'extentsTest1'));
305-
306-
% getMTag.add_positions(b.dataArrays{3});
307-
% getMTag.add_extents(b.dataArrays{5});
308-
% assert(strcmp(getMTag.open_extents.name, 'extentsTest2'));
309-
disp('Test MultiTag: add extents ... TODO (add dimensions required)');
310-
end
307+
assert(isempty(getMTag.open_extents));
308+
309+
getMTag.add_positions(b.dataArrays{2});
310+
getMTag.set_extents(b.dataArrays{4}.id);
311+
assert(strcmp(getMTag.open_extents.name, extName1));
311312

312-
%% Test: Open extents
313-
function [] = test_open_extents( varargin )
314-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
315-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
316-
317-
getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
318-
assert(isempty(getMultiTag.open_extents));
319-
320-
%-- ToDo implement test for existing extents
321-
%getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
322-
%assert(~isempty(getMultiTag.open_positions));
323-
disp('Test MultiTag: open existing extents ... TODO (proper testfile)');
313+
getMTag.set_extents('');
314+
assert(isempty(getMTag.open_extents));
315+
316+
getMTag.add_positions(b.dataArrays{3});
317+
getMTag.set_extents(b.dataArrays{5});
318+
319+
clear tmp getMTag da b f;
320+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
321+
assert(strcmp(f.blocks{1}.multiTags{1}.open_extents.name, extName2));
324322
end
325323

326324
%% Test: Set metadata
@@ -368,3 +366,65 @@
368366
% TODO
369367
disp('Test MultiTag: retrieve feature ... TODO (proper testfile)');
370368
end
369+
370+
%% Test: nix.MultiTag has feature by ID
371+
function [] = test_has_feature( varargin )
372+
fileName = 'testRW.h5';
373+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
374+
b = f.createBlock('featureTest', 'nixBlock');
375+
da = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2]);
376+
t = b.create_multi_tag('featureTest', 'nixMultiTag', da);
377+
daf = b.create_data_array('featTestDA', 'nixDataArray', 'double', [1 2]);
378+
feature = t.add_feature(daf, nix.LinkType.Tagged);
379+
featureID = feature.id;
380+
381+
assert(~t.has_feature('I do not exist'));
382+
assert(t.has_feature(featureID));
383+
384+
clear feature daf t da b f;
385+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
386+
assert(f.blocks{1}.multiTags{1}.has_feature(featureID));
387+
end
388+
389+
%% Test: nix.MultiTag has reference by ID or name
390+
function [] = test_has_reference( varargin )
391+
fileName = 'testRW.h5';
392+
daName = 'refTestDataArray';
393+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
394+
b = f.createBlock('referenceTestBlock', 'nixBlock');
395+
da = b.create_data_array(daName, 'nixDataArray', 'double', [1 2]);
396+
t = b.create_multi_tag('referenceTest', 'nixMultiTag', da);
397+
refName = 'referenceTest';
398+
daRef = b.create_data_array(refName, 'nixDataArray', 'double', [3 4]);
399+
t.add_reference(daRef.id);
400+
401+
assert(~t.has_reference('I do not exist'));
402+
assert(t.has_reference(daRef.id));
403+
404+
clear t daRef da b f;
405+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
406+
assert(f.blocks{1}.multiTags{1}.has_reference(refName));
407+
end
408+
409+
%% Test: Set units
410+
function [] = test_set_units( varargin )
411+
fileName = 'testRW.h5';
412+
daName = 'testDataArray';
413+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
414+
b = f.createBlock('testBlock', 'nixBlock');
415+
da = b.create_data_array(daName, 'nixDataArray', 'double', [1 2]);
416+
t = b.create_multi_tag('unitsTest', 'nixMultiTag', da);
417+
418+
assert(isempty(t.units));
419+
units = {'mV'};
420+
t.units = {'mV'};
421+
assert(isequal(t.units,units));
422+
t.units = {};
423+
assert(isempty(t.units));
424+
newUnits = {'mV', 'uA'};
425+
t.units = newUnits;
426+
427+
clear t da b f;
428+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
429+
assert(isequal(f.blocks{1}.multiTags{1}.units, newUnits));
430+
end

0 commit comments

Comments
 (0)