Skip to content

Commit 624a11b

Browse files
committed
removeCache: refactor MultiTag and MultiTagTests
1 parent 4bd8fa4 commit 624a11b

File tree

2 files changed

+88
-45
lines changed

2 files changed

+88
-45
lines changed

+nix/MultiTag.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
% ------------------
2626

2727
function [] = add_reference(obj, add_this)
28-
obj.referencesCache = nix.Utils.add_entity(obj, ...
29-
add_this, 'nix.DataArray', 'MultiTag::addReference', obj.referencesCache);
28+
nix.Utils.add_entity_(obj, add_this, ...
29+
'nix.DataArray', 'MultiTag::addReference');
3030
end;
3131

3232
function hasRef = has_reference(obj, id_or_name)
33-
hasRef = nix_mx('MultiTag::hasReference', obj.nix_handle, id_or_name);
33+
hasRef = nix_mx('MultiTag::hasReference', ...
34+
obj.nix_handle, id_or_name);
3435
end;
3536

3637
function delCheck = remove_reference(obj, del)
37-
[delCheck, obj.referencesCache] = nix.Utils.delete_entity(obj, ...
38-
del, 'nix.DataArray', 'MultiTag::removeReference', obj.referencesCache);
38+
delCheck = nix.Utils.delete_entity_(obj, del, ...
39+
'nix.DataArray', 'MultiTag::removeReference');
3940
end;
4041

4142
function retObj = open_reference(obj, id_or_name)
@@ -65,17 +66,17 @@
6566
else
6667
addID = add_this;
6768
end;
68-
retObj = nix.Feature(nix_mx('MultiTag::createFeature', obj.nix_handle, addID, link_type));
69-
obj.featuresCache.lastUpdate = 0;
69+
retObj = nix.Feature(nix_mx('MultiTag::createFeature', ...
70+
obj.nix_handle, addID, link_type));
7071
end;
7172

7273
function hasFeature = has_feature(obj, id_or_name)
7374
hasFeature = nix_mx('MultiTag::hasFeature', obj.nix_handle, id_or_name);
7475
end;
7576

7677
function delCheck = remove_feature(obj, del)
77-
[delCheck, obj.featuresCache] = nix.Utils.delete_entity(obj, ...
78-
del, 'nix.Feature', 'MultiTag::deleteFeature', obj.featuresCache);
78+
delCheck = nix.Utils.delete_entity_(obj, del, ...
79+
'nix.Feature', 'MultiTag::deleteFeature');
7980
end;
8081

8182
function retObj = open_feature(obj, id_or_name)

tests/TestMultiTag.m

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,29 @@
3030

3131
%% Test: Add sources by entity and id
3232
function [] = test_add_source ( varargin )
33-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
34-
b = test_file.createBlock('sourceTest', 'nixBlock');
33+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
34+
f = nix.File(fileName, nix.FileMode.Overwrite);
35+
b = f.createBlock('sourceTest', 'nixBlock');
3536
tmp = b.create_data_array('sourceTestDataArray', 'nixDataArray', 'double', [1 2]);
36-
getSource = b.create_source('sourceTest', 'nixSource');
37-
tmp = getSource.create_source('nestedSource1', 'nixSource');
38-
tmp = getSource.create_source('nestedSource2', 'nixSource');
39-
getMTag = b.create_multi_tag('sourcetest', 'nixMultiTag', b.dataArrays{1});
37+
s = b.create_source('sourceTest', 'nixSource');
38+
tmp = s.create_source('nestedSource1', 'nixSource');
39+
tmp = s.create_source('nestedSource2', 'nixSource');
40+
mTag = b.create_multi_tag('sourcetest', 'nixMultiTag', b.dataArrays{1});
4041

41-
assert(isempty(getMTag.sources));
42-
getMTag.add_source(getSource.sources{1}.id);
43-
getMTag.add_source(getSource.sources{2});
44-
assert(size(getMTag.sources, 1) == 2);
42+
assert(isempty(mTag.sources));
43+
assert(isempty(f.blocks{1}.multiTags{1}.sources));
44+
45+
mTag.add_source(s.sources{1}.id);
46+
assert(size(mTag.sources, 1) == 1);
47+
assert(size(f.blocks{1}.multiTags{1}.sources, 1) == 1);
48+
49+
mTag.add_source(s.sources{2});
50+
assert(size(mTag.sources, 1) == 2);
51+
assert(size(f.blocks{1}.multiTags{1}.sources, 1) == 2);
52+
53+
clear tmp mTag s b f;
54+
f = nix.File(fileName, nix.FileMode.ReadOnly);
55+
assert(size(f.blocks{1}.multiTags{1}.sources, 1) == 2);
4556
end
4657

4758
%% Test: Remove sources by entity and id
@@ -67,18 +78,29 @@
6778

6879
%% Test: Add references by entity and id
6980
function [] = test_add_reference ( varargin )
70-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
71-
b = test_file.createBlock('referenceTest', 'nixBlock');
81+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
82+
f = nix.File(fileName, nix.FileMode.Overwrite);
83+
b = f.createBlock('referenceTest', 'nixBlock');
7284
tmp = b.create_data_array('referenceTestDataArray', 'nixDataArray', 'double', [1 2]);
73-
getMTag = b.create_multi_tag('referencetest', 'nixMultiTag', b.dataArrays{1});
85+
mTag = b.create_multi_tag('referencetest', 'nixMultiTag', b.dataArrays{1});
7486

7587
tmp = b.create_data_array('referenceTest1', 'nixDataArray', 'double', [3 4]);
7688
tmp = b.create_data_array('referenceTest2', 'nixDataArray', 'double', [5 6]);
7789

78-
assert(isempty(getMTag.references));
79-
getMTag.add_reference(b.dataArrays{2}.id);
80-
getMTag.add_reference(b.dataArrays{3});
81-
assert(size(getMTag.references, 1) == 2);
90+
assert(isempty(mTag.references));
91+
assert(isempty(f.blocks{1}.multiTags{1}.references));
92+
93+
mTag.add_reference(b.dataArrays{2}.id);
94+
assert(size(mTag.references, 1) == 1);
95+
assert(size(f.blocks{1}.multiTags{1}.references, 1) == 1);
96+
97+
mTag.add_reference(b.dataArrays{3});
98+
assert(size(mTag.references, 1) == 2);
99+
assert(size(f.blocks{1}.multiTags{1}.references, 1) == 2);
100+
101+
clear tmp mTag b f;
102+
f = nix.File(fileName, nix.FileMode.ReadOnly);
103+
assert(size(f.blocks{1}.multiTags{1}.references, 1) == 2);
82104
end
83105

84106
%% Test: Remove references by entity and id
@@ -103,10 +125,11 @@
103125

104126
%% Test: Add features by entity and id
105127
function [] = test_add_feature ( varargin )
106-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
128+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
129+
f = nix.File(fileName, nix.FileMode.Overwrite);
107130
b = f.createBlock('featureTest', 'nixBlock');
108131
tmp = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2]);
109-
getMTag = b.create_multi_tag('featuretest', 'nixMultiTag', b.dataArrays{1});
132+
mTag = b.create_multi_tag('featuretest', 'nixMultiTag', b.dataArrays{1});
110133

111134
tmp = b.create_data_array('featTestDA1', 'nixDataArray', 'double', [1 2]);
112135
tmp = b.create_data_array('featTestDA2', 'nixDataArray', 'double', [3 4]);
@@ -115,14 +138,20 @@
115138
tmp = b.create_data_array('featTestDA5', 'nixDataArray', 'double', [9 10]);
116139
tmp = b.create_data_array('featTestDA6', 'nixDataArray', 'double', [11 12]);
117140

118-
assert(isempty(getMTag.features));
119-
tmp = getMTag.add_feature(b.dataArrays{2}.id, nix.LinkType.Tagged);
120-
tmp = getMTag.add_feature(b.dataArrays{3}, nix.LinkType.Tagged);
121-
tmp = getMTag.add_feature(b.dataArrays{4}.id, nix.LinkType.Untagged);
122-
tmp = getMTag.add_feature(b.dataArrays{5}, nix.LinkType.Untagged);
123-
tmp = getMTag.add_feature(b.dataArrays{6}.id, nix.LinkType.Indexed);
124-
tmp = getMTag.add_feature(b.dataArrays{7}, nix.LinkType.Indexed);
125-
assert(size(getMTag.features, 1) == 6);
141+
assert(isempty(mTag.features));
142+
assert(isempty(f.blocks{1}.multiTags{1}.features));
143+
tmp = mTag.add_feature(b.dataArrays{2}.id, nix.LinkType.Tagged);
144+
tmp = mTag.add_feature(b.dataArrays{3}, nix.LinkType.Tagged);
145+
tmp = mTag.add_feature(b.dataArrays{4}.id, nix.LinkType.Untagged);
146+
tmp = mTag.add_feature(b.dataArrays{5}, nix.LinkType.Untagged);
147+
tmp = mTag.add_feature(b.dataArrays{6}.id, nix.LinkType.Indexed);
148+
tmp = mTag.add_feature(b.dataArrays{7}, nix.LinkType.Indexed);
149+
assert(size(mTag.features, 1) == 6);
150+
assert(size(f.blocks{1}.multiTags{1}.features, 1) == 6);
151+
152+
clear tmp mTag b f;
153+
f = nix.File(fileName, nix.FileMode.ReadOnly);
154+
assert(size(f.blocks{1}.multiTags{1}.features, 1) == 6);
126155
end
127156

128157
%% Test: Remove features by entity and id
@@ -249,19 +278,29 @@
249278

250279
%% Test: Add positions by entity and id
251280
function [] = test_add_positions ( varargin )
252-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
253-
b = test_file.createBlock('positionsTest', 'nixBlock');
281+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
282+
posName1 = 'positionsTest1';
283+
posName2 = 'positionsTest2';
284+
285+
f = nix.File(fileName, nix.FileMode.Overwrite);
286+
b = f.createBlock('positionsTest', 'nixBlock');
254287
tmp = b.create_data_array('positionsTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
255-
getMTag = b.create_multi_tag('positionstest', 'nixMultiTag', b.dataArrays{1});
288+
mTag = b.create_multi_tag('positionstest', 'nixMultiTag', b.dataArrays{1});
256289

257-
tmp = b.create_data_array('positionsTest1', 'nixDataArray', 'double', [0 1]);
258-
tmp = b.create_data_array('positionsTest2', 'nixDataArray', 'double', [2 4]);
290+
tmp = b.create_data_array(posName1, 'nixDataArray', 'double', [0 1]);
291+
tmp = b.create_data_array(posName2, 'nixDataArray', 'double', [2 4]);
259292

260-
getMTag.add_positions(b.dataArrays{2}.id);
261-
assert(strcmp(getMTag.open_positions.name, 'positionsTest1'));
293+
mTag.add_positions(b.dataArrays{2}.id);
294+
assert(strcmp(mTag.open_positions.name, posName1));
295+
assert(strcmp(f.blocks{1}.multiTags{1}.open_positions.name, posName1));
262296

263-
getMTag.add_positions(b.dataArrays{3});
264-
assert(strcmp(getMTag.open_positions.name, 'positionsTest2'));
297+
mTag.add_positions(b.dataArrays{3});
298+
assert(strcmp(mTag.open_positions.name, posName2));
299+
assert(strcmp(f.blocks{1}.multiTags{1}.open_positions.name, posName2));
300+
301+
clear tmp mTag b f;
302+
f = nix.File(fileName, nix.FileMode.ReadOnly);
303+
assert(strcmp(f.blocks{1}.multiTags{1}.open_positions.name, posName2));
265304
end
266305

267306
%% Test: Has positions
@@ -305,13 +344,16 @@
305344
tmp = b.create_data_array(extName2, 'nixDataArray', 'double', [1, 3]);
306345

307346
assert(isempty(getMTag.open_extents));
347+
assert(isempty(f.blocks{1}.multiTags{1}.open_extents));
308348

309349
getMTag.add_positions(b.dataArrays{2});
310350
getMTag.set_extents(b.dataArrays{4}.id);
311351
assert(strcmp(getMTag.open_extents.name, extName1));
352+
assert(strcmp(f.blocks{1}.multiTags{1}.open_extents.name, extName1));
312353

313354
getMTag.set_extents('');
314355
assert(isempty(getMTag.open_extents));
356+
assert(isempty(f.blocks{1}.multiTags{1}.open_extents));
315357

316358
getMTag.add_positions(b.dataArrays{3});
317359
getMTag.set_extents(b.dataArrays{5});

0 commit comments

Comments
 (0)