• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

compare_full.cc

00001 // Copyright (C) 2007, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #include <mln/core/image/image1d.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/core/image/image3d.hh>
00029 
00030 #include <mln/value/int_u8.hh>
00031 #include <mln/value/int_u16.hh>
00032 #include <mln/value/int_s8.hh>
00033 #include <mln/value/int_s16.hh>
00034 
00035 #include <mln/data/compare.hh>
00036 
00037 #include <mln/debug/iota.hh>
00038 #include <mln/arith/plus.hh>
00039 #include <mln/arith/minus.hh>
00040 
00041 
00042 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00043 {
00044   f_box1d_t(const mln::box1d& b)
00045     : b_(b)
00046   {
00047   }
00048   mln::box1d b_;
00049   bool operator()(const mln::point1d& p) const
00050   {
00051     return b_.has(p);
00052   }
00053 };
00054 
00055 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00056 {
00057   f_box2d_t(const mln::box2d& b)
00058     : b_(b)
00059   {
00060   }
00061   mln::box2d b_;
00062   bool operator()(const mln::point2d& p) const
00063   {
00064     return b_.has(p);
00065   }
00066 };
00067 
00068 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00069 {
00070   f_box3d_t(const mln::box3d& b)
00071     : b_(b)
00072   {
00073   }
00074   mln::box3d b_;
00075   bool operator()(const mln::point3d& p) const
00076   {
00077     return b_.has(p);
00078   }
00079 };
00080 
00081 
00082 namespace mln
00083 {
00084   template<typename I, typename J>
00085   void
00086   test_less(I& lhs, J& rhs)
00087   {
00088     mln_assertion(! (lhs == rhs));
00089     mln_assertion(  (lhs <= rhs));
00090     mln_assertion(  (lhs <  rhs));
00091     mln_assertion(! (lhs >= rhs));
00092     mln_assertion(! (lhs >  rhs));
00093 
00094     mln_assertion(! (rhs == lhs));
00095     mln_assertion(! (rhs <= lhs));
00096     mln_assertion(! (rhs <  lhs));
00097     mln_assertion(  (rhs >= lhs));
00098     mln_assertion(  (rhs >  lhs));
00099   }
00100 
00101   template<typename I, typename J>
00102   void
00103   test_more(I& lhs, J& rhs)
00104   {
00105     mln_assertion(! (lhs == rhs));
00106     mln_assertion(  (lhs <= rhs));
00107     mln_assertion(  (lhs <  rhs));
00108     mln_assertion(! (lhs >= rhs));
00109     mln_assertion(! (lhs >  rhs));
00110 
00111     mln_assertion(! (rhs == lhs));
00112     mln_assertion(! (rhs <= lhs));
00113     mln_assertion(! (rhs <  lhs));
00114     mln_assertion(  (rhs >= lhs));
00115     mln_assertion(  (rhs >  lhs));
00116   }
00117 
00118   template<typename I, typename J>
00119   void
00120   test_equal(I& lhs, J& rhs)
00121   {
00122     mln_assertion(  (lhs == rhs));
00123     mln_assertion(  (lhs <= rhs));
00124     mln_assertion(! (lhs <  rhs));
00125     mln_assertion(  (lhs >= rhs));
00126     mln_assertion(! (lhs >  rhs));
00127 
00128     mln_assertion(  (rhs == lhs));
00129     mln_assertion(  (rhs <= lhs));
00130     mln_assertion(! (rhs <  lhs));
00131     mln_assertion(  (rhs >= lhs));
00132     mln_assertion(! (rhs >  lhs));
00133   }
00134 
00135   template <typename I>
00136   void
00137   chk1d(unsigned cols)
00138   {
00139     image1d<I> lhs (cols);
00140     image1d<I> rhs (cols);
00141     debug::iota (lhs);
00142     debug::iota (rhs);
00143 
00144     test_equal(lhs, rhs);
00145     image1d<int> lhs2 = lhs + 0;
00146     image1d<int> rhs2 = rhs + 1;
00147     test_less(lhs2, rhs2);
00148     image1d<int> lhs3 = lhs - 1;
00149     image1d<int> rhs3 = rhs + 0;
00150     test_more(lhs3, rhs3);
00151   }
00152 
00153   template <typename I>
00154   void
00155   chk2d(unsigned rows, unsigned cols)
00156   {
00157     image2d<I> lhs (rows, cols);
00158     image2d<I> rhs (rows, cols);
00159     debug::iota (lhs);
00160     debug::iota (rhs);
00161 
00162     test_equal(lhs, rhs);
00163     image2d<int> lhs2 = lhs + 0;
00164     image2d<int> rhs2 = rhs + 1;
00165     test_less(lhs2, rhs2);
00166     image2d<int> lhs3 = lhs - 1;
00167     image2d<int> rhs3 = rhs + 0;
00168     test_more(lhs3, rhs3);
00169   }
00170 
00171   template <typename I>
00172   void
00173   chk3d(unsigned slis, unsigned rows, unsigned cols)
00174   {
00175     image3d<I> lhs (slis, rows, cols);
00176     image3d<I> rhs (slis, rows, cols);
00177     debug::iota (lhs);
00178     debug::iota (rhs);
00179 
00180     test_equal(lhs, rhs);
00181     image3d<int> lhs2 = lhs + 0;
00182     image3d<int> rhs2 = rhs + 1;
00183     test_less(lhs2, rhs2);
00184     image3d<int> lhs3 = lhs - 1;
00185     image3d<int> rhs3 = rhs + 0;
00186     test_more(lhs3, rhs3);
00187   }
00188 }
00189 
00190 
00191 
00192 
00193 int main()
00194 {
00195   using namespace mln;
00196 
00197   unsigned slis_start = 1;
00198   unsigned slis_end   = 3;
00199 
00200   unsigned rows_start = 1;
00201   unsigned rows_end   = 16;
00202 
00203   unsigned cols_start = 1;
00204   unsigned cols_end = 32;
00205 
00206   std::cerr << "Tests data::compare" << std::endl;
00207 
00208   (std::cerr << "in 1d ... ").flush ();
00209   {
00210     for (unsigned i = cols_start; i < cols_end; ++i)
00211       {
00212         chk1d<int>(i);
00213         chk1d<unsigned>(i);
00214         chk1d<value::int_u8>(i);
00215         chk1d<value::int_u16>(i);
00216         chk1d<value::int_s8>(i);
00217         chk1d<value::int_s16>(i);
00218       }
00219   }
00220   std::cerr << "OK" << std::endl;
00221 
00222   (std::cerr << "in 2d ... ").flush ();
00223   {
00224     for (unsigned j = rows_start; j < rows_end; ++j)
00225       for (unsigned i = cols_start; i < cols_end; ++i)
00226         {
00227           chk2d<int>(j, i);
00228           chk2d<unsigned>(j, i);
00229           chk2d<value::int_u8>(j, i);
00230           chk2d<value::int_u16>(j, i);
00231           chk2d<value::int_s8>(j, i);
00232           chk2d<value::int_s16>(j, i);
00233         }
00234   }
00235   std::cerr << "OK" << std::endl;
00236 
00237   (std::cerr << "in 3d ... ").flush ();
00238   {
00239     for (unsigned k = slis_start; k < slis_end; ++k)
00240       for (unsigned j = rows_start; j < rows_end; ++j)
00241         for (unsigned i = cols_start; i < cols_end; ++i)
00242           {
00243             chk3d<int>(k, j, i);
00244             chk3d<unsigned>(k, j, i);
00245             chk3d<value::int_u8>(k, j, i);
00246             chk3d<value::int_u16>(k, j, i);
00247             chk3d<value::int_s8>(k, j, i);
00248             chk3d<value::int_s16>(k, j, i);
00249           }
00250   }
00251   std::cerr << "OK" << std::endl;
00252 }

Generated on Tue Oct 4 2011 15:23:37 for Milena (Olena) by  doxygen 1.7.1