Skip to content

Commit

Permalink
add err_msg to assert
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Mar 6, 2018
1 parent 125e786 commit 26c1002
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions tests/Test.m
Expand Up @@ -24,10 +24,12 @@ function Test()
test_transforms('r',deg2rad(lat),deg2rad(lon), deg2rad(lat1),deg2rad(lon1), deg2rad(az), deg2rad(el))

function test_transforms(angleUnit,lat,lon,lat1,lon1,az,el)

angleUnit=char(angleUnit);

%% aer2ecef contains:
[x1,y1,z1] = geodetic2ecef(E,lat,lon,alt, angleUnit);
assert_allclose([x1,y1,z1],[x0,y0,z0])
assert_allclose([x1,y1,z1],[x0,y0,z0],[],[],['geodetic2ecef: ',angleUnit])

[e1,n1,u1] = aer2enu(az, el, srange, angleUnit);
assert_allclose([e1,n1,u1], [er,nr,ur])
Expand Down Expand Up @@ -66,7 +68,7 @@ function test_transforms(angleUnit,lat,lon,lat1,lon1,az,el)

end % function

disp('test complete')
disp('GNU Octave / Matlab code OK')
end


Expand Down
7 changes: 4 additions & 3 deletions tests/assert_allclose.m
@@ -1,4 +1,4 @@
function ok = assert_allclose(actual, desired, atol, rtol)
function ok = assert_allclose(actual, desired, atol, rtol, err_msg)
% ok = assert_allclose(actual, desired, atol, rtol)
%
% Inputs
Expand All @@ -16,7 +16,8 @@
%
% if "actual" is within atol OR rtol of "desired", no error is emitted.

if nargin < 4, rtol=1e-5; end
if nargin < 5, err_msg=''; end
if nargin < 4 || isempty(rtol), rtol=1e-5; end
if nargin < 3 || isempty(atol), atol=1e-8; end

assert(isscalar(rtol))
Expand All @@ -26,7 +27,7 @@
if maxerrmag > atol + rtol * abs(desired)
disp(['Actual: ',num2str(actual)])
disp([' desired: ',num2str(desired)])
error(['AssertionError: maximum error magnitude ',num2str(maxerrmag),' on ',int2str(i),'th value: ',num2str(actual(i)),' atol: ',num2str(atol),' rtol: ',num2str(rtol)])
error(['AssertionError: ',err_msg,' maximum error magnitude ',num2str(maxerrmag),' on ',int2str(i),'th value: ',num2str(actual(i)),' atol: ',num2str(atol),' rtol: ',num2str(rtol)])
end

end
Expand Down

0 comments on commit 26c1002

Please sign in to comment.