Skip to content

Commit 0b90540

Browse files
committed
test: correct logic
1 parent 320af4d commit 0b90540

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

+stdlib/ram_free.m

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
function bytes = ram_free()
1313

14+
bytes = 0;
15+
1416
try
1517
% memory() was added cross-platform to Octave ~ 2021.
1618
% Matlab memory() at least through R2025a is still Windows only.
@@ -22,17 +24,7 @@
2224
switch e.identifier
2325
case {'MATLAB:memory:unsupported', 'Octave:undefined-function'}
2426
if stdlib.has_java()
25-
b = javaMethod("getOperatingSystemMXBean", "java.lang.management.ManagementFactory");
26-
27-
if stdlib.java_api() < 14
28-
bytes = b.getFreePhysicalMemorySize();
29-
else
30-
bytes = b.getFreeMemorySize();
31-
end
32-
else
33-
34-
bytes = 0;
35-
27+
bytes = ram_free_java();
3628
end
3729
otherwise, rethrow(e)
3830
end
@@ -42,4 +34,17 @@
4234

4335
end
4436

45-
%!assert(ram_free()>0)
37+
38+
function bytes = ram_free_java()
39+
40+
b = javaMethod("getOperatingSystemMXBean", "java.lang.management.ManagementFactory");
41+
42+
if stdlib.java_api() < 14
43+
bytes = b.getFreePhysicalMemorySize();
44+
else
45+
bytes = b.getFreeMemorySize();
46+
end
47+
48+
end
49+
50+
%!assert(ram_free() > 0)

+stdlib/ram_total.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
bytes = uint64(bytes);
3232

33-
3433
end
3534

3635

.github/workflows/ci-nojvm.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ jobs:
3535

3636
- uses: ./.github/workflows/composite-install-matlab
3737

38+
- name: Matlab tell External Language Interface versions
39+
uses: matlab-actions/run-command@v2
40+
with:
41+
command: stdlib.platform_tell()
42+
3843
- name: Fortran FC
3944
if: runner.os == 'macOS'
4045
run: echo "FC=gfortran-14" >> $GITHUB_ENV

test/TestSys.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ function test_ram_free(tc)
8787
f = stdlib.ram_free();
8888
tc.verifyGreaterThan(f, 0)
8989
tc.verifyClass(f, 'uint64')
90+
end
91+
92+
function test_ram_free_vs_total(tc)
93+
t = stdlib.ram_total();
94+
tc.assumeGreaterThan(t, 0)
95+
f = stdlib.ram_free();
96+
tc.assumeGreaterThan(f, 0)
9097

91-
tc.verifyLessThanOrEqual(f, stdlib.ram_total(), ...
92-
"Free RAM should be less than or equal to total RAM")
98+
tc.verifyLessThanOrEqual(f, t, "Free RAM should be less than or equal to total RAM")
9399
end
94100

95101
end

0 commit comments

Comments
 (0)