Boost logo

Boost Users :

Subject: Re: [Boost-users] First attempt at using Boost::Test is a flop: the program ends with an exception related to std::string but I don't use any
From: Ted Byers (r.ted.byers_at_[hidden])
Date: 2012-05-21 06:40:54


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of John Reid
> Sent: May-21-12 4:48 AM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] First attempt at using Boost::Test is a flop:
the
> program ends with an exception related to std::string but I don't use any
>
>
>
> On 21/05/12 04:50, Ted Byers wrote:
> > Here is the full output from my program:
> >
> >
> >
> > $ ./decision.test.suite
> >
> > terminate called after throwing an instance of 'std::logic_error'
> >
> > what(): basic_string::_S_construct NULL not valid
> >
> > Aborted (core dumped)
> >
> >
> >
> > Now, all the code in this program is focussed on number crunching, so
> > none of it involves strings. I am guessing that I missed something in
> > setting up a test suite.
> >
>
> Just a guess but might it be trying to stream one of your objects to a
> std::ostream? Do your classes support this behaviour? I think the library
offers
> different macros, some of which will print values when the test fails,
others
> don't. Perhaps you can try those.
>
No, none support IO. But then, none have data to write out. They're
function objects, derived from one or the other of the function objects
defined in STL.

Actually, I found the culprit. I had assumed initially that all I'd needed
was defined in a single header:

#include <boost/test/unit_test.hpp>

But, I continued investigating after I posted here, and observed that in the
framework example it also had:

#include <boost/test/included/unit_test.hpp>

I added that to my file, and it still compiled, but what a difference at run
time. The program now runs to completion without an exception. What I
don't have in an explanation, or why I haven't found, yet, documentation
that says what headers are needed in what test scenarios.

I have learned, however, some of the limitations of the algorithms I use to
compute the moments of a distribution. There is a rather poor, but commonly
recommended algorithm that works only when the mean and standard deviation
are roughly the same order of magnitude. It fails miserably when the mean
is orders of magnitude greater (in absolute value than the standard
deviation. The usual two pass algorithm and the best single pass algorithm
also work well when the mean is many orders of magnitude greater than the
standard deviation; although, surprisingly the single pass algorithm is more
accurate than the two pass algorithm in this edge case. But none that I
have tried so far works when the standard deviation is orders of magnitude
greater than the mean. But perhaps in this edge case, it may be
statistically impossible to get an accurate estimate of the mean.

I also hit a limitation of BOOST_CHECK_CLOSE. In testing my code to
check the accuracy of the algorithm for the standard normalized normal
distribution, of zero mean and unit variance, it always failed, giving an
infinite percent accuracy. Changing the distribution to mean of one and
variance of one resulted in the test passing. Clearly the incorrect result
of a failed test was due to a division by zero, and thus BOOST_CHECK_CLOSE
clearly can not compare a double with 0.0, and that strikes me as a
significant limitation. It is true that for my purposes, simply shifting
the distribution to the right by one meets my needs, I can imagine cases in
which that is not viable. Is there another macro that is specialized for
the case when the expected outcome, for a double, of a given calculation is
zero?

Thanks again.

Cheers

Ted


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net