Skip to content

Commit 20dc256

Browse files
committed
add write values tests
1 parent cd2cbbd commit 20dc256

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

tests/TestProperty.m

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
funcs = {};
66
funcs{end+1} = @test_attrs;
7+
funcs{end+1} = @test_update_values;
78
funcs{end+1} = @test_values;
89
end
910

@@ -42,17 +43,39 @@
4243

4344
%% Test: Access values
4445
function [] = test_values( varargin )
45-
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
46-
trial = f.sections{2}.sections{2}.sections{1};
47-
currProp = trial.open_property(trial.allProperties{1}.id);
46+
f = nix.File(fullfile(pwd,'tests','testRW.h5'), nix.FileMode.Overwrite);
47+
s = f.createSection('mainSection', 'nixSection');
48+
currProp = s.create_property_with_value('booleanProperty', {true, false, true});
4849

49-
assert(size(currProp.values, 1) == 1);
50-
assert(currProp.values{1}.value == 1);
50+
assert(size(currProp.values, 1) == 3);
51+
assert(currProp.values{1}.value);
5152
assert(currProp.values{1}.uncertainty == 0);
5253
assert(isempty(currProp.values{1}.checksum));
5354
assert(isempty(currProp.values{1}.encoder));
5455
assert(isempty(currProp.values{1}.filename));
5556
assert(isempty(currProp.values{1}.reference));
56-
57-
disp('Test Property: access values ... TODO (multiple property values)');
57+
end
58+
59+
%% Test: Update values
60+
function [] = test_update_values( varargin )
61+
f = nix.File(fullfile(pwd,'tests','testRW.h5'), nix.FileMode.Overwrite);
62+
s = f.createSection('mainSection', 'nixSection');
63+
64+
%-- test update boolean
65+
updateBool = s.create_property_with_value('booleanProperty', {true, false, true});
66+
assert(updateBool.values{1}.value);
67+
updateBool.values{1}.value = false;
68+
assert(~updateBool.values{1}.value);
69+
70+
%-- test update string
71+
updateString = s.create_property_with_value('stringProperty', {'this', 'has', 'strings'});
72+
assert(strcmp(updateString.values{3}.value, 'strings'));
73+
updateString.values{3}.value = 'more strings';
74+
assert(strcmp(updateString.values{3}.value, 'more strings'));
75+
76+
%-- test update double
77+
updateDouble = s.create_property_with_value('doubleProperty', {2, 3, 4, 5});
78+
assert(updateDouble.values{1}.value == 2);
79+
updateDouble.values{1}.value = 2.2;
80+
assert(updateDouble.values{1}.value == 2.2);
5881
end

0 commit comments

Comments
 (0)