Skip to content

Commit

Permalink
Matlab use test class
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Oct 11, 2021
1 parent 7114538 commit 5d01a90
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
28 changes: 28 additions & 0 deletions +igrf/TestUnit.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef TestUnit < matlab.unittest.TestCase

methods(TestMethodSetup)

function tset(tc)
cwd = fileparts(mfilename('fullpath'));
run(fullfile(cwd, '../setup.m'))
end
end

methods (Test)

function test_basic(tc)

%% basic
mag = igrf.igrf(datetime(2010,7,2), 65, 85, 0);

tc.verifyEqual(mag.north, 9295.415460, "RelTol", 0.001, 'north error')
tc.verifyEqual(mag.east, 2559.7889298, "RelTol", 0.001, 'east error')
tc.verifyEqual(mag.down, 59670.379598, "RelTol", 0.001, 'down error')
tc.verifyEqual(mag.total, 60444.284008, "RelTol", 0.001, 'total error')

tc.verifyEqual(mag.incl, 80.821575, "RelTol", 0.001, 'inclination error')
tc.verifyEqual(mag.decl, 15.396590, "RelTol", 0.001, 'declination error')

end
end
end
13 changes: 0 additions & 13 deletions +igrf/igrf.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,3 @@
B.decl = xarray2mat(dat{'decl'});

end


function M = xarray2mat(V)
% M = double(py.numpy.asfortranarray(V));
V = V.values;
S = V.shape;
V = cell2mat(cell(V.ravel('F').tolist()));
if length(S) == 1
M = V(1);
else
M = reshape(V,[int64(S{1}), int64(S{2})]);
end
end
11 changes: 11 additions & 0 deletions +igrf/private/xarray2mat.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function M = xarray2mat(V)
% M = double(py.numpy.asfortranarray(V));
V = V.values;
S = V.shape;
V = cell2mat(cell(V.ravel('F').tolist()));
if length(S) == 1
M = V(1);
else
M = reshape(V,[int64(S{1}), int64(S{2})]);
end
end
13 changes: 0 additions & 13 deletions +igrf/test_unit.m

This file was deleted.

2 changes: 2 additions & 0 deletions setup.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% this puts Python DLLs on Matlab shell path.

cwd = fileparts(mfilename('fullpath'));
addpath(cwd)

Expand Down

0 comments on commit 5d01a90

Please sign in to comment.