
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-12-04 Matthieu Garrigues <garrigues@lrde.epita.fr> Move the tests of mln/value. * tests/Makefile.am: Move the value tests... * tests/value/Makefile.am: ...here. * tests/value_bool.cc: Rename as... * tests/value/bool.cc: ...this. * tests/value_builtin.cc: Rename as... * tests/value/builtin.cc: ...this. * tests/value_equiv.cc: Rename as... * tests/value/equiv.cc: ...this. * tests/value_float01.cc: Rename as... * tests/value/float01.cc: ...this. * tests/value_float01_bis.cc: Rename as... * tests/value/float01_bis.cc: ...this. * tests/value_float01_f.cc: Rename as... * tests/value/float01_f.cc: ...this. * tests/value_graylevel.cc: Rename as... * tests/value/graylevel.cc: ...this. * tests/value_int_s.cc: Rename as... * tests/value/int_s.cc: ...this. * tests/value_int_s16.cc: Rename as... * tests/value/int_s16.cc: ...this. * tests/value_int_u8.cc: Rename as... * tests/value/int_u8.cc: ...this. * tests/value_interop.cc: Rename as... * tests/value/interop.cc: ...this. * tests/value_label.cc: Rename as... * tests/value/label.cc: ...this. * tests/value_quat.cc: Rename as... * tests/value/quat.cc: ...this. * tests/value_rgb8.cc: Rename as... * tests/value/rgb8.cc: ...this. * tests/value_scalar.cc: Rename as... * tests/value/scalar.cc: ...this. * tests/value_set.cc: Rename as... * tests/value/set.cc: ...this. --- Makefile.am | 27 --- value/Makefile.am | 41 +++++ value/bool.cc | 45 +++++ value/builtin.cc | 120 +++++++++++++++ value/equiv.cc | 58 +++++++ value/float01.cc | 150 +++++++++++++++++++ value/float01_bis.cc | 58 +++++++ value/float01_f.cc | 43 +++++ value/graylevel.cc | 396 +++++++++++++++++++++++++++++++++++++++++++++++++++ value/int_s.cc | 51 ++++++ value/int_s16.cc | 213 +++++++++++++++++++++++++++ value/int_u8.cc | 197 +++++++++++++++++++++++++ value/interop.cc | 114 ++++++++++++++ value/label.cc | 49 ++++++ value/quat.cc | 72 +++++++++ value/rgb8.cc | 71 +++++++++ value/scalar.cc | 94 ++++++++++++ value/set.cc | 65 ++++++++ 18 files changed, 1838 insertions(+), 26 deletions(-) Index: trunk/milena/tests/value_scalar.cc (deleted) =================================================================== Index: trunk/milena/tests/value_quat.cc (deleted) =================================================================== Index: trunk/milena/tests/value_interop.cc (deleted) =================================================================== Index: trunk/milena/tests/value_equiv.cc (deleted) =================================================================== Index: trunk/milena/tests/value_set.cc (deleted) =================================================================== Index: trunk/milena/tests/value_float01_bis.cc (deleted) =================================================================== Index: trunk/milena/tests/value_float01_f.cc (deleted) =================================================================== Index: trunk/milena/tests/value_builtin.cc (deleted) =================================================================== Index: trunk/milena/tests/value_label.cc (deleted) =================================================================== Index: trunk/milena/tests/value_int_s.cc (deleted) =================================================================== Index: trunk/milena/tests/value_rgb8.cc (deleted) =================================================================== Index: trunk/milena/tests/value_int_u8.cc (deleted) =================================================================== Index: trunk/milena/tests/value_float01.cc (deleted) =================================================================== Index: trunk/milena/tests/value_int_s16.cc (deleted) =================================================================== Index: trunk/milena/tests/value_graylevel.cc (deleted) =================================================================== Index: trunk/milena/tests/value_bool.cc (deleted) =================================================================== Index: trunk/milena/tests/value/set.cc =================================================================== --- trunk/milena/tests/value/set.cc (revision 0) +++ trunk/milena/tests/value/set.cc (revision 1586) @@ -0,0 +1,65 @@ +// 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_set.cc + * + * \brief Tests on mln::value::set_<T>. + */ + +#include <mln/value/int_u8.hh> +#include <mln/value/set.hh> + + + +template <typename T> +void test() +{ + typedef mln::value::set<T> S; + S s; + + mln_fwd_viter(S) v(s); + for_all(v) + std::cout << v << ' '; + std::cout << std::endl; + + mln_bkd_viter(S) w(s); + for_all(w) + std::cout << w << ' '; + std::cout << std::endl; +} + + + +int main() +{ + using namespace mln; + + test<bool>(); +// test<unsigned char>(); +// test<unsigned short>(); +// test<value::int_u8>(); +} Index: trunk/milena/tests/value/bool.cc =================================================================== --- trunk/milena/tests/value/bool.cc (revision 0) +++ trunk/milena/tests/value/bool.cc (revision 1586) @@ -0,0 +1,45 @@ +// 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_bool.cc + * + * \brief Tests on mln::value::set. + */ + +#include <mln/trait/value_.hh> +#include <mln/value/set.hh> + + +int main() +{ + using namespace mln; + + mln_assertion(mln_card(bool) == 2); + + value::set<bool> B; + std::cout << B << std::endl; +} Index: trunk/milena/tests/value/rgb8.cc =================================================================== --- trunk/milena/tests/value/rgb8.cc (revision 0) +++ trunk/milena/tests/value/rgb8.cc (revision 1586) @@ -0,0 +1,71 @@ +// 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_rgb8.cc + * + * \brief Tests on mln::value::rgb8. + */ + +#include <mln/value/rgb8.hh> +#include <mln/literal/all.hh> + + +int main() +{ + using namespace mln; + using value::rgb8; + using value::rgb; + + using literal::blue; + using literal::white; + + { + rgb8 v; + v.red() = 0; + v.green() = 1; + v.blue() = 2; + rgb8 c(0, 1, 2); + + std::cout << c << std::endl; + std::cout << v << std::endl; + + mln_assertion(c == c); + mln_assertion(c == v); + v.green() = 255; + std::cout << v << std::endl; + + mln_assertion(v != c); + + rgb<20> b = blue; + std::cout << b << std::endl; + + rgb<20> w = white; + std::cout << w << std::endl; + + mln_assertion(b != w); + } +} Index: trunk/milena/tests/value/float01_bis.cc =================================================================== --- trunk/milena/tests/value/float01_bis.cc (revision 0) +++ trunk/milena/tests/value/float01_bis.cc (revision 1586) @@ -0,0 +1,58 @@ +// 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_float01_bis.cc + * + * \brief Tests on mln::value::float01. + */ + +#include <iostream> +#include <mln/value/float01_8.hh> +#include <mln/value/float01_16.hh> + +int main() +{ + using namespace mln::value; + +// float01_8 a; + + std::cout << "a = " << std::endl; + std::cout << "testsetestest\n"<< std::endl; + +// gl8 a = white; +// gl16 b = white; +// assert((a == b) == true); +// gl8 c = (a + b) / 2; +// assert(c == white); +// c = a; +// assert(c == white); + +// c = (a * 2) / 2; +// assert(c == white); + + std::cout << "testsetestest\n"<< std::endl; +} Index: trunk/milena/tests/value/scalar.cc =================================================================== --- trunk/milena/tests/value/scalar.cc (revision 0) +++ trunk/milena/tests/value/scalar.cc (revision 1586) @@ -0,0 +1,94 @@ +// 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_scalar.cc + * + * \brief Tests on mln::value::scalar. + */ + +#include <iostream> + +#include <mln/value/scalar.hh> +#include <mln/value/int_u8.hh> + + +template <typename T> +void foo(const T& t) +{ + std::cout << mln::value::scalar(t) << std::endl; +} + +namespace mln +{ + namespace trait + { +// template <typename O1, typename O2> +// struct set_binary_< op::less, Object,O1, Object,O2 > { typedef bool ret; }; + +// template < typename Vl, typename Vr > +// struct set_binary_< op::less, mln::value::Scalar, Vl, mln::value::Scalar, Vr > +// { +// typedef double ret; +// }; + +// template <typename B, typename O> +// struct set_binary_< op::less, +// mln::value::Integer, B, +// mln::value::Scalar, O > +// { +// typedef bool ret; +// }; + + } +} + + +int main() +{ + using namespace mln; + +// int i = 51; +// foo(i); +// foo( value::scalar(i) ); + + + { + bool b; + value::int_u8 i, j; + + b = 1 > value::scalar(j); + + b = value::scalar(j) < value::scalar(j); + +// mln_trait_op_less_(value::scalar_< value::int_u8 >, value::scalar_< value::int_u8 >) tmp; +// void* v = tmp; + +// mln_trait_op_less_(int, value::scalar_< value::int_u8 >) tmp; +// void* v = tmp; + } + +} Index: trunk/milena/tests/value/int_u8.cc =================================================================== --- trunk/milena/tests/value/int_u8.cc (revision 0) +++ trunk/milena/tests/value/int_u8.cc (revision 1586) @@ -0,0 +1,197 @@ +// 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 <tests/value_macros.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + int_u8 i = 3, j; + + { + int k = 0; + k += value::scalar(k); + } + + // Assignment. + { + i = 51; + sym_compare_assert(i, ==, 51); + + i = 51u; + sym_compare_assert(i, ==, 51); + + signed char c = 51; + i = c; + sym_compare_assert(i, ==, 51); + + j = i; + sym_compare_assert(j, ==, 51); + + i = 3; + sym_compare_assert(3.0f, ==, i); + sym_compare_assert(i, !=, 2.99f); + + // Error at run-time as expected :-) + // i = 256; + // i = -1; + // i = 255, ++i; + } + + + // Comparaison + { + int_u8 i = 42; + int_u8 j = 51; + + asym_compare_assert(i, <, j); + asym_compare_assert(j, >, i); + asym_compare_assert(i, <, 12345.f); + asym_compare_assert(12345.f, >, i); + + sym_compare_assert(i, !=, j); + sym_compare_assert(i, ==, 42.f); + sym_compare_assert(42.f, ==, i); + sym_compare_assert(i, !=, 69.f); + sym_compare_assert(69.f, !=, i); + + } + + // Addition. + { + test_operator(int_u8, +, 5, 1); + test_interop(int_u8, int, +, 5, -1); + test_interop(int_u8, char, +, 4, 2); + test_interop(int_u8, unsigned char, +, 4, 2); + + int_u8 i = 234; + + i++; + sym_compare_assert(i, ==, 235.f); + + ++i; + sym_compare_assert(i, ==, 236.f); + + i = +i; + sym_compare_assert(i, ==, 236.f); + + } + + // Soustraction + { + test_operator(int_u8, -, 100, 5); + test_interop(int_u8, int, -, 100, 5); + test_interop(int_u8, char, -, 100, 5); + test_interop(int_u8, unsigned char, -, 5, 5); + + int_u8 c = 255; + c -= c; + + sym_compare_assert(c, ==, 0.f); + + int_u8 i = 236; + + i--; + sym_compare_assert(i, ==, 235.f); + + --i; + sym_compare_assert(i, ==, 234.f); + + sym_compare_assert(-i, ==, -234.f); + + sym_compare_assert(i * -2, !=, 0.f); + std::cout << (i) << " * -2 = " + << (i * -2) << ' ' + << (-2 * i) << ' ' + << (-2 * int(i)) + << std::endl; + } + + // Multiplication + { + test_operator(int_u8, *, 5, 1); + test_interop(int_u8, int, *, 5, 1); + test_interop(int_u8, char, *, 4, 2); + test_interop(int_u8, unsigned char, *, 4, 2); + + int_u8 c = 255; + + c *= 0; + sym_compare_assert(c, ==, 0.f); + + i *= 2; + int k; k *= i; + + unsigned char d = 0; + i *= d; + sym_compare_assert(i, ==, 0.f); + + // Error at run-time as expected :-) + // i = 128; + // i *= 2; + + } + + // Division + { + test_operator(int_u8, /, 5, 1); + test_interop(int_u8, int, /, 5, 1); + test_interop(int_u8, char, /, 4, 2); + test_interop(int_u8, unsigned char, /, 4, 2); + + int_u8 c = 200; + + c /= 1; + sym_compare_assert(c, ==, 200.f); + c /= 2; + sym_compare_assert(c, ==, 100.f); + + int_u8 d = 2; + c /= 2; + sym_compare_assert(c, ==, 50.f); + + } + + + // Modulo + { + test_operator(int_u8, %, 5, 10); + test_interop(int_u8, int, %, 5, 10); + test_interop(int_u8, char, %, 4, 20); + test_interop(int_u8, unsigned char, %, 4, 20); + } + +} Index: trunk/milena/tests/value/float01.cc =================================================================== --- trunk/milena/tests/value/float01.cc (revision 0) +++ trunk/milena/tests/value/float01.cc (revision 1586) @@ -0,0 +1,150 @@ +// 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_float01.cc + * + * \brief Tests on mln::value::float01. + */ + +#include <iostream> + +#include <mln/core/image2d.hh> +#include <mln/debug/iota.hh> +#include <mln/debug/println.hh> + +#include <mln/value/float01_8.hh> +#include <mln/value/float01_16.hh> +#include <mln/value/int_u8.hh> +#include <mln/level/transform.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> + +#include <mln/win/rectangle2d.hh> +#include <mln/level/median.hh> +#include <mln/level/compare.hh> + + +using namespace mln; +using namespace mln::value; +using mln::value::int_u8; + +float fi(int) { return 0.5; } +int ii(int) { return 1; } + +float fd(double) { return 0.5; } +int id(double) { return 1; } + + +struct tofloat01 : mln::Function_v2v<tofloat01> +{ + + typedef float01_<16> result; + result operator()(int_u8 v) const + { + result ret(double(v) / (mln_max(int_u8))); + // std::cout << v << "-> " << ret << std::endl; + return ret; + } +}; + +struct to8bits : mln::Function_v2v<to8bits> +{ + + typedef int_u8 result; + result operator()(float01_<16> v) const + { + result ret = int(v.value() * 255); + //std::cout << v << "-> " << ret << std::endl; + return ret; + } +}; + +int main() +{ + win::rectangle2d rect(51, 51); + border::thickness = 52; + + float01_8 a(0.5); + float01_16 b(0.5); + + assert(approx_equal(b,a)); + + std::cout << b << std::endl; + b = b + 0.2; + std::cout << b << std::endl; + b = b - 0.2; + std::cout << b << std::endl; + b = b * 1.5; + std::cout << b << std::endl; + b = b / 4.6; + std::cout << b << std::endl; + + b = b / 3; + std::cout << b << std::endl; + b = b * 1; + std::cout << b << std::endl; + + a = fi(a); + a = ii(a); + a = fd(a); + a = id(a); + + b = a; + a = b; + b = 0.34; + std::cout << b << std::endl; + b = 0; + std::cout << b << std::endl; + b = 1; + std::cout << b << std::endl; + + { + std::cout << "convert" << std::endl; + image2d<int_u8> + lena = io::pgm::load<int_u8>("../img/lena.pgm"), + ref(lena.domain()); + + image2d<float01_16> out(lena.domain()); + image2d<float01_16> tmp(lena.domain()); + + level::transform(lena, tofloat01(), tmp); + + level::median(tmp, rect, out); + level::median(lena, rect, ref); + + + level::transform(out, to8bits(), lena); + + io::pgm::save(lena, "out.pgm"); + io::pgm::save(ref, "ref.pgm"); + mln_assertion(lena == ref); + //debug::println(out); + } + + +} Index: trunk/milena/tests/value/builtin.cc =================================================================== --- trunk/milena/tests/value/builtin.cc (revision 0) +++ trunk/milena/tests/value/builtin.cc (revision 1586) @@ -0,0 +1,120 @@ +// 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_builtin.cc + * + * \brief Tests on mln::trait::op with a builtin. + */ + +#include <iostream> + +#include <mln/value/scalar.hh> +#include <mln/value/int_u8.hh> + + +namespace mln +{ + namespace trait + { + + namespace op + { + + template <typename T> + struct test; + + template <typename L, typename R> + struct test_2; + + } + + // unary + + template < typename S > + struct set_unary_< op::test, mln::value::Scalar, S > + { + typedef double ret; + }; + +// template <typename I> +// struct set_unary_< op::test, +// mln::value::Integer, I > +// { +// typedef float ret; +// }; + +// template <typename I> +// struct set_unary_< op::test, +// mln::value::Built_In, I > +// { +// typedef bool ret; +// }; + + + // binary + + template < typename S1, typename S2 > + struct set_binary_< op::test_2, + mln::value::Scalar, S1, + mln::value::Scalar, S2 > + { + typedef double ret; + }; + +// template < typename I, typename S > +// struct set_binary_< op::test_2, +// mln::value::Integer, I, +// mln::value::Scalar, S > +// { +// typedef float ret; +// }; + +// template < typename B, typename S > +// struct set_binary_< op::test_2, +// mln::value::Built_In, B, +// mln::value::Scalar, S > +// { +// typedef bool ret; +// }; + + } +} + + +int main() +{ + using namespace mln; + + { + mln::trait::solve_binary< trait::op::test_2, int, value::scalar_< value::int_u8 > >::ret tmp; + double& d = tmp; + } + { + mln::trait::solve_unary< trait::op::test, int >::ret tmp; + double& d = tmp; + } +} Index: trunk/milena/tests/value/quat.cc =================================================================== --- trunk/milena/tests/value/quat.cc (revision 0) +++ trunk/milena/tests/value/quat.cc (revision 1586) @@ -0,0 +1,72 @@ +// 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_quat.cc + * + * \brief Tests on mln::value::quat. + */ + +#include <iostream> + +#include <mln/value/quat.hh> + + +int main() +{ + using namespace mln; + + value::quat q1(3.f, 4.f, 1.6f, 0.5f); + value::quat q2(1.2, make::vec(3, 6, 4)); + value::quat q3(make::vec(1.3, 3., -6., 4.)); + + std::cout << q1 << std::endl; + std::cout << q2 << std::endl; + std::cout << q3 << std::endl; + + std::cout << q1.s() << std::endl; + + q1.s() = 2.6; + std::cout << q1 << std::endl; + + std::cout << q1.v() << std::endl; + + q2.v() = make::vec(1.4, 5.9, 3.1); + std::cout << q2 << std::endl; + + std::cout << q2 * q3 << std::endl; + + mln_assertion(! q3.is_unit()); + q3.set_unit(); + std::cout << q3 << std::endl; + mln_assertion(q3.is_unit()); + + std::cout << q2.conj() << std::endl; + std::cout << q2.inv() << std::endl; + std::cout << norm::l2(q2.to_vec()) << ' ' << norm::l2(q2.inv().to_vec()) << std::endl; + std::cout << q2.inv().inv() << std::endl; + +} Index: trunk/milena/tests/value/float01_f.cc =================================================================== --- trunk/milena/tests/value/float01_f.cc (revision 0) +++ trunk/milena/tests/value/float01_f.cc (revision 1586) @@ -0,0 +1,43 @@ +// 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_float01_f.cc + * + * \brief Tests on mln::value::float01_f. + */ + +#include <iostream> +#include <mln/value/float01_f.hh> + +int main() +{ + using mln::value::float01_f; + + float01_f x = 0.5; + std::cout << x + 21.25 << std::endl; + x = x + 34; +} Index: trunk/milena/tests/value/int_s.cc =================================================================== --- trunk/milena/tests/value/int_s.cc (revision 0) +++ trunk/milena/tests/value/int_s.cc (revision 1586) @@ -0,0 +1,51 @@ +// 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_s.cc + * + * \brief Tests on mln::value::int_s. + */ + +#include <mln/value/int_s.hh> +#include <mln/value/int_u.hh> + + +int main() +{ + using namespace mln; + using value::int_s; + + { + int_s<7> i = 3; + i = 2; + mln_assertion(i == 2); + mln_assertion(i != 3); + + mln_assertion(-i == -2); + mln_assertion(-3 * i == -6); + } +} Index: trunk/milena/tests/value/label.cc =================================================================== --- trunk/milena/tests/value/label.cc (revision 0) +++ trunk/milena/tests/value/label.cc (revision 1586) @@ -0,0 +1,49 @@ +// 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_label.cc + * + * \brief Tests on mln::value::label. + */ + +#include <mln/value/int_u8.hh> +#include <mln/value/label.hh> + + + +int main() +{ + using namespace mln; + using value::int_u8; + using value::label; + + int_u8 i = 51; + label<8> l = 50; + ++l; + mln_assertion(l == l); + mln_assertion(i == l.to_enc()); +} Index: trunk/milena/tests/value/interop.cc =================================================================== --- trunk/milena/tests/value/interop.cc (revision 0) +++ trunk/milena/tests/value/interop.cc (revision 1586) @@ -0,0 +1,114 @@ +// 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_interop.cc + * + * \brief Tests interoperability on mln::value::*. + */ + +#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_u16; + using value::float01_8; + + + // Tests on int_u<n> alone. + { + int_u8 i; + i = 51; + i *= 2; + } + + using value::int_s8; + + +// { +// // 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; +// mln_assertion(j == (128 + 42)); + +// (k = j - i) = i - j; +// mln_assertion(k == (-42)); + +// j = 2; +// (j = j * i) = i * j; +// mln_assertion(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; +// mln_assertion(x < 0 && x < 1); + +// x = x * j; +// mln_assertion(x < 0 && x < 1); + +// x = x * j; +// mln_assertion(x < 0 && x < 1); +// } + +} Index: trunk/milena/tests/value/int_s16.cc =================================================================== --- trunk/milena/tests/value/int_s16.cc (revision 0) +++ trunk/milena/tests/value/int_s16.cc (revision 1586) @@ -0,0 +1,213 @@ +// 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_s16.cc + * + * \brief Tests on mln::value::int_s16. + */ + +#include <mln/value/int_s16.hh> + +#define test_operator(T, OP, V1, V2) \ + \ +{ \ + T i = V1; \ + T j = V2; \ + \ + i = i OP j; \ + mln_assertion(i == (V1 OP V2)); \ + mln_assertion(j == V2); \ + \ + i OP##= i; \ + mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \ +} + +#define test_interop(T1, T2, OP, V1, V2) \ + \ +{ \ + T1 i = V1; \ + T2 j = V2; \ + \ + i = i OP j; \ + mln_assertion(i == (V1 OP V2)); \ + mln_assertion(j == V2); \ + \ + i OP##= i; \ + mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \ +} + + +// test_operator + +int main() +{ + using namespace mln; + using value::int_s16; + + int_s16 i = 3, j; + + // Assignment. + { + i = 51; + mln_assertion(i == 51); + + i = 51u; + mln_assertion(i == 51); + + signed char c = 51; + i = c; + mln_assertion(i == 51); + + j = i; + mln_assertion(j == 51); + + i = 3; + mln_assertion(3.0f == i); + mln_assertion(i != 2.99f); + + // Error at run-time as expected :-) + // i = 256; + // i = -1; + // i = 255, ++i; + } + + + // Comparaison + { + int_s16 i = 42; + int_s16 j = 51; + + mln_assertion(i < j); + mln_assertion(j > i); + mln_assertion(i < 12345); + mln_assertion(12345 > i); + + mln_assertion(i != j); + mln_assertion(i == 42); + mln_assertion(42 == i); + mln_assertion(i != 69); + mln_assertion(69 != i); + + } + + // Addition. + { + test_operator(int_s16, +, -5, 1); + test_interop(int_s16, int, +, 5, -1); + test_interop(int_s16, char, +, -4, 2); + test_interop(int_s16, unsigned char, +, 4, 2); + + int_s16 i = 234; + + i++; + mln_assertion(i == 235); + + ++i; + mln_assertion(i == 236); + + i = +i; + mln_assertion(i == 236); + + } + + // Soustraction + { + test_operator(int_s16, -, 100, 5); + test_interop(int_s16, int, -, 100, 5); + test_interop(int_s16, char, -, 100, 5); + test_interop(int_s16, unsigned char, -, 100, 5); + + int_s16 c = 255; + c -= c; + + mln_assertion(c == 0); + + int_s16 i = 236; + + i--; + mln_assertion(i == 235); + + --i; + mln_assertion(i == 234); + + mln_assertion(-i == -234); + } + + // Multiplication + { + test_operator(int_s16, *, 5, 1); + test_interop(int_s16, int, *, 5, 1); + test_interop(int_s16, char, *, 4, 2); + test_interop(int_s16, unsigned char, *, 4, 2); + + int_s16 c = 255; + + c *= 0; + mln_assertion(c == 0); + + i *= 2; + int k; k *= i; + + unsigned char d = 0; + i *= d; + mln_assertion(i == 0); + + // Error at run-time as expected :-) + // i = 128; + // i *= 2; + + } + + // Division + { + test_operator(int_s16, /, 5, 1); + test_interop(int_s16, int, /, 5, 1); + test_interop(int_s16, char, /, 4, 2); + test_interop(int_s16, unsigned char, /, 4, 2); + + int_s16 c = 200; + + c /= 1; + mln_assertion(c == 200); + c /= 2; + mln_assertion(c == 100); + + int_s16 d = 2; + c /= 2; + mln_assertion(c == 50); + + } + + + // Modulo + { + test_operator(int_s16, %, 5, 10); + test_interop(int_s16, int, %, 5, 10); + test_interop(int_s16, char, %, 4, 20); + test_interop(int_s16, unsigned char, %, 4, 20); + } +} Index: trunk/milena/tests/value/Makefile.am =================================================================== --- trunk/milena/tests/value/Makefile.am (revision 1585) +++ trunk/milena/tests/value/Makefile.am (revision 1586) @@ -1,3 +1,44 @@ ## Process this file through Automake to create Makefile.in -*- Makefile -*- include $(top_srcdir)/milena/tests/tests.mk + +SUBDIRS = \ + concept \ + builtin + +check_PROGRAMS = \ + bool \ + builtin \ + equiv \ + float01_bis \ + float01 \ + float01_f \ + graylevel \ + interop \ + int_s16 \ + int_s \ + int_u8 \ + label \ + quat \ + rgb8 \ + scalar \ + set + +bool_SOURCES = bool.cc +builtin_SOURCES = builtin.cc +equiv_SOURCES = equiv.cc +float01_bis_SOURCES = float01_bis.cc +float01_SOURCES = float01.cc +float01_f_SOURCES = float01_f.cc +graylevel_SOURCES = graylevel.cc +interop_SOURCES = interop.cc +int_s16_SOURCES = int_s16.cc +int_s_SOURCES = int_s.cc +int_u8_SOURCES = int_u8.cc +label_SOURCES = label.cc +quat_SOURCES = quat.cc +rgb8_SOURCES = rgb8.cc +scalar_SOURCES = scalar.cc +set_SOURCES = set.cc + +TESTS = $(check_PROGRAMS) Index: trunk/milena/tests/value/equiv.cc =================================================================== --- trunk/milena/tests/value/equiv.cc (revision 0) +++ trunk/milena/tests/value/equiv.cc (revision 1586) @@ -0,0 +1,58 @@ +// 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_equiv.cc + * + * \brief Tests on mln::value::equiv. + * + * \todo Rename "::to_equiv()" as "::to_equiv_()". + */ + +#include <mln/value/int_u8.hh> +#include <mln/value/equiv.hh> + + +int main() +{ + using namespace mln; + + value::int_u8 i = 51; + + { + const unsigned& u = i.to_equiv(); + mln_assertion(u == 51); + } + { + const unsigned& u = value::equiv(i); + mln_assertion(u == 51); + } + { + const unsigned& u = value::equiv( value::scalar(i) ); + mln_assertion(u == 51); + } + +} Index: trunk/milena/tests/value/graylevel.cc =================================================================== --- trunk/milena/tests/value/graylevel.cc (revision 0) +++ trunk/milena/tests/value/graylevel.cc (revision 1586) @@ -0,0 +1,396 @@ +// 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_graylevel.cc + * + * \brief Tests on mln::value::graylevel. Tests operations between + * graylevel of different encodings. + * + */ + +#include <mln/value/graylevel.hh> +#include <mln/value/int_u8.hh> + +#include <mln/literal/black.hh> +#include <mln/literal/white.hh> + + + +int main() +{ + using namespace mln::value; + + using mln::literal::white; + using mln::literal::black; + + gl8 a = 255; + gl8 b = 255; + + // Constructions + { + gl8 x; + + gl8 a = 12; + gl8 b(12); + mln_assertion(a == b); + +// gl16 c = 2335; +// gl8 d = c; +// mln_assertion(c == d); + + gl8 d = 250; + gl16 c = d; + mln_assertion(c == d); + + gl8 e = gray(white); + mln_assertion(e == white); + + gl8 f = 12; + gl8 g = f; + gl8 h(f); + + mln_assertion(f == g); + mln_assertion(h == g); + } + + // Literals + { + gl8 a(white); + gl16 b(white); + + mln_assertion(a == b); + mln_assertion(a.value() == float(255)); + mln_assertion(b.value() == float(65535)); + mln_assertion(a == white); + mln_assertion(b == white); + + gl8 c = (gl16(white) + white) / 2; + std::cout << "gl8 c = (white + white) / 2; => c.value() == " + << int(c.value()) << std::endl; + mln_assertion(c == white); + mln_assertion(c.value() == float(255)); + + c = (gl8(white) + white) / 2; + mln_assertion(c == white); + mln_assertion(c.value() == float(255)); + + c = (gray(white) + white) / 2; + mln_assertion(c == white); + mln_assertion(c.value() == float(255)); + + a = black; + b = black; + + mln_assertion(a == b); + mln_assertion(a.value() == float(0)); + mln_assertion(b.value() == float(0)); + +// c = (black + black) / 2; +// mln_assertion(c == black); +// mln_assertion(c.value() == float(0)); + } + + // Assigment + { + gl8 a; + gl16 b; + + a = white; + mln_assertion(a == white); + mln_assertion(a.value() == float(255)); + + a = 23; + mln_assertion(a != white); + mln_assertion(a != black); + mln_assertion(a.value() == float(23)); + + b = 2; + mln_assertion(b != white); + mln_assertion(b != black); + mln_assertion(b.value() == float(2)); + + a = b; + mln_assertion(a.value() == float(2 / 257)); + + signed char c = 51; + a = c; + mln_assertion(a.value() == float(51)); + + // bounds + a = 255; + mln_assertion(a.value() == float(255)); + a = 0; + mln_assertion(a.value() == float(0)); + } + + // Addition + { + gl8 a; + gl16 b; + + // gl8 <- gl8 + gl8 + a = 42; + a += a; + mln_assertion(a.value() == float(84)); + + a = 42; + a = a + a; + mln_assertion(a.value() == float(84)); + + // gl8 <- gl8 + gl16 + a = 42; + b = 16969; + a = a + b; + mln_assertion(a.value() == float((42 + b.value() / 257) )); + a = 42; + b = 16969; + a += b; + mln_assertion(a.value() == float((42 + b.value() / 257) )); + + + // gl16 <- gl8 + gl16 + a = 42; + b = 16969; + b += a; + mln_assertion(b.value() == float((42 * 257 + 16969) )); + + a = 42; + b = 16969; + b = a + b; + mln_assertion(b.value() == float((42 * 257 + 16969) )); + + // misc + a = 255; + b = 0; + a = a + b; + mln_assertion(a.value() == float(255)); + + a = 0; + b = 65535; + a = a + b; + mln_assertion(a.value() == float(255)); + } + + + // Soustraction + { + gl8 a; + gl16 b; + + // gl8 <- gl8 - gl8 + a = 42; + a -= a; + mln_assertion(a == black); + + a = 42; + a = a - a; + mln_assertion(a == black); + + // gl8 <- gl8 - gl16 + a = 42; + b = 5969; + + a = b; + std::cout << "a.value() = " << int(a.value()) << std::endl; + std::cout << "should be " << (b.value() / 256) << std::endl; + + a = 42; + a = a - b; + std::cout << int(a.value()) << ":" << (42 - b.value() / 256) << std::endl; + mln_assertion(a.value() == float((42 - b.value() / 256) )); + a = 42; + b = 16969; + a -= b; + mln_assertion(a.value() == float((42 - b.value() / 257) )); + + + // gl16 <- gl8 - gl16 + a = 100; + b = 16969; + b -= a; + mln_assertion(b.value() == float((100 * 257 - 16969) )); + + a = 100; + b = 16969; + b = a - b; + mln_assertion(b.value() == float((100 * 257 - 16969) )); + + // misc + a = 255; + b = 0; + a = a - b; + mln_assertion(a.value() == float(255)); + + a = 0; + b = 65535; + a = a - b; + mln_assertion(a.value() == float(255)); + + // ... + { + graylevel<2> a = 2; + graylevel<3> b = 5; + graylevel<2> c; + graylevel<3> d; + + c = a - b; + d = a - b; + mln_assertion(c == d); + } + + { + + // ... + gl8 a = 42; + gl16 b = 5969; + gl8 p; + p = b; + gl8 q; + gl8 r; + + q = a - p; + r = a - b; + std::cout << int(q.value()) << " " << int(r.value()) << std::endl; + mln_assertion(q == r); + + } + + } + + // Multiplication + { + gl8 a; + gl16 b; + + // gl8 <- gl8 * gl8 + a = 21; + a *= a; + mln_assertion(a.value() == 42); + + a = 21; + a = a * a; + mln_assertion(a.value() == 42); + + // gl8 <- gl8 * gl16 + a = 10; + b = 5969; + a = a * b; + mln_assertion(a.value() == float((10 * b.value() / 257) )); + + a = 10; + b = 16969; + a *= b; + mln_assertion(a.value() == float((10 * b.value() / 257) )); + + + // gl16 <- gl8 * gl16 + a = 10; + b = 5969; + b *= a; + mln_assertion(b.value() == float((10 * 257 * 5969) )); + + a = 10; + b = 5969; + b = a * b; + mln_assertion(b.value() == float((10 * 257 * 5969) )); + + // misc + a = 255; + b = 0; + a = a * b; + mln_assertion(a == black); + + a = 0; + b = 65535; + a = a * b; + mln_assertion(a == black); + + // ... + { + graylevel<2> a = 2; + graylevel<3> b = 5; + graylevel<2> c; + graylevel<3> d; + + c = a * b; + d = a * b; + mln_assertion(c == d); + } + + { + + // ... + gl8 a = 7; + gl16 b = 5969; + + gl8 p; + p = b; + + gl8 q; + gl8 r; + + q = a * p; + r = a * b; + std::cout << int(q.value()) << " " << int(r.value()) << std::endl; + mln_assertion(q == r); + + } + + } + + + // Not exhaustive + + // gl8 a(white); + // gl16 b(white); + // mln_assertion(a == b); + // // mln_assertion(-a == -b); + + // mln_assertion(a.value() != b.value()); + + // { + // gl8 c = (a + b) / 2; + // mln_assertion(c == white); + // mln_assertion(c.value() == 255); + + // c = a; + // mln_assertion(c == white); + + // c = (a * 2) / 2; + // mln_assertion(c == white); + + // c = c / 6; + // } + + // { + // gl8 c = (white + white) / 2; + // mln_assertion(c == white); + // mln_assertion(c.value() == float(255)); + // } + + // gray g(black); +} Index: trunk/milena/tests/Makefile.am =================================================================== --- trunk/milena/tests/Makefile.am (revision 1585) +++ trunk/milena/tests/Makefile.am (revision 1586) @@ -19,6 +19,7 @@ norm \ set \ util \ + value \ win check_PROGRAMS = \ @@ -131,19 +132,6 @@ trait_value \ translate_image \ \ - value_float01_bis \ - value_float01 \ - value_float01_f \ - value_graylevel \ - value_interop \ - value_int_s16 \ - value_int_s \ - value_int_u8 \ - value_label \ - value_quat \ - value_rgb8 \ - value_scalar \ - value_set \ vec \ \ window1d \ @@ -262,19 +250,6 @@ trait_value_SOURCES = trait_value.cc translate_image_SOURCES = translate_image.cc -value_float01_bis_SOURCES = value_float01_bis.cc -value_float01_SOURCES = value_float01.cc -value_float01_f_SOURCES = value_float01_f.cc -value_graylevel_SOURCES = value_graylevel.cc -value_interop_SOURCES = value_interop.cc -value_int_s16_SOURCES = value_int_s16.cc -value_int_s_SOURCES = value_int_s.cc -value_int_u8_SOURCES = value_int_u8.cc -value_label_SOURCES = value_label.cc -value_quat_SOURCES = value_quat.cc -value_rgb8_SOURCES = value_rgb8.cc -value_scalar_SOURCES = value_scalar.cc -value_set_SOURCES = value_set.cc vec_SOURCES = vec.cc window1d_SOURCES = window1d.cc