milena r1491: Add simple tests for level

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-11-16 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add simple tests for level. * tests/level/compare.cc, * tests/level/compute.cc, * tests/level/saturate.cc, * tests/level/sort_points.cc, * tests/level/stretch.cc: New test for level. * tests/level/median.cc, * tests/level/paste.cc, * tests/level/transform.cc: Upadate test. --- compare.cc | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ compute.cc | 53 ++++++++++++++++++++++++++++++ median.cc | 2 - paste.cc | 6 --- saturate.cc | 57 +++++++++++++++++++++++++++++++++ sort_points.cc | 61 +++++++++++++++++++++++++++++++++++ stretch.cc | 65 +++++++++++++++++++++++++++++++++++++ transform.cc | 12 +++++- 8 files changed, 345 insertions(+), 9 deletions(-) Index: trunk/milena/tests/level/median.cc =================================================================== --- trunk/milena/tests/level/median.cc (revision 1490) +++ trunk/milena/tests/level/median.cc (revision 1491) @@ -51,7 +51,7 @@ border::thickness = 52; image2d<int_u8> - lena = io::pgm::load("../img/lena.pgm"), + lena = io::pgm::load("../../img/lena.pgm"), out(lena.domain()); level::median(lena, rect, out); Index: trunk/milena/tests/level/transform.cc =================================================================== --- trunk/milena/tests/level/transform.cc (revision 1490) +++ trunk/milena/tests/level/transform.cc (revision 1491) @@ -52,15 +52,23 @@ { using namespace mln; - const unsigned size = 10000; + const unsigned size = 1000; image2d<unsigned short> ima(size, size); + image2d<unsigned short> + out(size, size); (std::cout << "iota... ").flush(); debug::iota(ima); std::cout << "done" << std::endl; (std::cout << "transform... ").flush(); - level::transform(ima, mysqrt(), ima); + level::transform(ima, mysqrt(), out); + std::cout << "done" << std::endl; + + (std::cout << "checking... ").flush(); + box_fwd_piter_<point2d> p(out.domain()); + for_all(p) + mln_assertion((unsigned short)std::sqrt(ima(p)) == out(p)); std::cout << "done" << std::endl; } Index: trunk/milena/tests/level/stretch.cc =================================================================== --- trunk/milena/tests/level/stretch.cc (revision 0) +++ trunk/milena/tests/level/stretch.cc (revision 1491) @@ -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/level/stretch.cc + * + * \brief Tests on mln::level::stretch. + */ + + +#include <mln/core/image2d.hh> +#include <mln/level/stretch.hh> +#include <mln/debug/iota.hh> +#include <mln/value/int_u8.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + int vs[3][3] = { + { 1000, 2000, 3000 }, + { 1000, 2000, 3000 }, + { 1000, 2000, 3000 } + }; + image2d<int> ima(make::image2d(vs)); + + image2d<int_u8> out(3, 3); + + int_u8 ws[3][3] = { + { 0, 127, 255 }, + { 0, 127, 255 }, + { 0, 127, 255 } + }; + + image2d<int_u8> ref(make::image2d(ws)); + level::stretch(ima, out); + box_fwd_piter_<point2d> p(out.domain()); + for_all(p) + mln_assertion(out(p) == ref(p)); +} Index: trunk/milena/tests/level/compute.cc =================================================================== --- trunk/milena/tests/level/compute.cc (revision 0) +++ trunk/milena/tests/level/compute.cc (revision 1491) @@ -0,0 +1,53 @@ +// 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/level/compute.cc + * + * \brief Tests on mln::level::compute. + */ + +#include <mln/core/image2d.hh> +#include <mln/level/compute.hh> +#include <mln/debug/iota.hh> +#include <mln/accu/min.hh> +#include <mln/accu/max.hh> + + +int main() +{ + using namespace mln; + + const unsigned size = 200; + image2d<int> ima(size, size); + accu::min_<int> acu_min; + accu::max_<int> acu_max; + debug::iota(ima); + int min = level::compute(ima, acu_min); + int max = level::compute(ima, acu_max); + mln_assertion(min == 1); + mln_assertion(max == 40000); +} Index: trunk/milena/tests/level/paste.cc =================================================================== --- trunk/milena/tests/level/paste.cc (revision 1490) +++ trunk/milena/tests/level/paste.cc (revision 1491) @@ -45,18 +45,12 @@ box2d b(make::point2d(1,2), make::point2d(2,4)); image2d<int> ima(b, 2); debug::iota(ima); - debug::println(ima); - box2d b2(make::point2d(-1,-2), make::point2d(3,6)); image2d<int> ima2(b2, 0); debug::iota(ima2); - debug::println(ima2); - - trace::quiet = false; level::paste(ima, ima2); // Fast version. - debug::println(ima2); level::impl::generic::paste_(ima, ima2); // Not so fast version... } Index: trunk/milena/tests/level/sort_points.cc =================================================================== --- trunk/milena/tests/level/sort_points.cc (revision 0) +++ trunk/milena/tests/level/sort_points.cc (revision 1491) @@ -0,0 +1,61 @@ +// 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/level/sort_points.cc + * + * \brief Tests on mln::level::sort_points. + */ + +#include <mln/core/image2d.hh> +#include <mln/debug/iota.hh> +#include <mln/level/sort_points.hh> +#include <mln/core/p_array.hh> + + +int main () +{ + using namespace mln; + + image2d<int> ima(3, 3); + debug::iota (ima); + p_array<point2d> array_inc = level::sort_points_increasing(ima); + p_array<point2d> array_dec = level::sort_points_decreasing(ima); + + p_array<point2d> array_inc_ref; + p_array<point2d> array_dec_ref; + + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 3; ++j) + array_inc_ref.append(point2d(i, j)); + + for (int i = 2; i >= 0; --i) + for (int j = 2; j >= 0; --j) + array_dec_ref.append(point2d(i, j)); + + mln_assertion(array_inc == array_inc_ref); + mln_assertion(array_dec == array_dec_ref); +} Index: trunk/milena/tests/level/compare.cc =================================================================== --- trunk/milena/tests/level/compare.cc (revision 0) +++ trunk/milena/tests/level/compare.cc (revision 1491) @@ -0,0 +1,98 @@ +// 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/level/compare.cc + * + * \brief Tests on mln::level::compare. + */ + +#include <mln/core/image2d.hh> +#include <mln/level/compare.hh> +#include <mln/debug/iota.hh> + + +int main() +{ + using namespace mln; + + const unsigned size = 3; + image2d<int> rhs(size, size), lhs(rhs.domain()); + debug::iota(rhs); + debug::iota(lhs); + mln_assertion( (lhs == rhs)); + mln_assertion( (lhs <= rhs)); + mln_assertion(! (lhs < rhs)); + mln_assertion( (lhs >= rhs)); + mln_assertion(! (lhs > rhs)); + + int vs[3][3] = { + + { 2, 3, 4 }, + { 5, 6, 7 }, + { 8, 9, 10 }, + + }; + + rhs = make::image2d(vs); + + mln_assertion(! (lhs == rhs)); + mln_assertion( (lhs <= rhs)); + mln_assertion( (lhs < rhs)); + mln_assertion(! (lhs >= rhs)); + mln_assertion(! (lhs > rhs)); + + mln_assertion(! (rhs == lhs)); + mln_assertion(! (rhs <= lhs)); + mln_assertion(! (rhs < lhs)); + mln_assertion( (rhs >= lhs)); + mln_assertion( (rhs > lhs)); + + + int ws[3][3] = { + + { 1, 3, 4 }, + { 4, 6, 7 }, + { 7, 9, 10 }, + + }; + + rhs = make::image2d(ws); + + mln_assertion(! (lhs == rhs)); + mln_assertion( (lhs <= rhs)); + mln_assertion(! (lhs < rhs)); + mln_assertion(! (lhs >= rhs)); + mln_assertion(! (lhs > rhs)); + + mln_assertion(! (rhs == lhs)); + mln_assertion(! (rhs <= lhs)); + mln_assertion(! (rhs < lhs)); + mln_assertion( (rhs >= lhs)); + mln_assertion(! (rhs > lhs)); + + +} Index: trunk/milena/tests/level/saturate.cc =================================================================== --- trunk/milena/tests/level/saturate.cc (revision 0) +++ trunk/milena/tests/level/saturate.cc (revision 1491) @@ -0,0 +1,57 @@ +// 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/level/saturate.cc + * + * \brief Tests on mln::level::saturate. + */ + + +#include <mln/core/image2d.hh> +#include <mln/level/saturate.hh> +#include <mln/debug/iota.hh> + + +int main() +{ + using namespace mln; + + const unsigned size = 1000; + image2d<int> ima(3, 3); + int vs[3][3] = { + { 2, 2, 3 }, + { 4, 5, 6 }, + { 6, 6, 6 } + }; + + image2d<int> ref(make::image2d(vs)); + debug::iota(ima); + level::saturate_inplace(ima, 2, 6); + box_fwd_piter_<point2d> p(ima.domain()); + for_all(p) + mln_assertion(ima(p) == ref(p)); +}
participants (1)
-
Guillaume Duhamel