Skip to content

Commit 0cc48f4

Browse files
committed
is_exe: use choose_method
1 parent 0e2fd37 commit 0cc48f4

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

+stdlib/+native/is_exe_legacy.m renamed to +stdlib/+legacy/is_exe.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function y = is_exe_legacy(file)
1+
function y = is_exe(file)
22

33
y = isfile(file);
44

+stdlib/is_exe.m

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
%
33
% false if not a file
44

5-
function y = is_exe(p)
5+
function y = is_exe(file, method)
66
arguments
7-
p {mustBeTextScalar}
7+
file {mustBeTextScalar}
8+
method (1,:) string = ["java", "python", "native", "legacy"]
89
end
910

10-
% Java or Python are like 100x faster than Matlab native
11-
if stdlib.has_java()
12-
y = stdlib.java.is_exe(p);
13-
elseif stdlib.has_python()
14-
y = stdlib.python.is_exe(p);
15-
else
16-
y = stdlib.native.is_exe(p);
17-
end
11+
% Java or Python ~ 100x faster than Matlab native
12+
fun = choose_method(method, "is_exe", 'R2025a');
13+
14+
y = fun(file);
1815

1916
end

test/TestIsExe.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{'', false}, ...
88
{"", false}
99
}
10-
fun = {@stdlib.is_exe, @stdlib.java.is_exe, @stdlib.python.is_exe, @stdlib.native.is_exe, @stdlib.native.is_exe_legacy}
10+
method = {'java', 'python', 'native', 'legacy'}
1111
end
1212

1313
methods(TestClassSetup)
@@ -19,26 +19,26 @@ function pkg_path(tc)
1919

2020
methods(Test, TestTags="impure")
2121

22-
function test_is_exe(tc, p, fun)
23-
is_capable(tc, fun)
22+
function test_is_exe(tc, p, method)
23+
is_capable(tc, str2func("stdlib." + method + ".is_exe"))
2424

25-
tc.verifyEqual(fun(p{1}), p{2})
25+
tc.verifyEqual(stdlib.is_exe(p{1}, method), p{2})
2626
end
2727

2828

29-
function test_is_exe_dir(tc, fun)
30-
is_capable(tc, fun)
29+
function test_is_exe_dir(tc, method)
30+
is_capable(tc, str2func("stdlib." + method + ".is_exe"))
3131

32-
tc.verifyFalse(fun('.'))
32+
tc.verifyFalse(stdlib.is_exe('.', method))
3333
end
3434

3535

36-
function test_matlab_exe(tc, fun)
37-
is_capable(tc, fun)
36+
function test_matlab_exe(tc, method)
37+
is_capable(tc, str2func("stdlib." + method + ".is_exe"))
3838

3939

4040
f = matlab_path();
41-
tc.verifyTrue(fun(f))
41+
tc.verifyTrue(stdlib.is_exe(f, method))
4242
end
4343

4444

0 commit comments

Comments
 (0)