Commit 7698ead6 authored by Guillaume Duhamel's avatar Guillaume Duhamel
Browse files

Add full tests for border.

	* tests/border/adjust_full.cc,
	* tests/border/duplicate_full.cc,
	* tests/border/fill_full.cc,
	* tests/border/mirror_full.cc: New full tests.

	* tests/border/duplicate.cc: Fix Doxygen comment.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1565 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 91a4fc39
2007-11-28 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr>
Add full tests for border.
* tests/border/adjust_full.cc,
* tests/border/duplicate_full.cc,
* tests/border/fill_full.cc,
* tests/border/mirror_full.cc: New full tests.
* tests/border/duplicate.cc: Fix Doxygen comment.
2007-11-28 Benoit Sigoure <tsuna@lrde.epita.fr>
Fix various typos.
......
// 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/border/adjust_full.cc
*
* \brief Tests on mln::border::adjust.
*/
#include <mln/core/image2d.hh>
#include <mln/border/get.hh>
#include <mln/border/adjust.hh>
int main()
{
using namespace mln;
typedef image2d<int> I;
I ima(3, 3, 2);
border::adjust(ima, 3);
mln_assertion(border::get(ima) == 3);
border::adjust(ima, 5);
mln_assertion(border::get(ima) == 5);
border::adjust(ima, 1);
mln_assertion(border::get(ima) == 5);
border::adjust(ima, 4);
mln_assertion(border::get(ima) == 5);
border::adjust(ima, 42);
mln_assertion(border::get(ima) == 42);
border::adjust(ima, 51);
mln_assertion(border::get(ima) == 51);
border::adjust(ima, 2);
mln_assertion(border::get(ima) == 51);
}
......@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
/*! \file tests/border_duplicate/test_border_duplicate_image2d_1.cc
/*! \file tests/border/duplicate.cc
*
* \brief Tests on mln::border::duplicate.
*/
......
// 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/border/duplicate_full.cc
*
* \brief Tests on mln::border::duplicate.
*/
#include <mln/core/image2d.hh>
#include <mln/debug/iota.hh>
#include <mln/border/duplicate.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_s8.hh>
using namespace mln;
int
main (void)
{
{
(std::cerr << "Test border::mirror on int with border = 3 ... ").flush ();
typedef int T;
int border = 3;
int row = 4;
int col = 5;
int r = row + 2 * border;
int c = col + 2 * border;
image2d<T> ima(row, col, border);
debug::iota (ima);
border::duplicate (ima);
T vs[110] =
{
1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
6, 6, 6, 6, 7, 8, 9, 10, 10, 10, 10,
11, 11, 11, 11, 12, 13, 14, 15, 15, 15, 15,
16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20
};
for (int i = 0; i < c * r; ++i)
mln_assertion(ima[i] == vs[i]);
std::cerr << "OK" << std::endl;
}
{
(std::cerr << "Test border::mirror on int_u8 with border = 2 ... ").flush ();
typedef value::int_u8 T;
int border = 2;
int row = 4;
int col = 5;
int r = row + 2 * border;
int c = col + 2 * border;
image2d<T> ima(row, col, border);
debug::iota (ima);
border::duplicate (ima);
T vs[72] =
{
1, 1, 1, 2, 3, 4, 5, 5, 5,
1, 1, 1, 2, 3, 4, 5, 5, 5,
1, 1, 1, 2, 3, 4, 5, 5, 5,
6, 6, 6, 7, 8, 9, 10, 10, 10,
11, 11, 11, 12, 13, 14, 15, 15, 15,
16, 16, 16, 17, 18, 19, 20, 20, 20,
16, 16, 16, 17, 18, 19, 20, 20, 20,
16, 16, 16, 17, 18, 19, 20, 20, 20
};
for (int i = 0; i < c * r; ++i)
mln_assertion(ima[i] == vs[i]);
std::cerr << "OK" << std::endl;
}
{
(std::cerr << "Test border::mirror on int_s8 with border = 1 ... ").flush ();
typedef value::int_s8 T;
int border = 1;
int row = 4;
int col = 5;
int r = row + 2 * border;
int c = col + 2 * border;
image2d<T> ima(row, col, border);
debug::iota (ima);
border::duplicate (ima);
T vs[49] =
{
1, 1, 2, 3, 4, 5, 5,
1, 1, 2, 3, 4, 5, 5,
6, 6, 7, 8, 9, 10, 10,
11, 11, 12, 13, 14, 15, 15,
16, 16, 17, 18, 19, 20, 20,
16, 16, 17, 18, 19, 20, 20
};
for (int i = 0; i < c * r; ++i)
mln_assertion(ima[i] == vs[i]);
std::cerr << "OK" << std::endl;
}
{
(std::cerr << "Test border::mirror on int with border = 0 ... ").flush ();
typedef int T;
int border = 0;
int row = 4;
int col = 5;
int r = row + 2 * border;
int c = col + 2 * border;
image2d<T> ima(row, col, border);
debug::iota (ima);
border::duplicate (ima);
T vs[20] =
{
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15,
16, 17, 18, 19, 20
};
for (int i = 0; i < c * r; ++i)
mln_assertion(ima[i] == vs[i]);
std::cerr << "OK" << std::endl;
}
}
// 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/border_fill/test_border_fill_image2d_1.cc
*
* \brief Tests on mln::border::fill.
*/
#include <mln/border/fill.hh>
#include <mln/level/fill.hh>
#include <mln/core/image1d.hh>
#include <mln/core/image2d.hh>
#include <mln/core/image3d.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
#include <mln/value/int_s8.hh>
#include <mln/value/int_s16.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/rgb16.hh>
#include <mln/value/float01_8.hh>
#include <mln/value/float01_16.hh>
#include <mln/debug/println_with_border.hh>
using namespace mln;
template <typename T>
int
check1d(unsigned row, unsigned border, T& value, T& v)
{
image1d<T> ima(row, border);
level::fill (ima, v);
border::fill (ima, value);
unsigned i = 0;
for(i = 0; i < border; ++i)
mln_assertion (ima[i] == value);
unsigned bo = border + row;
for(; i < bo; ++i)
mln_assertion (ima[i] == v);
bo += border;
for(; i < bo; ++i)
mln_assertion (ima[i] == value);
}
template <typename T>
int
check2d(unsigned row, unsigned col, unsigned border, T& value, T& v)
{
image2d<T> ima(row, col, border);
level::fill (ima, v);
border::fill (ima, value);
unsigned c = col + 2 * border;
unsigned r = row + 2 * border;
unsigned bo = c * border + border;
unsigned i = 0;
unsigned u = col + border;
unsigned ww = r * c;
for(i = 0; i < bo; ++i)
mln_assertion (ima[i] == value);
bo += c * row;
for(; i < bo; ++i)
{
unsigned cur = i % c;
if (cur < border || cur >= u)
mln_assertion (ima[i] == value);
else
mln_assertion (ima[i] == v);
}
for(; i < ww; ++i)
mln_assertion (ima[i] == value);
}
template <typename T>
int
check3d(unsigned sli, unsigned row, unsigned col, unsigned border, T& value, T& v)
{
image3d<T> ima(sli, row, col, border);
level::fill (ima, v);
border::fill (ima, value);
unsigned c = col + 2 * border;
unsigned r = row + 2 * border;
unsigned bo = c * border + border;
unsigned i = 0;
unsigned u = col + border;
unsigned ww = r * c;
for(i = 0; i < bo; ++i)
mln_assertion (ima[i] == value);
bo += c * row;
for(; i < bo; ++i)
{
unsigned cur = i % c;
if (cur < border || cur >= u)
mln_assertion (ima[i] == value);
else
mln_assertion (ima[i] == v);
}
for(; i < ww; ++i)
mln_assertion (ima[i] == value);
}
int
main (void)
{
int limits = 10;
{
std::cerr << "Tests border::fill on int:" << std::endl;
typedef int T;
T value = (T) -1;
T v = 42;
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on unsigned:" << std::endl;
typedef unsigned T;
T value = (T) -1;
T v = 42;
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on int_u8 ... " << std::endl;
typedef value::int_u8 T;
T value = 255;
T v = 42;
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on int_u16 ... " << std::endl;
typedef value::int_u16 T;
T value = 65535;
T v = 42;
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on int_s8 ... " << std::endl;
typedef value::int_s8 T;
T value = 127;
T v = 42;
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on int_s16 ... " << std::endl;
typedef value::int_s16 T;
T value = 32767;
T v = 42;
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on rgb8 ... " << std::endl;
typedef value::rgb8 T;
T value = T(255, 255, 255);
T v = T(42, 0, 0);
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}
{
std::cerr << "Tests border::fill on rgb16:" << std::endl;
typedef value::rgb16 T;
T value = T(65535, 65535, 65535);
T v = T(42, 0, 0);
(std::cerr << "in 1d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
check1d(i, j, value, v);
std::cerr << "OK" << std::endl;
(std::cerr << "in 2d ... ").flush ();
for (int i = 1; i < limits; ++i)
for (int j = 1; j < limits; ++j)
for (int k = 1; k < limits; ++k)
check2d(i, j, k, value, v);
std::cerr << "OK" << std::endl;
}