1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
function test_jsonlab(testname, fhandle, input, expected, varargin)
res = fhandle('', input, varargin{:});
if (~isequal(strtrim(res), expected))
warning('Test %s: failed: expected ''%s'', obtained ''%s''', testname, expected, res);
else
fprintf(1, 'Testing %s: ok\n\toutput:''%s''\n', testname, strtrim(res));
if (regexp(res, '^[\[\{A-Za-z]'))
handleinfo = functions(fhandle);
loadfunname = regexprep(handleinfo.function, '^save', 'load');
loadfun = str2func(loadfunname);
if (strcmp(loadfunname, 'loadbj'))
newres = loadfun(fhandle('', input, varargin{:}, 'debug', 0), varargin{:});
else
newres = loadfun(res, varargin{:});
end
if (exist('isequaln'))
try
if (isequaln(newres, input))
fprintf(1, '\t%s successfully restored the input\n', loadfunname);
end
catch
end
else
try
if (newres == input)
fprintf(1, '\t%s successfully restored the input\n', loadfunname);
end
catch
end
end
end
end
|