Skip to content

Commit 3d71fc1

Browse files
committed
refactor tag tests
1 parent 7c05967 commit 3d71fc1

File tree

1 file changed

+74
-56
lines changed

1 file changed

+74
-56
lines changed

tests/TestTag.m

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
funcs{end+1} = @test_remove_source;
88
funcs{end+1} = @test_add_reference;
99
funcs{end+1} = @test_remove_reference;
10-
funcs{end+1} = @test_list_fetch_references;
11-
funcs{end+1} = @test_list_fetch_sources;
12-
funcs{end+1} = @test_list_fetch_features;
10+
funcs{end+1} = @test_fetch_references;
11+
funcs{end+1} = @test_fetch_sources;
12+
funcs{end+1} = @test_fetch_features;
1313
funcs{end+1} = @test_open_source;
1414
funcs{end+1} = @test_open_feature;
1515
funcs{end+1} = @test_open_reference;
@@ -21,12 +21,12 @@
2121
%% Test: Add sources by entity and id
2222
function [] = test_add_source ( varargin )
2323
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
24-
getBlock = test_file.createBlock('sourcetest', 'nixblock');
25-
getSource = getBlock.create_source('sourcetest','nixsource');
26-
createSource1 = getSource.create_source('nestedsource1','nixsource');
27-
createSource2 = getSource.create_source('nestedsource2','nixsource');
24+
getBlock = test_file.createBlock('sourceTest', 'nixBlock');
25+
getSource = getBlock.create_source('sourceTest', 'nixSource');
26+
tmp = getSource.create_source('nestedSource1', 'nixSource');
27+
tmp = getSource.create_source('nestedSource2', 'nixSource');
2828
position = [1.0 1.2 1.3 15.9];
29-
getTag = getBlock.create_tag('foo', 'bar', position);
29+
getTag = getBlock.create_tag('sourcetest', 'nixTag', position);
3030

3131
assert(isempty(getTag.sources));
3232
getTag.add_source(getSource.sources{1}.id);
@@ -37,12 +37,12 @@
3737
%% Test: Remove sources by entity and id
3838
function [] = test_remove_source ( varargin )
3939
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
40-
getBlock = test_file.createBlock('sourcetest', 'nixblock');
41-
getSource = getBlock.create_source('sourcetest','nixsource');
42-
createSource1 = getSource.create_source('nestedsource1','nixsource');
43-
createSource2 = getSource.create_source('nestedsource2','nixsource');
40+
getBlock = test_file.createBlock('test', 'nixBlock');
41+
getSource = getBlock.create_source('test', 'nixSource');
42+
tmp = getSource.create_source('nestedSource1', 'nixSource');
43+
tmp = getSource.create_source('nestedSource2', 'nixSource');
4444
position = [1.0 1.2 1.3 15.9];
45-
getTag = getBlock.create_tag('foo', 'bar', position);
45+
getTag = getBlock.create_tag('sourcetest', 'nixTag', position);
4646
getTag.add_source(getSource.sources{1}.id);
4747
getTag.add_source(getSource.sources{2});
4848

@@ -58,9 +58,9 @@
5858
%% Test: Add references by entity and id
5959
function [] = test_add_reference ( varargin )
6060
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
61-
getBlock = test_file.createBlock('referenceTest', 'nixblock');
62-
getRefDA1 = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
63-
getRefDA2 = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
61+
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
62+
tmp = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
63+
tmp = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
6464

6565
position = [1.0 1.2 1.3 15.9];
6666
getTag = getBlock.create_tag('referenceTest', 'nixTag', position);
@@ -74,7 +74,7 @@
7474
%% Test: Remove references by entity and id
7575
function [] = test_remove_reference ( varargin )
7676
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
77-
getBlock = test_file.createBlock('referenceTest', 'nixblock');
77+
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
7878
getRefDA1 = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
7979
getRefDA2 = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
8080

@@ -92,29 +92,42 @@
9292
assert(size(getBlock.dataArrays, 1) == 2);
9393
end
9494

95-
%% Test: List/fetch references
96-
function [] = test_list_fetch_references( varargin )
97-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
98-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
99-
getTag = getBlock.open_tag(getBlock.tags{1,1}.id);
95+
%% Test: fetch references
96+
function [] = test_fetch_references( varargin )
97+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
98+
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
99+
tmp = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
100+
tmp = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
101+
tmp = getBlock.create_data_array('referenceTest3', 'nixDataArray', 'double', [5 6]);
102+
position = [1.0 1.2 1.3 15.9];
103+
getTag = getBlock.create_tag('referenceTest', 'nixTag', position);
100104

101-
assert(size(getTag.references(), 1) == 1);
105+
getTag.add_reference(getBlock.dataArrays{1});
106+
getTag.add_reference(getBlock.dataArrays{2});
107+
getTag.add_reference(getBlock.dataArrays{3});
108+
assert(size(getTag.references, 1) == 3);
102109
end
103110

104-
%% Test: List/fetch sources
105-
function [] = test_list_fetch_sources( varargin )
106-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
107-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
108-
getTag = getBlock.open_tag(getBlock.tags{1,1}.id);
109-
110-
%-- ToDo get testfile with tag referencing a source
111-
assert(size(getTag.sources(),1) == 0);
112-
disp('Test Tag: fetch sources ... TODO (proper testfile)');
111+
%% Test: fetch sources
112+
function [] = test_fetch_sources( varargin )
113+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
114+
getBlock = test_file.createBlock('test', 'nixBlock');
115+
getSource = getBlock.create_source('test','nixSource');
116+
tmp = getSource.create_source('nestedsource1', 'nixSource');
117+
tmp = getSource.create_source('nestedsource2', 'nixSource');
118+
tmp = getSource.create_source('nestedsource3', 'nixSource');
119+
position = [1.0 1.2 1.3 15.9];
120+
getTag = getBlock.create_tag('tagtest', 'nixTag', position);
121+
122+
getTag.add_source(getSource.sources{1});
123+
getTag.add_source(getSource.sources{2});
124+
getTag.add_source(getSource.sources{3});
125+
assert(size(getTag.sources, 1) == 3);
113126
end
114127

115128

116-
%% Test: List/fetch features
117-
function [] = test_list_fetch_features( varargin )
129+
%% Test: fetch features
130+
function [] = test_fetch_features( varargin )
118131
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
119132
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
120133
getTag = getBlock.open_tag(getBlock.tags{1,1}.id);
@@ -126,22 +139,24 @@
126139

127140
%% Test: Open source by ID or name
128141
function [] = test_open_source( varargin )
129-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
130-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
131-
getTag = getBlock.open_tag(getBlock.tags{1,1}.id);
142+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
143+
getBlock = test_file.createBlock('test', 'nixBlock');
144+
getSource = getBlock.create_source('test', 'nixSource');
145+
sourceName = 'nestedsource';
146+
createSource = getSource.create_source(sourceName, 'nixSource');
147+
position = [1.0 1.2 1.3 15.9];
148+
getTag = getBlock.create_tag('tagtest', 'nixTag', position);
149+
getTag.add_source(getSource.sources{1});
150+
151+
getSourceByID = getTag.open_source(createSource.id);
152+
assert(~isempty(getSourceByID));
132153

133-
%-- TODO: implement testfile with source referenced from a tag
134-
%getSourceByID = getTag.open_source(getTag.sources{1,1}.id);
135-
%assert(strcmp(getSourceByID.id, ''));
136-
disp('Test Tag: open source by ID ... TODO (proper testfile)');
137-
138-
%getSourceByName = getTag.open_source(getTag.sources{1,1}.name);
139-
%assert(strcmp(getSourceByName.id, ''));
140-
disp('Test Tag: open source by name ... TODO (proper testfile)');
154+
getSourceByName = getTag.open_source(sourceName);
155+
assert(~isempty(getSourceByName));
141156

142157
%-- test open non existing source
143-
getSource = getTag.open_source('I dont exist');
144-
assert(isempty(getSource));
158+
getNonSource = getTag.open_source('I dont exist');
159+
assert(isempty(getNonSource));
145160
end
146161

147162

@@ -168,19 +183,22 @@
168183

169184
%% Test: Open reference by ID or name
170185
function [] = test_open_reference( varargin )
171-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
172-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
173-
getTag = getBlock.open_tag(getBlock.tags{1,1}.id);
174-
175-
getRefByID = getTag.open_reference(getTag.references{1,1}.id);
176-
assert(strcmp(getRefByID.id, '75138768-edc3-482e-894d-301f1dd66f8d'));
186+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
187+
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
188+
tmp = getBlock.create_data_array('referenceTest', 'nixDataArray', 'double', [1 2]);
189+
position = [1.0 1.2 1.3 15.9];
190+
getTag = getBlock.create_tag('referenceTest', 'nixTag', position);
191+
getTag.add_reference(getBlock.dataArrays{1});
177192

193+
getRefByID = getTag.open_reference(getTag.references{1,1}.id);
194+
assert(~isempty(getRefByID));
195+
178196
getRefByName = getTag.open_reference(getTag.references{1,1}.name);
179-
assert(strcmp(getRefByName.id, '75138768-edc3-482e-894d-301f1dd66f8d'));
197+
assert(~isempty(getRefByName));
180198

181199
%-- test open non existing source
182-
getRef = getTag.open_reference('I dont exist');
183-
assert(isempty(getRef));
200+
getNonRef = getTag.open_reference('I dont exist');
201+
assert(isempty(getNonRef));
184202
end
185203

186204

0 commit comments

Comments
 (0)