octave-maintainers
[Top][All Lists]
Advanced

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

Re: request for "assert"


From: Joseph P. Skudlarek
Subject: Re: request for "assert"
Date: Sat, 21 Apr 2001 07:58:16 -0700

Thanks for the reply, Paul.

Ah, I didn't explain myself very well.  Actually, I was thinking of
something even easier, an assert routine which takes a boolean value
(most likely generated by a conditional expression), and if the value is
not true, it simply errors out.

The version I'm using goes like this:

       ## -*- Mode: octave; indent-tabs-mode: nil fill-column: 72 -*- ##

    function assert(assertion)
      if (! assertion) 
        error("assertion failed");
      endif
    endfunction

    ##[]  

I use it in cases like this:

        ...
        bin_width_hz = 1/Ts / w;
        bin_3dB = 500e3 / bin_width_hz;
        assert(bin_3dB < r);
        ...

What you described I've seen MFC refer to as "AssertValid", rather than
just assert.  What I'm think of is more like "assert" from the C
library.

If assert were an Octave builtin, then it potentially could also state
the test of the conditional which failed, like I get from my C compiler:

        a.out: assert.c:5: main: Assertion `0 == 1' failed.

I hope this helps.  Thanks for helping to maintain a wonderful! tool.

/Jskud

>------ Begin Included Message ------
> Date: Sat, 21 Apr 2001 13:24:32 +0100
> To: "Joseph P. Skudlarek" <address@hidden>
> Cc: address@hidden
> Subject: Re: request for "assert"
> Content-Disposition: inline
> User-Agent: Mutt/1.2.5i
> From: Paul Kienzle <address@hidden>
> 
> I've got a version at:
> 
> http://users.powernet.co.uk/kienzle/octave/matcompat/scripts/testfun/assert.m
> 
> It recursively walks structure trees, but doesn't handle lists.  Feel free
> to extend it.
> 
> Ideally, each type should provide a comparator which determines if two
> instances of that type have the same value within some error bound so
> that assert would also work for user defined types.  Add an isequal
> method to the octave_value class?
> 
> Paul Kienzle
> address@hidden
> 
> On Fri, Apr 20, 2001 at 09:22:31PM -0700, Joseph P. Skudlarek wrote:
> > Hi.  An assert is a wonderful thing.  It's easy for a user to add, but
> > given the utility and the benefit, it might be better if it were built
> > in -- more people might use it.  So, how 'bout considering it?  Thanks.
> > /Jskud 
> > 
> > 
> 
>------  End Included Message  ------



reply via email to

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