Skip to content

Commit a9a1a35

Browse files
committed
[h5,nc]exists: improve validation, speed test
1 parent 96cd631 commit a9a1a35

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

+stdlib/+hdf5nc/h5exists.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
arguments
1313
file (1,1) string {mustBeFile}
14-
vars (1,:) string {mustBeNonempty,mustBeNonzeroLengthText}
14+
vars string
1515
end
1616

1717
i = startsWith(vars, "/");

+stdlib/+hdf5nc/ncexists.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
arguments
1313
file (1,1) string {mustBeFile}
14-
vars (1,:) string {mustBeNonempty,mustBeNonzeroLengthText}
14+
vars string
1515
end
1616

1717
% NOT contains because we want exact string match

+stdlib/+test/TestHDF5.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
type = {'single', 'double', 'float32', 'float64', ...
99
'int8', 'int16', 'int32', 'int64', ...
1010
'uint8', 'uint16', 'uint32', 'uint64'}
11-
vars = {'A0', 'A1', 'A2', 'A3', 'A4'}
1211
str = {"string", 'char'}
1312
end
1413

@@ -102,16 +101,25 @@ function test_get_variables(tc)
102101
end
103102

104103

105-
function test_exists(tc, vars)
104+
function test_exists(tc)
106105
import stdlib.hdf5nc.h5exists
107106
basic = tc.TestData.basic;
108107

109-
e = h5exists(basic, "/" + vars);
108+
tc.verifyEmpty(h5exists(basic, string.empty))
109+
110+
e = h5exists(basic, "");
111+
110112
tc.verifyTrue(isscalar(e))
111-
tc.verifyTrue(e)
113+
tc.verifyFalse(e)
114+
115+
vars = {'A0', 'A1', 'A2', 'A3', 'A4', '/A0'};
116+
117+
e = h5exists(basic, vars);
118+
tc.verifyTrue(isvector(e))
119+
tc.verifyTrue(all(e))
112120

113121
% vector
114-
e = h5exists(basic, [vars, "oops"]);
122+
e = h5exists(basic, ["/A1", "oops"]);
115123
tc.verifyTrue(isrow(e))
116124
tc.verifyEqual(e, [true, false])
117125
end

+stdlib/+test/TestNetCDF.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
type = {'single', 'double', 'float32', 'float64', ...
99
'int8', 'int16', 'int32', 'int64', ...
1010
'uint8', 'uint16', 'uint32', 'uint64'}
11-
vars = {'A0', 'A1', 'A2', 'A3', 'A4'}
1211
end
1312

1413

@@ -93,20 +92,23 @@ function test_get_variables(tc)
9392
end
9493

9594

96-
function test_exists(tc, vars)
95+
function test_exists(tc)
9796
import stdlib.hdf5nc.ncexists
98-
import matlab.unittest.constraints.IsScalar
9997
basic = tc.TestData.basic;
10098

101-
e = ncexists(basic, vars);
102-
tc.verifyThat(e, IsScalar)
103-
tc.verifyTrue(e)
99+
tc.verifyEmpty(ncexists(basic, string.empty))
100+
101+
e = ncexists(basic, "");
102+
103+
tc.verifyTrue(isscalar(e))
104+
tc.verifyFalse(e)
104105

105-
% vector
106-
e = ncexists(basic, [vars, "oops"]);
107-
tc.verifyTrue(isrow(e))
106+
e = ncexists(basic, ["A1", "oops"]);
107+
tc.verifyTrue(isvector(e))
108108
tc.verifyEqual(e, [true, false])
109109

110+
e = ncexists(basic, {'A0', 'A1', 'A2', 'A3', 'A4'});
111+
tc.verifyTrue(all(e))
110112
end
111113

112114

0 commit comments

Comments
 (0)