octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting DejaGNU tests to Paul's test/assert infrastructure


From: David Bateman
Subject: Re: Converting DejaGNU tests to Paul's test/assert infrastructure
Date: Wed, 26 Oct 2005 16:33:46 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Paul Kienzle a écrit :


On Oct 26, 2005, at 5:22 AM, David Bateman wrote:


* The functions in the test scripts are converted to funtion handles and so things like fsolve("f", ....) won't work. Paul are the function handles really needed, or is there a way to get the same functionality in the test scripts without nested functions?


The problem is that the test function might blow away a function of the same name in the users environment. Instead I'm generating a unique name and returning a handle to that. The alternative is to find a way to create a function in a private namespace only, or to modify the name of the function so that it is guaranteed not to collide.

For now we can change the definition to use the function name directly, but build a 'private namespace' in the usual way by changing the function name to package_fn, or in this case, changing function a to function __test_a in the definition and use. Later when support is added for private functions those tests will continue to work without change.

- Paul

Paul,

Is it necessary to allow arbitrary contexts or namespaces to allow this in test.m? Maybe if we could imagine a symbol table "global_fbi_sym_tab", then something like

global f;
function y = f(x)
 y = sin(x);
endfunction
function y = g(x);
 global f;
 y = 2 * f (x);
endfunction
g(1)

would be sufficient. Alternatively if "top_level_fbi_sym_tab" and "curr_caller_fbi_sym_tab" existed then we might do the same with evalin. A further means might be a syntax like

function y = f (context, x)
y = evalin(context, 'g(x)');
endfunction
function y = g(x)
sin(x);
endfunction
context = save_context();
y = f(context,1);

which would require an octave_value to save the current context and that evalin was capable of using it. One thing that I see that is odd behaviour o octave while looking at this is the following

global f;
f = @sin;
function y = g(x)
global f;
y = f(x);
endfunction
g(1)
function y = f(x)
y = cos(x);
endfunction
f(1)
g(1)

which returns

ans = 1.6829
ans = 0.84147
ans = 1.6829

so the redefition of "f" as afunction works in fbi_sym_tab in the current context, but it doesn't alter the fact that its defined as a function handle in the global space. This is odd as in the above it is defined as global in the top-level context. So perhaps the first idea above needs to be done in any case to remove this little inconsistency...

Regards
David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]