Skip to content

Commit b5bca51

Browse files
committed
Merge pull request #31 from haoxingz/formal_test
"test.py" rewritten under nosetests framework
2 parents 0941de8 + 894d9ee commit b5bca51

File tree

14 files changed

+223
-22
lines changed

14 files changed

+223
-22
lines changed

pymatbridge/matlab/functions/json2mat.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
%
88
% Jonas Almeida, March 2010
99

10+
format long; % Avoid decimal digits loss
11+
1012
if exist(J)==2 % if J is a filename
1113
fid=fopen(J,'r');
1214
J='';

pymatbridge/matlab/functions/mat2json.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
%
1515
% Jonas Almeida, March 2010
1616

17+
PRECISION = 10; % Keep a maximum of 10 decimal digits
18+
1719
switch class(M)
1820
case 'struct'
1921
J='{';
@@ -36,7 +38,7 @@
3638
otherwise
3739
if isnumeric(M) % notice looseness in not converting single numbers into arrays
3840
if length(M(:))==1
39-
J=num2str(M);
41+
J=num2str(M, PRECISION);
4042
else
4143
s=size(M);
4244
if (length(s)==2)&(s(1)<2) % horizontal or null vector

pymatbridge/matlab/webserver.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@
237237
switch(ext)%FOLDUP
238238
case {'.m'}
239239
fhandle = str2func(name);
240-
try
241-
html=feval(fhandle,request,config);
242-
catch ME
243-
html=['<html><body><font color="#FF0000">Error in file : ' name ...
240+
try
241+
html=feval(fhandle,request,config);
242+
catch ME
243+
html=['<html><body><font color="#FF0000">Error in file : ' name ...
244244
'.m</font><br><br><font color="#990000"> The file returned the following error: <br>' ...
245-
ME.message '</font></body></html>'];
246-
fprintf(ME.message);
247-
log_it(config,'error','file returned error %s',ME.message);
245+
ME.message '</font></body></html>'];
246+
fprintf(ME.message);
247+
log_it(config,'error','file returned error %s',ME.message);
248248
end
249249
header=make_html_http_header(html,found);
250250
response=header2text(header);

pymatbridge/matlab/www/demo_dict.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function [val1 val2 val3] = demo_dict(args)
2+
% Demonstration of passing Python dictionary variables around
3+
val1 = args.pDict(1).apple;
4+
val2 = args.pDict(1).pear;
5+
val3 = args.pDict(1).banana;
6+
7+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function res = test_precision_divide(args)
2+
% This function devides val1 by val2 and returns the result
3+
res = args.val1 / args.val2;
4+
5+
end %function
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function res = test_precision_multiply(args)
2+
% This function returns the product of two arguments val1 and val2
3+
res = args.val1 * args.val2;
4+
5+
end %function
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function res = test_precision_pass(args)
2+
% This function takes an argument val and simply return it
3+
4+
res = args.val;
5+
6+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function res = test_precision_sqrt(args)
2+
% This function returns the square root of the value
3+
res = sqrt(args.val);
4+
5+
end %function
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function res = test_precision_sum(args)
2+
% This function returns the sum of two arguments val1 and val2
3+
res = args.val1 + args.val2;
4+
5+
end %function

pymatbridge/matlab/www/web_feval.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
end
4040

4141
func_path = headers.Content.func_path;
42-
4342
if arguments_check
4443
arguments = json2mat(headers.Content.arguments);
4544
else

0 commit comments

Comments
 (0)