Skip to content

Commit 45eeec6

Browse files
committed
removeCache: refactor Tag and TagTests
1 parent 624a11b commit 45eeec6

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

+nix/Tag.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
% ------------------
2828

2929
function [] = add_reference(obj, add_this)
30-
obj.referencesCache = nix.Utils.add_entity(obj, ...
31-
add_this, 'nix.DataArray', 'Tag::addReference', obj.referencesCache);
30+
nix.Utils.add_entity(obj, add_this, ...
31+
'nix.DataArray', 'Tag::addReference');
3232
end;
3333

3434
function hasRef = has_reference(obj, id_or_name)
3535
hasRef = nix_mx('Tag::hasReference', obj.nix_handle, id_or_name);
3636
end;
3737

3838
function delCheck = remove_reference(obj, del)
39-
[delCheck, obj.referencesCache] = nix.Utils.delete_entity(obj, ...
40-
del, 'nix.DataArray', 'Tag::removeReference', obj.referencesCache);
39+
delCheck = nix.Utils.delete_entity_(obj, del, ...
40+
'nix.DataArray', 'Tag::removeReference');
4141
end;
4242

4343
function retObj = open_reference(obj, id_or_name)
@@ -65,17 +65,17 @@
6565
else
6666
addID = add_this;
6767
end;
68-
retObj = nix.Feature(nix_mx('Tag::createFeature', obj.nix_handle, addID, link_type));
69-
obj.featuresCache.lastUpdate = 0;
68+
retObj = nix.Feature(nix_mx('Tag::createFeature', ...
69+
obj.nix_handle, addID, link_type));
7070
end;
7171

7272
function hasFeature = has_feature(obj, id_or_name)
7373
hasFeature = nix_mx('Tag::hasFeature', obj.nix_handle, id_or_name);
7474
end;
7575

7676
function delCheck = remove_feature(obj, del)
77-
[delCheck, obj.featuresCache] = nix.Utils.delete_entity(obj, ...
78-
del, 'nix.Feature', 'Tag::deleteFeature', obj.featuresCache);
77+
delCheck = nix.Utils.delete_entity_(obj, del, ...
78+
'nix.Feature', 'Tag::deleteFeature');
7979
end;
8080

8181
function retObj = open_feature(obj, id_or_name)

tests/TestTag.m

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,25 @@
2626

2727
%% Test: Add sources by entity and id
2828
function [] = test_add_source ( varargin )
29-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
30-
getBlock = test_file.createBlock('sourceTest', 'nixBlock');
31-
getSource = getBlock.create_source('sourceTest', 'nixSource');
32-
tmp = getSource.create_source('nestedSource1', 'nixSource');
33-
tmp = getSource.create_source('nestedSource2', 'nixSource');
29+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
30+
f = nix.File(fileName, nix.FileMode.Overwrite);
31+
b = f.createBlock('sourceTest', 'nixBlock');
32+
s = b.create_source('sourceTest', 'nixSource');
33+
tmp = s.create_source('nestedSource1', 'nixSource');
34+
tmp = s.create_source('nestedSource2', 'nixSource');
3435
position = [1.0 1.2 1.3 15.9];
35-
getTag = getBlock.create_tag('sourcetest', 'nixTag', position);
36+
t = b.create_tag('sourcetest', 'nixTag', position);
3637

37-
assert(isempty(getTag.sources));
38-
getTag.add_source(getSource.sources{1}.id);
39-
getTag.add_source(getSource.sources{2});
40-
assert(size(getTag.sources,1) == 2);
38+
assert(isempty(t.sources));
39+
assert(isempty(f.blocks{1}.tags{1}.sources));
40+
t.add_source(s.sources{1}.id);
41+
t.add_source(s.sources{2});
42+
assert(size(t.sources, 1) == 2);
43+
assert(size(f.blocks{1}.tags{1}.sources, 1) == 2);
44+
45+
clear tmp t s b f;
46+
f = nix.File(fileName, nix.FileMode.ReadOnly);
47+
assert(size(f.blocks{1}.tags{1}.sources, 1) == 2);
4148
end
4249

4350
%% Test: Remove sources by entity and id
@@ -63,18 +70,26 @@
6370

6471
%% Test: Add references by entity and id
6572
function [] = test_add_reference ( varargin )
66-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
67-
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
68-
tmp = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
69-
tmp = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
73+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
74+
f = nix.File(fileName, nix.FileMode.Overwrite);
75+
b = f.createBlock('referenceTest', 'nixBlock');
76+
tmp = b.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
77+
tmp = b.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
7078

7179
position = [1.0 1.2 1.3 15.9];
72-
getTag = getBlock.create_tag('referenceTest', 'nixTag', position);
80+
t = b.create_tag('referenceTest', 'nixTag', position);
7381

74-
assert(isempty(getTag.references));
75-
getTag.add_reference(getBlock.dataArrays{1}.id);
76-
getTag.add_reference(getBlock.dataArrays{2});
77-
assert(size(getTag.references, 1) == 2);
82+
assert(isempty(t.references));
83+
assert(isempty(f.blocks{1}.tags{1}.references));
84+
85+
t.add_reference(b.dataArrays{1}.id);
86+
t.add_reference(b.dataArrays{2});
87+
assert(size(t.references, 1) == 2);
88+
assert(size(f.blocks{1}.tags{1}.references, 1) == 2);
89+
90+
clear tmp t b f;
91+
f = nix.File(fileName, nix.FileMode.ReadOnly);
92+
assert(size(f.blocks{1}.tags{1}.references, 1) == 2);
7893
end
7994

8095
%% Test: Remove references by entity and id
@@ -100,7 +115,8 @@
100115

101116
%% Test: Add features by entity and id
102117
function [] = test_add_feature ( varargin )
103-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
118+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
119+
f = nix.File(fileName, nix.FileMode.Overwrite);
104120
b = f.createBlock('featureTest', 'nixBlock');
105121
tmp = b.create_data_array('featureTestDataArray1', 'nixDataArray', 'double', [1 2]);
106122
tmp = b.create_data_array('featureTestDataArray2', 'nixDataArray', 'double', [3 4]);
@@ -109,16 +125,22 @@
109125
tmp = b.create_data_array('featureTestDataArray5', 'nixDataArray', 'double', [9 10]);
110126
tmp = b.create_data_array('featureTestDataArray6', 'nixDataArray', 'double', [11 12]);
111127
position = [1.0 1.2 1.3 15.9];
112-
getTag = b.create_tag('featureTest', 'nixTag', position);
128+
t = b.create_tag('featureTest', 'nixTag', position);
113129

114-
assert(isempty(getTag.features));
115-
tmp = getTag.add_feature(b.dataArrays{1}.id, nix.LinkType.Tagged);
116-
tmp = getTag.add_feature(b.dataArrays{2}, nix.LinkType.Tagged);
117-
tmp = getTag.add_feature(b.dataArrays{3}.id, nix.LinkType.Untagged);
118-
tmp = getTag.add_feature(b.dataArrays{4}, nix.LinkType.Untagged);
119-
tmp = getTag.add_feature(b.dataArrays{5}.id, nix.LinkType.Indexed);
120-
tmp = getTag.add_feature(b.dataArrays{6}, nix.LinkType.Indexed);
121-
assert(size(getTag.features, 1) == 6)
130+
assert(isempty(t.features));
131+
assert(isempty(f.blocks{1}.tags{1}.features));
132+
tmp = t.add_feature(b.dataArrays{1}.id, nix.LinkType.Tagged);
133+
tmp = t.add_feature(b.dataArrays{2}, nix.LinkType.Tagged);
134+
tmp = t.add_feature(b.dataArrays{3}.id, nix.LinkType.Untagged);
135+
tmp = t.add_feature(b.dataArrays{4}, nix.LinkType.Untagged);
136+
tmp = t.add_feature(b.dataArrays{5}.id, nix.LinkType.Indexed);
137+
tmp = t.add_feature(b.dataArrays{6}, nix.LinkType.Indexed);
138+
assert(size(t.features, 1) == 6);
139+
assert(size(f.blocks{1}.tags{1}.features, 1) == 6);
140+
141+
clear tmp t b f;
142+
f = nix.File(fileName, nix.FileMode.ReadOnly);
143+
assert(size(f.blocks{1}.tags{1}.features, 1) == 6);
122144
end
123145

124146
%% Test: Remove features by entity and id

0 commit comments

Comments
 (0)