Skip to content

Commit 65591fa

Browse files
committed
tests for dimensions added
1 parent 9a21715 commit 65591fa

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed

+nix/DataArray.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@
5555

5656
function dim = append_set_dimension(obj)
5757
func_name = strcat(obj.alias, '::append_set_dimension');
58-
dim = nix_mx(func_name, obj.nix_handle);
58+
dim = nix.SetDimension(nix_mx(func_name, obj.nix_handle));
5959
obj.dimsCache.lastUpdate = 0;
6060
end
6161

6262
function dim = append_sampled_dimension(obj, interval)
6363
func_name = strcat(obj.alias, '::append_sampled_dimension');
64-
dim = nix_mx(func_name, obj.nix_handle, interval);
64+
dim = nix.SampledDimension(nix_mx(func_name, obj.nix_handle, interval));
6565
obj.dimsCache.lastUpdate = 0;
6666
end
6767

6868
function dim = append_range_dimension(obj, ticks)
6969
func_name = strcat(obj.alias, '::append_range_dimension');
70-
dim = nix_mx(func_name, obj.nix_handle, ticks);
70+
dim = nix.RangeDimension(nix_mx(func_name, obj.nix_handle, ticks));
7171
obj.dimsCache.lastUpdate = 0;
7272
end
7373

+nix/Dynamic.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function set_method(obj, val)
2424
end
2525

2626
if (isempty(val))
27-
nix_mx(strcat(obj.alias, '::set_none_', prop), obj.nix_handle, val);
27+
nix_mx(strcat(obj.alias, '::set_none_', prop), obj.nix_handle, 0);
2828
else
2929
nix_mx(strcat(obj.alias, '::set_', prop), obj.nix_handle, val);
3030
end

nix_mx.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void mexFunction(int nlhs,
272272
.reg("set_none_label", SETTER(const boost::none_t, nix::SampledDimension, label))
273273
.reg("set_unit", SETTER(const std::string&, nix::SampledDimension, unit))
274274
.reg("set_none_unit", SETTER(const boost::none_t, nix::SampledDimension, unit))
275-
.reg("set_sampling", SETTER(double, nix::SampledDimension, samplingInterval))
275+
.reg("set_samplingInterval", SETTER(double, nix::SampledDimension, samplingInterval))
276276
.reg("set_offset", SETTER(double, nix::SampledDimension, offset))
277277
.reg("set_none_offset", SETTER(const boost::none_t, nix::SampledDimension, offset))
278278
.reg("index_of", &nix::SampledDimension::indexOf)

tests/RunTests.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
t8.tests = TestFeature();
3232
t9.name = 'PROPERTY';
3333
t9.tests = TestProperty();
34+
t10.name = 'DIMENSIONS';
35+
t10.tests = TestDimensions();
3436

3537
% concatenate all test handles
36-
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8, t9};
38+
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10};
3739

3840
for i = 1:length(all_tests)
3941
fprintf([10 'Execute ' all_tests{i}.name ' tests:\n\n']);

tests/TestDimensions.m

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
function funcs = TestDimensions
2+
%TestDimensions tests for Dimensions
3+
% Detailed explanation goes here
4+
5+
funcs = {};
6+
funcs{end+1} = @test_set_dimension;
7+
funcs{end+1} = @test_sample_dimension;
8+
funcs{end+1} = @test_range_dimension;
9+
end
10+
11+
function [] = test_set_dimension( varargin )
12+
%% Test: set dimension
13+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
14+
b = f.createBlock('daTestBlock', 'test nixBlock');
15+
da = b.create_data_array('daTest', 'test nixDataArray', 'double', [1 2]);
16+
d1 = da.append_set_dimension();
17+
18+
assert(strcmp(d1.dimensionType, 'set'));
19+
assert(isempty(d1.labels));
20+
21+
d1.labels = {'foo', 'bar'};
22+
assert(strcmp(d1.labels{1}, 'foo'));
23+
assert(strcmp(d1.labels{2}, 'bar'));
24+
25+
% fix this in NIX
26+
%d1.labels = {};
27+
%assert(isempty(d1.labels));
28+
end
29+
30+
function [] = test_sample_dimension( varargin )
31+
%% Test: sampled dimension
32+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
33+
b = f.createBlock('daTestBlock', 'test nixBlock');
34+
da = b.create_data_array('daTest', 'test nixDataArray', 'double', [1 2]);
35+
d1 = da.append_sampled_dimension(200);
36+
37+
assert(strcmp(d1.dimensionType, 'sample'));
38+
assert(isempty(d1.label));
39+
assert(isempty(d1.unit));
40+
assert(d1.samplingInterval == 200);
41+
assert(isempty(d1.offset));
42+
43+
d1.label = 'foo';
44+
d1.unit = 'mV';
45+
d1.samplingInterval = 325;
46+
d1.offset = 500;
47+
48+
assert(strcmp(d1.label, 'foo'));
49+
assert(strcmp(d1.unit, 'mV'));
50+
assert(d1.samplingInterval == 325);
51+
assert(d1.offset == 500);
52+
53+
d1.label = '';
54+
d1.unit = '';
55+
d1.offset = 0;
56+
57+
assert(isempty(d1.label));
58+
assert(isempty(d1.unit));
59+
assert(d1.samplingInterval == 325);
60+
assert(d1.offset == 0);
61+
end
62+
63+
function [] = test_range_dimension( varargin )
64+
%% Test: range dimension
65+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
66+
b = f.createBlock('daTestBlock', 'test nixBlock');
67+
da = b.create_data_array('daTest', 'test nixDataArray', 'double', [1 2]);
68+
ticks = [1 2 3 4];
69+
d1 = da.append_range_dimension(ticks);
70+
71+
assert(strcmp(d1.dimensionType, 'range'));
72+
assert(isempty(d1.label));
73+
assert(isempty(d1.unit));
74+
assert(isequal(d1.ticks, ticks));
75+
76+
new_ticks = [5 6 7 8];
77+
d1.label = 'foo';
78+
d1.unit = 'mV';
79+
d1.ticks = new_ticks;
80+
81+
assert(strcmp(d1.label, 'foo'));
82+
assert(strcmp(d1.unit, 'mV'));
83+
assert(isequal(d1.ticks, new_ticks));
84+
85+
d1.label = '';
86+
d1.unit = '';
87+
88+
assert(isempty(d1.label));
89+
assert(isempty(d1.unit));
90+
end

0 commit comments

Comments
 (0)