Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2007-03-16 12:40:42


"Pierre-Jules Tremblay" <iamtrep_at_[hidden]> wrote in message
news:4590bfef0703140534r2f8ac251j8827f6466dd626c5_at_mail.gmail.com...
>I understand.
>
> So I'm not sure I can build the tool I need with the existing tools.
> What I need to do is essentially compare two vector<float> objects of
> same size, element-by-element. I would be ok with using an absolute
> difference test in all cases (so that zero and non-zero comparison
> tests remain valid), however if I'm not mistaken my only choice is
> BOOST_CHECK_SMALL(a-b,tol) where a and b are corresponding elements of
> the two vectors. The downside of this approach is that if the test
> fails, only one value gets printed out, i.e. the result of the
> subtraction.
>
> Can you suggest a way to combine existing tools to get what I'm looking
> for?

You could write your own comparison predicate that is build on
boost::test_tools::check_is_small:

boost::test_tools::predicate_result
my_compare_coll( vector<float> const& v1, vector<float> const& v2, float
tol )
{
    boost::test_tools::predicate_result res;

    // compare sizes here

    // compare elem by elem
    // if ith elems mismatched produce an error
    // see equal_coll_impl( Left left_begin, Left left_end, Right
right_begin, Right right_end ) for example
    // atomic check is based on boost::test_tools::check_is_small
    // boost::test_tools::check_is_small( *v1_it - *v2_it, tol );

    return res;
}

Gennadiy


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