File: test_char.m

package info (click to toggle)
mwrap 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,548 kB
  • sloc: cpp: 3,315; python: 1,850; ansic: 856; makefile: 258; lex: 233; sh: 145
file content (44 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
39
40
41
42
43
44
function test_char
% pass-fail test of the char- args and arrays.
% must do either make test_char_cpp or make test_char_c99 first.
% based on test_single.m, Barnett & Gimbutas 7/5/20-7/20/20.

tol = 2e-16;
tols = 1e-7;
%format long g  % for debug


%fprintf('scalar char routines...\n') % -------------------------------------
x = 1/3; ce = x+x; xs = single(x);

try
c = addchar(xs,xs);   % should error
catch ME
  assert(~isempty(strfind(ME.message,'Invalid scalar argument, mxCHAR_CLASS expected')))
end

a = '1'; b = '2'; ce = a+b;
c = addchar(a,b);
assert(norm(c-ce)<tol)
assert(strcmp(class(c),'double'))



if( 1 == 2 ),
%FIXME: not implemented in mwrap 1.2, only scalar char is supported

%fprintf('vector char routines...\n') % -------------------------------------
x = x*ones(3,1); ce=x+x; xf = single(x);

try
c = arraddchar(xf,xf);   % should error
catch ME
  assert(~isempty(strfind(ME.message,'Invalid array argument, mxCHAR_CLASS expected')));
end

a = '12'; b = '23'; ce = a+b;
c = vecaddchar(a,b);
assert(abs(c-ce)<tol)
assert(strcmp(class(c),'double'))

end