3662: Add new tests.

* tests/make/Makefile.am, * tests/core/image/vertex_image.cc, * tests/make/dummy_p_edges.cc, * tests/make/dummy_p_vertices.cc, * tests/make/p_edges_with_mass_centers.cc, * tests/make/p_vertices_with_mass_centers.cc: new test for the newly added routines. --- milena/ChangeLog | 12 + milena/tests/core/image/vertex_image.cc | 231 ++++++++++++++------- milena/tests/make/Makefile.am | 8 + milena/tests/make/dummy_p_edges.cc | 75 +++++++ milena/tests/make/dummy_p_vertices.cc | 75 +++++++ milena/tests/make/p_edges_with_mass_centers.cc | 86 ++++++++ milena/tests/make/p_vertices_with_mass_centers.cc | 84 ++++++++ 7 files changed, 499 insertions(+), 72 deletions(-) create mode 100644 milena/tests/make/dummy_p_edges.cc create mode 100644 milena/tests/make/dummy_p_vertices.cc create mode 100644 milena/tests/make/p_edges_with_mass_centers.cc create mode 100644 milena/tests/make/p_vertices_with_mass_centers.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 0b743d3..0e13e64 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,17 @@ 2009-04-14 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add new tests. + + * tests/make/Makefile.am, + * tests/core/image/vertex_image.cc, + * tests/make/dummy_p_edges.cc, + * tests/make/dummy_p_vertices.cc, + * tests/make/p_edges_with_mass_centers.cc, + * tests/make/p_vertices_with_mass_centers.cc: new test for the newly + added routines. + +2009-04-14 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add small routines to help while constructing graph images. * mln/make/dummy_p_edges.hh, diff --git a/milena/tests/core/image/vertex_image.cc b/milena/tests/core/image/vertex_image.cc index 3531420..8dcd980 100644 --- a/milena/tests/core/image/vertex_image.cc +++ b/milena/tests/core/image/vertex_image.cc @@ -32,6 +32,7 @@ #include <vector> #include <mln/core/image/vertex_image.hh> +#include <mln/make/vertex_image.hh> #include <mln/core/image/image2d.hh> #include <mln/accu/bbox.hh> @@ -113,113 +114,199 @@ int main() for (unsigned i = 0; i < iota.size(); ++i) iota(i) = 10 + i; - typedef vertex_image<point2d,unsigned> ima_t; - ima_t ima(g, sites, iota); + + + /// Vertices are associated to image sites. { - // FIXME: Move this part to a special test case. + typedef vertex_image<point2d,unsigned> ima_t; + ima_t ima = make::vertex_image(g, sites, iota); + + { + // FIXME: Move this part to a special test case. + + // Compute the bounding box of 'ima'. + accu::bbox<point2d> a; + mln_piter_(ima_t) p(ima.domain()); + for_all(p) + a.take(p); + box2d bbox = a.to_result(); + mln_assertion(bbox == make::box2d(5, 5)); + + // Print the image. + /* FIXME: Unfortunately, displaying graph images is not easy right + now(2008-02-05). We could use + + debug::println(ima); + + but there's not specialization working for graph_image; the one + selected by the compiler is based on a 2-D bbox, and expects the + interface of graph_image to work with points(not psites). + Moreover, this implementation only shows *values*, not the graph + itslef. + + An alternative is to use debug::graph, + but it doesn't show the values, only the vertices and edges of the + graph. + + The current solution is a mix between debug::graph and hand-made + iterations. */ + image2d<int> ima_rep(bbox); + + // We use the value 9 in debug::graph to represent edges to distinguish it + // from vertices holding a value of 1. + debug::draw_graph(ima_rep, ima.domain(), 1, 9); + } - // Compute the bounding box of 'ima'. - accu::bbox<point2d> a; + /*------------. + | Iterators. | + `------------*/ + + // iteration over the domain of IMA. mln_piter_(ima_t) p(ima.domain()); + unsigned i = 10; for_all(p) - a.take(p); - box2d bbox = a.to_result(); - mln_assertion(bbox == make::box2d(5, 5)); + mln_assertion(ima(p) == i++); - // Print the image. - /* FIXME: Unfortunately, displaying graph images is not easy right - now(2008-02-05). We could use + typedef ima_t::win_t win_t; + win_t win; - debug::println(ima); + { + // Window - Forward iteration + mln_qiter_(win_t) q(win, p); + for_all(p) + { + i = 0; + for_all(q) + { + mln_assertion(expected_fwd_nb[p.id()][i] == q.id()); + ++i; + } + } + } - but there's not specialization working for graph_image; the one - selected by the compiler is based on a 2-D bbox, and expects the - interface of graph_image to work with points(not psites). - Moreover, this implementation only shows *values*, not the graph - itslef. + { + // Window - Backward iteration + mln_bkd_qiter_(win_t) q(win, p); + for_all(p) + { + i = 0; + for_all(q) + { + mln_assertion(expected_bkd_nb[p.id()][i] == q.id()); + ++i; + } + } + } - An alternative is to use debug::graph, - but it doesn't show the values, only the vertices and edges of the - graph. + typedef ima_t::nbh_t nbh_t; + nbh_t neigh; + { + // Neighborhood - Forward iteration + mln_niter_(nbh_t) n(neigh, p); - The current solution is a mix between debug::graph and hand-made - iterations. */ - image2d<int> ima_rep(bbox); + for_all(p) + { + i = 0; + for_all(n) + { + mln_assertion(expected_fwd_nb[p.id()][i] == n.id()); + ++i; + } + } + } - // We use the value 9 in debug::graph to represent edges to distinguish it - // from vertices holding a value of 1. - debug::draw_graph(ima_rep, ima.domain(), 1, 9); + { + // Neighborhood - Backward iteration + mln_bkd_niter_(nbh_t) n(neigh, p); + for_all(p) + { + i = 0; + for_all(n) + { + mln_assertion(expected_bkd_nb[p.id()][i] == n.id()); + ++i; + } + } + } } - /*------------. - | Iterators. | - `------------*/ - // iteration over the domain of IMA. - mln_piter_(ima_t) p(ima.domain()); - unsigned i = 10; - for_all(p) - mln_assertion(ima(p) == i++); - typedef ima_t::win_t win_t; - win_t win; + /// Vertices do not have image site information. + /// The associated sites are the vertex themselves. { - // Window - Forward iteration - mln_qiter_(win_t) q(win, p); + typedef vertex_image<void,unsigned> ima_void_t; + ima_void_t ima_void(g, iota); + + // iteration over the domain of IMA. + mln_piter_(ima_void_t) p(ima_void.domain()); + unsigned i = 10; for_all(p) + mln_assertion(ima_void(p) == i++); + + typedef ima_void_t::win_t win_t; + win_t win; + { - i = 0; - for_all(q) + // Window - Forward iteration + mln_qiter_(win_t) q(win, p); + for_all(p) { - mln_assertion(expected_fwd_nb[p.id()][i] == q.id()); - ++i; + i = 0; + for_all(q) + { + mln_assertion(expected_fwd_nb[p.id()][i] == q.id()); + ++i; + } } } - } - { - // Window - Backward iteration - mln_bkd_qiter_(win_t) q(win, p); - for_all(p) { - i = 0; - for_all(q) + // Window - Backward iteration + mln_bkd_qiter_(win_t) q(win, p); + for_all(p) { - mln_assertion(expected_bkd_nb[p.id()][i] == q.id()); - ++i; + i = 0; + for_all(q) + { + mln_assertion(expected_bkd_nb[p.id()][i] == q.id()); + ++i; + } } } - } - typedef ima_t::nbh_t nbh_t; - nbh_t neigh; - { - // Neighborhood - Forward iteration - mln_niter_(nbh_t) n(neigh, p); - - for_all(p) + typedef ima_void_t::nbh_t nbh_t; + nbh_t neigh; { - i = 0; - for_all(n) + // Neighborhood - Forward iteration + mln_niter_(nbh_t) n(neigh, p); + + for_all(p) { - mln_assertion(expected_fwd_nb[p.id()][i] == n.id()); - ++i; + i = 0; + for_all(n) + { + //FIXME: Ambiguities with n.id()!!!! + mln_assertion(expected_fwd_nb[p.id()][i] == n.element().id()); + ++i; + } } } - } - { - // Neighborhood - Backward iteration - mln_bkd_niter_(nbh_t) n(neigh, p); - for_all(p) { - i = 0; - for_all(n) + // Neighborhood - Backward iteration + mln_bkd_niter_(nbh_t) n(neigh, p); + for_all(p) { - mln_assertion(expected_bkd_nb[p.id()][i] == n.id()); - ++i; + i = 0; + for_all(n) + { + //FIXME: Ambiguities with n.id()!!!! + mln_assertion(expected_bkd_nb[p.id()][i] == n.element().id()); + ++i; + } } } } diff --git a/milena/tests/make/Makefile.am b/milena/tests/make/Makefile.am index 7e4c12b..ba517cd 100644 --- a/milena/tests/make/Makefile.am +++ b/milena/tests/make/Makefile.am @@ -4,22 +4,30 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ dual_neighb \ + dummy_p_edges \ + dummy_p_vertices \ graph \ h_mat \ image2d \ image3d \ mat \ + p_edges_with_mass_centers \ + p_vertices_with_mass_centers \ region_adjacency_graph \ rag_and_labeled_wsl \ w_window \ w_window_directional dual_neighb_SOURCES = dual_neighb.cc +dummy_p_edges_SOURCES = dummy_p_edges.cc +dummy_p_vertices_SOURCES = dummy_p_vertices.cc graph_SOURCES = graph.cc h_mat_SOURCES = h_mat.cc image2d_SOURCES = image2d.cc image3d_SOURCES = image3d.cc mat_SOURCES = mat.cc +p_edges_with_mass_centers_SOURCES = p_edges_with_mass_centers.cc +p_vertices_with_mass_centers_SOURCES = p_vertices_with_mass_centers.cc region_adjacency_graph_SOURCES = region_adjacency_graph.cc rag_and_labeled_wsl_SOURCES = rag_and_labeled_wsl.cc w_window_SOURCES = w_window.cc diff --git a/milena/tests/make/dummy_p_edges.cc b/milena/tests/make/dummy_p_edges.cc new file mode 100644 index 0000000..b04e6d4 --- /dev/null +++ b/milena/tests/make/dummy_p_edges.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/make/dummy_p_edges.cc +/// +/// Tests on mln::make::dummy_p_edges. + + +#include <mln/core/image/image2d.hh> +#include <mln/core/site_set/p_array.hh> + +#include <mln/util/graph.hh> + +#include <mln/value/label_8.hh> + +#include <mln/make/dummy_p_edges.hh> + +int main() +{ + using namespace mln; + + typedef util::graph G; + G g; + g.add_vertices(5); + g.add_edge(1,2); + g.add_edge(1,3); + g.add_edge(4,3); + g.add_edge(4,2); + + { + typedef p_edges<G, pw::cst_<int> > pe_t; + pe_t pe = make::dummy_p_edges(g); + + mln_assertion(pe.nsites() == 4); + mln_piter_(pe_t) p(pe); + for_all(p) + mln_assertion(p == 0); + } + + { + typedef p_edges<G, pw::cst_<point2d> > pe_t; + pe_t pe = make::dummy_p_edges(g, point2d::plus_infty()); + + mln_assertion(pe.nsites() == 4); + mln_piter_(pe_t) p(pe); + for_all(p) + mln_assertion(p == point2d::plus_infty()); + } + +} + diff --git a/milena/tests/make/dummy_p_vertices.cc b/milena/tests/make/dummy_p_vertices.cc new file mode 100644 index 0000000..6cfa2b8 --- /dev/null +++ b/milena/tests/make/dummy_p_vertices.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/make/dummy_p_vertices.cc +/// +/// Tests on mln::make::dummy_p_vertices. + + +#include <mln/core/image/image2d.hh> +#include <mln/core/site_set/p_array.hh> + +#include <mln/util/graph.hh> + +#include <mln/value/label_8.hh> + +#include <mln/make/dummy_p_vertices.hh> + +int main() +{ + using namespace mln; + + typedef util::graph G; + G g; + g.add_vertices(5); + g.add_edge(1,2); + g.add_edge(1,3); + g.add_edge(4,3); + g.add_edge(4,2); + + { + typedef p_vertices<G, pw::cst_<int> > pe_t; + pe_t pe = make::dummy_p_vertices(g); + + mln_assertion(pe.nsites() == 4); + mln_piter_(pe_t) p(pe); + for_all(p) + mln_assertion(p == 0); + } + + { + typedef p_vertices<G, pw::cst_<point2d> > pe_t; + pe_t pe = make::dummy_p_vertices(g, point2d::plus_infty()); + + mln_assertion(pe.nsites() == 4); + mln_piter_(pe_t) p(pe); + for_all(p) + mln_assertion(p == point2d::plus_infty()); + } + +} + diff --git a/milena/tests/make/p_edges_with_mass_centers.cc b/milena/tests/make/p_edges_with_mass_centers.cc new file mode 100644 index 0000000..967320c --- /dev/null +++ b/milena/tests/make/p_edges_with_mass_centers.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/make/p_edges_with_mass_centers.cc +/// +/// Tests on mln::make::p_edges_with_mass_centers. + + +#include <mln/core/image/image2d.hh> +#include <mln/core/site_set/p_array.hh> + +#include <mln/util/graph.hh> + +#include <mln/value/label_8.hh> + +#include <mln/make/p_edges_with_mass_centers.hh> + +#include <mln/util/site_pair.hh> + +int main() +{ + using namespace mln; + + typedef value::label_8 L; + + L data[] = { + 1, 1, 1, 0, 2, 2, 2, + 1, 1, 1, 0, 2, 2, 2, + 1, 1, 1, 0, 2, 2, 2, + 0, 0, 0, 0, 0, 0, 0, + 3, 3, 3, 0, 4, 4, 4, + 3, 3, 3, 0, 4, 4, 4, + 3, 3, 3, 0, 4, 4, 4 + }; + + image2d<L> wst = make::image2d(data); + typedef util::graph G; + G g; + g.add_vertices(5); + g.add_edge(1,2); + g.add_edge(1,3); + g.add_edge(4,3); + g.add_edge(4,2); + + L nbasins = 4; + typedef p_edges<G,fun::i2v::array<util::site_pair<point2d> > > pe_t; + pe_t pe = make::p_edges_with_mass_centers(wst, nbasins, g); + + typedef util::site_pair<point2d> P; + typedef p_array<P> arr_t; + arr_t arr; + arr.insert(P(point2d(1,1), point2d(1,5))); + arr.insert(P(point2d(1,1), point2d(5,1))); + arr.insert(P(point2d(5,1), point2d(5,5))); + arr.insert(P(point2d(1,5), point2d(5,5))); + + mln_piter_(pe_t) p1(pe); + mln_piter_(arr_t) p2(arr); + for_all_2(p1,p2) + mln_assertion(p1 == p2); +} + diff --git a/milena/tests/make/p_vertices_with_mass_centers.cc b/milena/tests/make/p_vertices_with_mass_centers.cc new file mode 100644 index 0000000..2d103df --- /dev/null +++ b/milena/tests/make/p_vertices_with_mass_centers.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/make/p_vertices_with_mass_centers.cc +/// +/// Tests on mln::make::p_vertices_with_mass_centers. + + +#include <mln/core/image/image2d.hh> +#include <mln/core/site_set/p_array.hh> + +#include <mln/util/graph.hh> + +#include <mln/value/label_8.hh> + +#include <mln/make/p_vertices_with_mass_centers.hh> + +int main() +{ + using namespace mln; + + typedef value::label_8 L; + + L data[] = { + 1, 1, 1, 0, 2, 2, 2, + 1, 1, 1, 0, 2, 2, 2, + 1, 1, 1, 0, 2, 2, 2, + 0, 0, 0, 0, 0, 0, 0, + 3, 3, 3, 0, 4, 4, 4, + 3, 3, 3, 0, 4, 4, 4, + 3, 3, 3, 0, 4, 4, 4 + }; + + image2d<L> wst = make::image2d(data); + typedef util::graph G; + G g; + g.add_vertices(5); + g.add_edge(1,2); + g.add_edge(1,3); + g.add_edge(4,3); + g.add_edge(4,2); + + L nbasins = 4; + typedef p_vertices<G,fun::i2v::array<point2d> > pv_t; + pv_t pv = make::p_vertices_with_mass_centers(wst, nbasins, g); + + typedef p_array<point2d> arr_t; + arr_t arr; + arr.insert(point2d(3,3)); + arr.insert(point2d(1,1)); + arr.insert(point2d(1,5)); + arr.insert(point2d(5,1)); + arr.insert(point2d(5,5)); + + mln_piter_(pv_t) p1(pv); + mln_piter_(arr_t) p2(arr); + for_all_2(p1,p2) + mln_assertion(p1 == p2); +} + -- 1.5.6.5
participants (1)
-
Guillaume Lazzara