octave-maintainers
[Top][All Lists]
Advanced

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

Re: Matlab compatibility of assert


From: John W. Eaton
Subject: Re: Matlab compatibility of assert
Date: Tue, 24 Sep 2013 11:50:18 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12

On 09/24/2013 11:18 AM, Julien Bect wrote:

It seems to me that Octave's assert behaves almost exactly as Matlab's
assert when there are more than one argument and the second argument is
a string (interpreted as an error message).

I think there is still some abiguity in the behavior.  For example,
suppose I'm testing with

  assert (observed, "the value I expect")

and OBSERVED happens to be a logical value that is true.  Then instead
of failing because of mismatch, the assert succeeds.  And if OBSERVED
is false, I get "the value I expect" as an error message instead of
the usual error message about mismatched values.  Although it probably
doesn't happen often, I don't think this kind of inconsistency is good
behavior.

I see now that Matlab requires the condition to be a logical scalar
value, so we don't have trouble with other cases, just logical scalar.
So perhaps we are compatible, but at the expense of inconsistency for
the way we use assert in the Octave test suite.

Maybe we should implement the Matlab behavior in assert and use
test_assert or tassert, or something else for the Octave assert
functionality that we use in the test suite?  Then we could easily
make assert a built-in function and it would be somewhat faster too,
solving the initial performance concern.

We could leave the !%assert syntax alone, but have it call the new
test_assert function.

The built-in assert function could test for the Matlab style case and
perform that action, otherwise warn about deprecated usage and call
the new test_assert function.

jwe


reply via email to

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