Skip to content

Commit 3f1387f

Browse files
committed
normalize: choose_method
1 parent 0532b05 commit 3f1387f

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

+stdlib/+java/normalize.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
end
1212
end
1313

14-
15-
16-
end
14+
end

+stdlib/normalize.m

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@
1111
%
1212
% MEX code is about 4-5x faster than plain Matlab below
1313

14-
function n = normalize(p)
14+
function n = normalize(file, method)
1515
arguments
16-
p {mustBeTextScalar}
16+
file {mustBeTextScalar}
17+
method (1,:) string = ["java", "python", "native"]
1718
end
1819

19-
if stdlib.has_java()
20-
n = stdlib.java.normalize(p);
21-
elseif stdlib.has_python()
22-
n = stdlib.python.normalize(p);
23-
else
24-
n = stdlib.native.normalize(p);
25-
end
26-
27-
end
20+
fun = choose_method(method, "normalize");
2821

22+
n = fun(file);
2923

30-
%!testif 0
24+
end

test/TestNormalize.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
properties (TestParameter)
44
p = init_norm()
55
d = init_drop_slash()
6-
norm_fun = {@stdlib.normalize, @stdlib.native.normalize, @stdlib.java.normalize, @stdlib.python.normalize}
6+
fun = {'native', 'java', 'python'}
77
end
88

99
methods(TestClassSetup)
@@ -15,10 +15,16 @@ function pkg_path(tc)
1515

1616
methods (Test, TestTags="pure")
1717

18-
function test_normalize(tc, p, norm_fun)
19-
is_capable(tc, norm_fun)
18+
function test_normalize(tc, p, fun)
19+
tc.assertNotEmpty(which("stdlib." + fun + ".normalize"))
20+
try
21+
c = stdlib.normalize(p{1}, fun);
22+
catch e
23+
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
24+
return
25+
end
2026

21-
tc.verifyEqual(norm_fun(p{1}), p{2}, ...
27+
tc.verifyEqual(c, p{2}, ...
2228
sprintf("normalize(%s) mex: %d", p{1}, stdlib.is_mex_fun("stdlib.normalize")))
2329
end
2430

0 commit comments

Comments
 (0)