milena r1226: Add tests and clean gray values

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-03 Matthieu Garrigues <garrigues@lrde.epita.fr> Add tests and clean gray values. * mln/value/gray.hh, * mln/value/graylevel.hh: Clean useless operators. * tests/value_gray.cc: Add tests. * tests/value_int_u.cc: New, add tests. * tests/value_int_u8.cc: Add tests. --- mln/value/gray.hh | 12 ----- mln/value/graylevel.hh | 19 -------- tests/value_gray.cc | 2 tests/value_int_u.cc | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/value_int_u8.cc | 10 +--- 5 files changed, 110 insertions(+), 37 deletions(-) Index: trunk/milena/tests/value_int_u.cc =================================================================== --- trunk/milena/tests/value_int_u.cc (revision 0) +++ trunk/milena/tests/value_int_u.cc (revision 1226) @@ -0,0 +1,104 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/value_int_u8.cc + * + * \brief Tests on mln::value::int_u8. + */ + +#include <mln/value/int_u8.hh> +#include <mln/value/int_s8.hh> +#include <mln/value/int_u16.hh> +#include <mln/value/float01_8.hh> + +int main() +{ + using namespace mln; + using value::int_u8; + using value::int_s8; + using value::int_u16; + using value::float01_8; + + { + // Operations on int_u<n> + int_u8 i = 128; + int_u16 j = 42; + int_s8 k = 42; + float01_8 x; + + (j = j + i) = i + j; + assert(j == (128 + 42)); + + (k = j - i) = i - j; + assert(k == (-42)); + + j = 2; + (j = j * i) = i * j; + assert(j == (2 * 128)); + + (x = (j / i) / ((j / i) + 0.1)) + = (i / j) / ((i / j) + 0.1); + +// std::cout << i + i << std::endl; +// float01_8 f = i / 200.5; +// std::cout << x << std::endl; + } + + { + // Operations on int_u<n> and int / float + int_u16 j = 42; + int_s8 k = 42; + float x; + + // int + (k = j - 123) = 123 - j; + (j = j + 123) = 123 + j; + (j = j * 4) = 4 * j; + + (j = j / 4) = 4 / j; + + // float + x = (j / 4.5 * 3.4 + 3.5 - 5.6) / 0.0234; + } + + + { + // Operations on int_u<n> and float01_8 + int_u16 j = 42; + float01_8 x = 0.456; + + x = x / j; + assert(x < 0 && x < 1); + + x = x * j; + assert(x < 0 && x < 1); + + x = x * j; + assert(x < 0 && x < 1); + + } +} Index: trunk/milena/tests/value_gray.cc =================================================================== --- trunk/milena/tests/value_gray.cc (revision 1225) +++ trunk/milena/tests/value_gray.cc (revision 1226) @@ -41,4 +41,6 @@ c = (a * 2) / 2; assert(c == white); + + c = c / 6; } Index: trunk/milena/tests/value_int_u8.cc =================================================================== --- trunk/milena/tests/value_int_u8.cc (revision 1225) +++ trunk/milena/tests/value_int_u8.cc (revision 1226) @@ -31,13 +31,14 @@ */ #include <mln/value/int_u8.hh> - - +#include <mln/value/int_u16.hh> +#include <mln/value/float01_8.hh> int main() { using namespace mln; using value::int_u8; + using value::float01_8; { int_u8 i = 3; @@ -48,9 +49,4 @@ mln_assertion(-i == -2); mln_assertion(-3 * i == -6); } - - { - int_u8 i = 128; - std::cout << i + i << std::endl; - } } Index: trunk/milena/mln/value/graylevel.hh =================================================================== --- trunk/milena/mln/value/graylevel.hh (revision 1225) +++ trunk/milena/mln/value/graylevel.hh (revision 1226) @@ -71,15 +71,10 @@ /// Access to std type. enc value() const; - /// Op encoding_t. - operator enc() const; - /// Op<. bool operator<(const graylevel<n>& rhs) const; graylevel<n>& operator=(const int val); - /// Op==. - // bool operator==(const graylevel<n>& rhs) const; protected: enc val_; @@ -119,14 +114,6 @@ template <unsigned n, unsigned m> gray operator-(const graylevel<n>& lhs, const graylevel<m>& rhs); - template <unsigned n> - gray operator*(int s, const graylevel<n>& rhs); - - template <unsigned n> - gray operator*(const graylevel<n>& lhs, int s); - - template <unsigned n> - gray operator/(const graylevel<n>& lhs, int s); @@ -165,12 +152,6 @@ } template <unsigned n> - graylevel<n>::operator typename graylevel<n>::enc() const - { - return val_; - } - - template <unsigned n> bool graylevel<n>::operator<(const graylevel<n>& rhs) const { return val_ < rhs.val_; Index: trunk/milena/mln/value/gray.hh =================================================================== --- trunk/milena/mln/value/gray.hh (revision 1225) +++ trunk/milena/mln/value/gray.hh (revision 1226) @@ -142,13 +142,12 @@ template <unsigned N> gray operator/(const graylevel<N>& lhs, int s) { + std::cout << "div div " << s << std::endl; mln_precondition(s > 0); gray tmp(N, lhs.value() / s); return tmp; } - - // Gray. gray::gray() @@ -338,15 +337,6 @@ return tmp; } -// template <unsigned N> -// graylevel<N>& -// graylevel<N>::operator=(const gray& g) -// { -// mln_precondition(g.nbits() == N); -// assert(g.value() < internal::two_pow_(N)); -// this->val = g.value(); // FIXME: Add static_cast. -// } - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::value
participants (1)
-
Matthieu Garrigues