Skip to content

Commit 14f0483

Browse files
committed
completify: add missing Tag functions and tests
1 parent b62e8b4 commit 14f0483

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

+nix/Tag.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
add_this, 'nix.DataArray', 'Tag::addReference', obj.referencesCache);
3232
end;
3333

34+
function hasRef = has_reference(obj, id_or_name)
35+
hasRef = nix_mx('Tag::hasReference', obj.nix_handle, id_or_name);
36+
end;
37+
3438
function delCheck = remove_reference(obj, del)
3539
[delCheck, obj.referencesCache] = nix.Utils.delete_entity(obj, ...
3640
del, 'nix.DataArray', 'Tag::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('Tag::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', 'Tag::deleteFeature', obj.featuresCache);
@@ -86,4 +94,4 @@
8694
end;
8795

8896
end;
89-
end
97+
end

nix_mx.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ void mexFunction(int nlhs,
181181
.reg("references", GETTER(std::vector<nix::DataArray>, nix::Tag, references))
182182
.reg("features", &nix::Tag::features)
183183
.reg("sources", FILTER(std::vector<nix::Source>, nix::Tag, std::function<bool(const nix::Source &)>, sources))
184+
.reg("hasReference", GETBYSTR(bool, nix::Tag, hasReference))
185+
.reg("hasFeature", GETBYSTR(bool, nix::Tag, hasFeature))
184186
.reg("openReferenceDataArray", GETBYSTR(nix::DataArray, nix::Tag, getReference))
185187
.reg("openFeature", GETBYSTR(nix::Feature, nix::Tag, getFeature))
186188
.reg("openSource", GETBYSTR(nix::Source, nix::Tag, getSource))
@@ -192,6 +194,9 @@ void mexFunction(int nlhs,
192194
.reg("set_type", SETTER(const std::string&, nix::Tag, type))
193195
.reg("set_definition", SETTER(const std::string&, nix::Tag, definition))
194196
.reg("set_none_definition", SETTER(const boost::none_t, nix::Tag, definition))
197+
.reg("set_position", SETTER(const std::vector<double>&, nix::Tag, position))
198+
.reg("set_extent", SETTER(const std::vector<double>&, nix::Tag, extent))
199+
.reg("set_none_extent", SETTER(const boost::none_t, nix::Tag, extent))
195200
.reg("removeReference", REMOVER(nix::DataArray, nix::Tag, removeReference))
196201
.reg("removeSource", REMOVER(nix::Source, nix::Tag, removeSource))
197202
.reg("deleteFeature", REMOVER(nix::Feature, nix::Tag, deleteFeature));

tests/TestTag.m

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
funcs{end+1} = @test_retrieve_data;
2121
funcs{end+1} = @test_retrieve_feature_data;
2222
funcs{end+1} = @test_attrs;
23+
funcs{end+1} = @test_has_feature;
24+
funcs{end+1} = @test_has_reference;
2325
end
2426

2527
%% Test: Add sources by entity and id
@@ -291,11 +293,13 @@
291293
disp('Test Tag: retrieve feature ... TODO (proper testfile)');
292294
end
293295

296+
%% Test: Read and write nix.Tag attributes
294297
function [] = test_attrs( varargin )
295-
%% Test: Access Attributes
296-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
298+
fileName = 'testRW.h5';
299+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
297300
b = f.createBlock('testBlock', 'nixBlock');
298-
t1 = b.create_tag('testTag', 'nixTag', [1, 2, 3, 4]);
301+
pos = [1, 2, 3, 4];
302+
t1 = b.create_tag('testTag', 'nixTag', pos);
299303

300304
assert(~isempty(t1.id));
301305
assert(strcmp(t1.name, 'testTag'));
@@ -317,4 +321,64 @@
317321

318322
t1.units = {};
319323
assert(isempty(t1.units));
320-
end
324+
325+
assert(isequal(t1.position, pos));
326+
newPos = [1, 2.2, 3];
327+
t1.position = newPos;
328+
assert(~isequal(t1.position, pos));
329+
assert(isequal(t1.position, newPos));
330+
331+
assert(isempty(t1.extent));
332+
ext = [1 2];
333+
newExt = [3 4.5];
334+
lastExt = [6 7.8 9];
335+
t1.extent = ext;
336+
assert(isequal(t1.extent, ext));
337+
t1.extent = newExt;
338+
assert(~isequal(t1.extent, ext));
339+
assert(isequal(t1.extent, newExt));
340+
t1.extent = [];
341+
assert(isempty(t1.extent));
342+
t1.extent = lastExt;
343+
344+
clear t1 b f;
345+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
346+
assert(isequal(f.blocks{1}.tags{1}.position, newPos));
347+
assert(isequal(f.blocks{1}.tags{1}.extent, lastExt));
348+
end
349+
350+
%% Test: nix.Tag has feature by ID
351+
function [] = test_has_feature( varargin )
352+
fileName = 'testRW.h5';
353+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
354+
b = f.createBlock('featureTest', 'nixBlock');
355+
da = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2]);
356+
t = b.create_tag('featureTest', 'nixTag', [1.0 1.2 1.3 15.9]);
357+
feature = t.add_feature(b.dataArrays{1}, nix.LinkType.Tagged);
358+
featureID = feature.id;
359+
360+
assert(~t.has_feature('I do not exist'));
361+
assert(t.has_feature(featureID));
362+
363+
clear tmp t da b f;
364+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
365+
assert(f.blocks{1}.tags{1}.has_feature(featureID));
366+
end
367+
368+
%% Test: nix.Tag has reference by ID or name
369+
function [] = test_has_reference( varargin )
370+
fileName = 'testRW.h5';
371+
daName = 'referenceTest';
372+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
373+
b = f.createBlock('referenceTest', 'nixBlock');
374+
da = b.create_data_array(daName, 'nixDataArray', 'double', [1 2]);
375+
t = b.create_tag('referenceTest', 'nixTag', [1.0 1.2 1.3 15.9]);
376+
t.add_reference(b.dataArrays{1});
377+
378+
assert(~t.has_reference('I do not exist'));
379+
assert(t.has_reference(da.id));
380+
381+
clear t da b f;
382+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
383+
assert(f.blocks{1}.tags{1}.has_reference(daName));
384+
end

0 commit comments

Comments
 (0)