You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Anton Pevtsov <an...@moscow.vdiweb.com> on 2006/01/16 17:10:34 UTC

test for lib.alg.search

The attached file (25.search.cpp) contains my attempt to update
lib.alg.search test and port it to new test driver.

During the update I have found that the realization of the search_n
algorithm assumes that the ++ operator exists for the Size type.
I think this is not correct because the Size type may be just an
intergal type and has no any operators defined for this type.
So, the algorithm.cc.diff file contains the patch to fix this problem in
the search_n implementation (the same problems were in the fill_n and
generate_n algorithms and I tried to update the search_n implementation
in the same way)

Here is the change log:

2006-01-16  Anton Pevtsov  <an...@moscow.vdiweb.com>

    * algorithm.cc (__search_n ) : fix bug with the type of __matches
    variable


With best wishes,
Anton Pevtsov

Re: test for lib.alg.search

Posted by Martin Sebor <se...@roguewave.com>.
Anton Pevtsov wrote:
> The attached file (25.search.cpp) contains my attempt to update
> lib.alg.search test and port it to new test driver.
> 
> During the update I have found that the realization of the search_n
> algorithm assumes that the ++ operator exists for the Size type.
> I think this is not correct because the Size type may be just an
> intergal type and has no any operators defined for this type.
> So, the algorithm.cc.diff file contains the patch to fix this problem in
> the search_n implementation (the same problems were in the fill_n and
> generate_n algorithms and I tried to update the search_n implementation
> in the same way)
> 
> Here is the change log:
> 
> 2006-01-16  Anton Pevtsov  <an...@moscow.vdiweb.com>
> 
>    * algorithm.cc (__search_n ) : fix bug with the type of __matches
>    variable

This is related to STDCXX-83 and STDCXX-84:
   http://issues.apache.org/jira/browse/STDCXX-83
   http://issues.apache.org/jira/browse/STDCXX-84

Could you please open an issue in Jira for this one as well,
just for the record? (Remember to link it to the two above).
I'll commit your patch once we have an issue to reference.

[...]
> // exercises std::search()
> template 
> <class ForwardIterator1, class ForwardIterator2, class T, class PredTag>
> void test_search (int line, 
>                   const char *seq1, const char *seq2, 
>                   std::size_t off, 
>                   ForwardIterator1 it1, ForwardIterator2 it2,
>                   const T* , PredTag pred_tag)
[...]
>     // 25.1.9, p2:
>     // check the returned iterator
>     rw_assert (result.cur_ == expected.cur_, 0, line, 
>                "std::%s<%s, %s%{?}, %s%{;}> (\"%s\", ..., \"%s\") "
>                "found subsequence at %td, expected at %d",
>                fname, it1name, it2name, pred_tag.pred_inx, predname,
>                seq1, seq2, result.cur_ - first1.cur_, 
>                off == std::size_t (-1) ? -1 : off);
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This expression seems needlessly complicated. In addition, it gives
warnings (e.g., EDG eccp warning #68-D: integer conversion resulted
in a change of sign).

How about something like this instead:

     rw_assert (result.cur_ == expected.cur_, 0, line,
                "std::%s<%s, %s%{?}, %s%{;}> (\"%s\", ..., \"%s\") "
                "found subsequence at %td, "
                "expected at %{?}end%{;}%zu%{;}",
                fname, it1name, it2name, pred_tag.pred_inx, predname,
                seq1, seq2, result.cur_ - first1.cur_,
                _RWSTD_SIZE_MAX == off, off);

[...]
 > template <class T, class PredTag>
 > void test_search(const T*, PredTag pred_tag)
 > {
 >     rw_info (0, 0, 0,
 >              "template <class %s, class %1$s%{?}, class %s%{;}> "
 >              "std::search (%1$s, %1$s, %1$s, %1$s%{?}, %s%{;})",
 >              "ForwardIterator", pred_tag.pred_inx, "BinaryPredicate",
 >              pred_tag.pred_inx, "BinaryPredicate");

Could this be simplified (i.e., avoid duplicating "BinaryPredicate")
like this:

     rw_info (0, 0, 0,
              "template <class %s, class %1$s%{?}, class %s%{;}> "
              "std::search (%1$s, %1$s, %1$s, %1$s%{?}, %3$s%{;})",
              "ForwardIterator", pred_tag.pred_inx, "BinaryPredicate",
              pred_tag.pred_inx);

Lastly, would it be possible to test both algorithms (std::search() as
well as std::search_n()) in the same function instead of duplicating
most of the code in two places?

Thanks
Martin