3431: Make test::predicate more robust.

* mln/test/predicate.hh: add predicate_tests() function and call it in test::impl::* functions. Fix a wrong pixter type. --- milena/ChangeLog | 8 ++++ milena/mln/test/predicate.hh | 96 +++++++++++++++++++++++++++++++---------- 2 files changed, 80 insertions(+), 24 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 6f46274..85e2329 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,13 @@ 2009-02-27 Guillaume Lazzara <z@lrde.epita.fr> + Make test::predicate more robust. + + * mln/test/predicate.hh: add predicate_tests() function and call it + in test::impl::* functions. + Fix a wrong pixter type. + +2009-02-27 Guillaume Lazzara <z@lrde.epita.fr> + Small fixes for doc generation. * doc/Doxyfile.in: add doc/tutorial/img to IMAGE_PATH. diff --git a/milena/mln/test/predicate.hh b/milena/mln/test/predicate.hh index f2f44e3..2949490 100644 --- a/milena/mln/test/predicate.hh +++ b/milena/mln/test/predicate.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory // (LRDE) // // This file is part of the Olena Library. This library is free @@ -44,38 +44,77 @@ namespace mln namespace test { - /*! Test if all pixel values of \p ima verify the predicate \p - * f. - * - * \param[in] ima The image. - * \param[in] f The predicate. - */ + /// Test if all pixel values of \p ima verify the predicate \p + /// f. + /// + /// \param[in] ima The image. + /// \param[in] f The predicate. template <typename I, typename F> bool predicate(const Image<I>& ima, const Function_v2b<F>& f); - /*! Test if all pixel values of \p lhs and \p rhs verify the - * predicate \p f. - * - * \param[in] lhs The image. - * \param[in] rhs The image. - * \param[in] f The predicate. - */ + /// Test if all pixel values of \p lhs and \p rhs verify the + /// predicate \p f. + /// + /// \param[in] lhs The image. + /// \param[in] rhs The image. + /// \param[in] f The predicate. template <typename I, typename J, typename F> bool predicate(const Image<I>& lhs, const Image<J>& rhs, const Function_vv2b<F>& f); - /*! Test if all points of \p pset verify the predicate \p f. - * - * \param[in] pset The point set. - * \param[in] f The predicate. - */ + /// Test if all points of \p pset verify the predicate \p f. + /// + /// \param[in] pset The point set. + /// \param[in] f The predicate. template <typename S, typename F> bool predicate(const Site_Set<S>& pset, const Function_p2b<F>& f); # ifndef MLN_INCLUDE_ONLY + namespace internal + { + + template <typename I, typename F> + inline + void predicate_tests(const Image<I>& ima, + const Function_v2b<F>& f) + { + mln_precondition(exact(ima).is_valid()); + (void) ima; + (void) f; + } + + template <typename I, typename J, typename F> + inline + void predicate_tests(const Image<I>& lhs_, + const Image<J>& rhs_, + const Function_vv2b<F>& f) + { + const I& lhs = exact(lhs_); + const J& rhs = exact(rhs_); + + mln_precondition(lhs.is_valid()); + mln_precondition(rhs.is_valid()); + mln_precondition(lhs.domain() == rhs.domain()); + (void) lhs; + (void) rhs; + (void) f; + } + + template <typename S, typename F> + inline + void predicate_tests(const Site_Set<S>& pset, + const Function_p2b<F>& f) + { + mln_precondition(exact(pset).is_valid()); + (void) pset; + (void) f; + } + + } // end of namespace mln::test::internal + namespace impl { @@ -83,6 +122,8 @@ namespace mln inline bool predicate_(trait::image::speed::any, const I& ima, const F& f) { + internal::predicate_tests(ima, f); + mln_piter(I) p(ima.domain()); for_all(p) if (! f(ima(p))) @@ -94,6 +135,8 @@ namespace mln inline bool predicate_(trait::image::speed::fastest, const I& ima, const F& f) { + internal::predicate_tests(ima, f); + mln_pixter(const I) pxl(ima); for_all(pxl) if (! f(pxl.val())) @@ -107,6 +150,8 @@ namespace mln trait::image::speed::any, const I& lhs, const J& rhs, const F& f) { + internal::predicate_tests(lhs, rhs, f); + mln_piter(I) p(lhs.domain()); for_all(p) if (! f(lhs(p), rhs(p))) @@ -120,8 +165,10 @@ namespace mln trait::image::speed::fastest, const I& lhs, const J& rhs, const F& f) { + internal::predicate_tests(lhs, rhs, f); + mln_pixter(const I) pxl1(lhs); - mln_pixter(const I) pxl2(rhs); + mln_pixter(const J) pxl2(rhs); for_all_2(pxl1, pxl2) if (! f(pxl1.val(), pxl2.val())) return false; @@ -132,6 +179,8 @@ namespace mln inline bool predicate_(const Site_Set<S>& pset, const F& f) { + internal::predicate_tests(pset, f); + mln_piter(S) p(exact(pset)); for_all(p) if (! f(p)) @@ -148,7 +197,7 @@ namespace mln inline bool predicate(const Image<I>& ima, const Function_v2b<F>& f) { - mln_precondition(exact(ima).is_valid()); + internal::predicate_tests(ima, f); return impl::predicate_(mln_trait_image_speed(I)(), exact(ima), exact(f)); } @@ -161,9 +210,7 @@ namespace mln const I& lhs = exact(lhs_); const J& rhs = exact(rhs_); - mln_precondition(lhs.is_valid()); - mln_precondition(rhs.is_valid()); - mln_precondition(lhs.domain() == rhs.domain()); + internal::predicate_tests(lhs_, rhs_, f); return impl::predicate_(mln_trait_image_speed(I)(), mln_trait_image_speed(J)(), @@ -175,6 +222,7 @@ namespace mln inline bool predicate(const Site_Set<S>& pset, const Function_p2b<F>& f) { + internal::predicate_tests(pset, f); return impl::predicate_(exact(pset), exact(f)); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara