Add the testsuite for Triangulation_2, factorize it with T_3

I have added the file
`Testsuite/include/CGAL/Testsuite/Triangulation_23/test_move_semantic.h`
so that is can be reused in the tests for `Triangulation_2` and
`Triangulation_3`.

So far, the tests in `test_delaunay_hierarchy_2.cpp` fail...
This commit is contained in:
Laurent Rineau 2021-02-03 12:47:33 +01:00
parent e6fe1c2031
commit cbc73a8fc4
5 changed files with 100 additions and 101 deletions

View File

@ -0,0 +1,69 @@
// Copyright (c) 2021 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Laurent Rineau
//
#include <cassert>
namespace CGAL {
namespace Testsuite {
namespace Triangulation_23 {
template <typename Tr>
void test_move_semantic(Tr source_tr) {
const auto dimension = source_tr.dimension();
const auto nb_of_vertices = source_tr.number_of_vertices();
auto check_triangulation_validity = [&](const Tr& tr) {
assert(tr.is_valid());
assert(tr.number_of_vertices() == nb_of_vertices);
assert(tr.dimension() == dimension);
};
auto check_moved_from_triangulation = [](const Tr& tr_copy) {
assert(tr_copy.dimension() == -2);
assert(tr_copy.number_of_vertices() + 1 == 0);
};
auto check_empty_triangulation = [](const Tr& tr_copy2) {
assert(tr_copy2.dimension() == -1);
assert(tr_copy2.number_of_vertices() == 0);
};
// move constructor
{
Tr tr_copy(source_tr);
check_triangulation_validity(tr_copy);
Tr tr_move_constructed(std::move(tr_copy));
check_triangulation_validity(tr_move_constructed);
check_moved_from_triangulation(tr_copy);
Tr tr_copy2(source_tr);
Tr tr_move_constructed2(std::move(tr_copy2));
check_moved_from_triangulation(tr_copy2);
tr_copy2.clear();
check_empty_triangulation(tr_copy2);
Tr tr_copy3(source_tr);
Tr tr_move_constructed3(std::move(tr_copy3));
check_moved_from_triangulation(tr_copy3);
tr_copy3 = source_tr;
check_triangulation_validity(tr_copy3);
}
// move-assignment
{
Tr tr_copy4(source_tr);
Tr tr_move_assigned;
tr_move_assigned = std::move(tr_copy4);
check_triangulation_validity(tr_move_assigned);
check_moved_from_triangulation(tr_copy4);
}
};
}
}
}

View File

@ -31,6 +31,7 @@
#include <CGAL/_test_fct_is_infinite.h>
#include <CGAL/_test_triangulation_iterators.h>
#include <CGAL/_test_triangulation_circulators.h>
#include <CGAL/Testsuite/Triangulation_23/test_move_semantic.h>
template <class Triangul>
@ -281,6 +282,15 @@ _test_cls_triangulation_short_2( const Triangul &)
assert( T2_3_4.number_of_vertices() == 11 );
assert( T2_3_4.is_valid() );
/****************************/
/******* MOVE SEMANTIC*******/
std::cout << " move constructors and move assignment" << std::endl;
namespace test_tr_23 = CGAL::Testsuite::Triangulation_23;
test_tr_23::test_move_semantic(T0_1);
test_tr_23::test_move_semantic(T1_5);
test_tr_23::test_move_semantic(T2_8);
test_tr_23::test_move_semantic(T2_3);
/*********************************************/
/****** FINITE/INFINITE VERTICES/FACES *******/

View File

@ -31,6 +31,7 @@
#include <CGAL/Random.h>
#include <CGAL/Testsuite/use.h>
#include <CGAL/internal/Has_nested_type_Bare_point.h>
#include <CGAL/Testsuite/Triangulation_23/test_move_semantic.h>
// Accessory set of functions to differentiate between
// Delaunay::nearest_vertex[_in_cell] and
@ -421,41 +422,8 @@ _test_cls_delaunay_3(const Triangulation &)
assert(T1.number_of_vertices() == 0);
assert(T1.is_valid());
// move constructor
{
Cls T_copy(T0);
assert(T_copy.dimension() == 3);
assert(T_copy.number_of_vertices() == 4);
assert(T_copy.is_valid());
Cls T_move_constructed(std::move(T_copy));
assert(T_move_constructed.dimension() == 3);
assert(T_move_constructed.number_of_vertices() == 4);
assert(T_move_constructed.is_valid());
assert(T_copy.dimension() == -2);
assert(T_copy.number_of_vertices() + 1 == 0);
Cls T_copy2(T0);
Cls T_move_constructed2(std::move(T_copy2));
T_copy2.clear();
assert(T_copy2 == Cls());
Cls T_copy3(T0);
Cls T_move_constructed3(std::move(T_copy3));
T_copy3 = T0;
assert(T_copy3 == T0);
}
// move-assignment
{
Cls T_copy4(T0);
Cls T_move_assigned;
T_move_assigned = std::move(T_copy4);
assert(T_copy4.dimension() == -2);
assert(T_copy4.number_of_vertices() + 1 == 0);
assert(T_move_assigned.dimension() == 3);
assert(T_move_assigned.number_of_vertices() == 4);
assert(T_move_assigned.is_valid());
assert(T_move_assigned == T0);
}
namespace test_tr_23 = CGAL::Testsuite::Triangulation_23;
test_tr_23::test_move_semantic(T0);
// Affectation :
T1=T0;
@ -488,6 +456,7 @@ _test_cls_delaunay_3(const Triangulation &)
assert(T1_0.dimension()==1);
assert(T1_0.number_of_vertices()==n);
assert(T1_0.is_valid());
test_tr_23::test_move_semantic(T1_0);
std::cout << " Constructor7 " << std::endl;
Cls T1_1;
n = T1_1.insert(l2.begin(),l2.end());
@ -548,6 +517,8 @@ _test_cls_delaunay_3(const Triangulation &)
assert(T2_0.dimension()==2);
assert(T2_0.number_of_vertices()==8);
test_tr_23::test_move_semantic(T2_0);
{
Cls Tfromfile;
std::cout << " I/O" << std::endl;
@ -596,6 +567,8 @@ _test_cls_delaunay_3(const Triangulation &)
assert(T3_0.number_of_vertices()==125);
assert(T3_0.dimension()==3);
test_tr_23::test_move_semantic(T3_0);
if (del) {
std::cout << " deletion in Delaunay - grid case - (dim 3) " <<
std::endl;

View File

@ -17,6 +17,8 @@
#include <list>
#include <type_traits>
#include <CGAL/use.h>
#include <CGAL/Testsuite/Triangulation_23/test_move_semantic.h>
template <class Triangulation>
void
_test_cls_regular_3(const Triangulation &)
@ -206,35 +208,6 @@ _test_cls_regular_3(const Triangulation &)
assert(T.is_valid());
assert(T.dimension()==3);
// move constructor
{
Triangulation T_copy(T);
assert(T_copy == T);
assert(T_copy == T);
Triangulation T_move_constructed(std::move(T_copy));
assert(T_move_constructed == T);
assert(T_copy.dimension() == -2);
assert(T_copy.number_of_vertices() + 1 == 0);
Cls T_copy2(T);
Cls T_move_constructed2(std::move(T_copy2));
T_copy2.clear();
assert(T_copy2 == Cls());
Cls T_copy3(T);
Cls T_move_constructed3(std::move(T_copy3));
T_copy3 = T;
assert(T_copy3 == T);
}
// move-assignment
{
Cls T_copy4(T);
Cls T_move_assigned;
T_move_assigned = std::move(T_copy4);
assert(T_copy4.dimension() == -2);
assert(T_copy4.number_of_vertices() + 1 == 0);
assert(T_move_assigned.dimension() == 3);
assert(T_move_assigned.is_valid());
assert(T_move_assigned == T);
}
namespace test_tr_23 = CGAL::Testsuite::Triangulation_23;
test_tr_23::test_move_semantic(T);
}

View File

@ -23,6 +23,7 @@
#include <CGAL/Random.h>
#include <CGAL/Testsuite/use.h>
#include <CGAL/use.h>
#include <CGAL/Testsuite/Triangulation_23/test_move_semantic.h>
template <class Triangulation, class Container>
bool check_all_are_finite(Triangulation* tr, const Container& cont)
@ -286,41 +287,8 @@ _test_cls_triangulation_3(const Triangulation &)
assert(T1.number_of_vertices() == 0);
assert(T1.is_valid());
// move constructor
{
Cls T_copy(T0);
assert(T_copy.dimension() == 3);
assert(T_copy.number_of_vertices() == 4);
assert(T_copy.is_valid());
Cls T_move_constructed(std::move(T_copy));
assert(T_move_constructed.dimension() == 3);
assert(T_move_constructed.number_of_vertices() == 4);
assert(T_move_constructed.is_valid());
assert(T_copy.dimension() == -2);
assert(T_copy.number_of_vertices() + 1 == 0);
Cls T_copy2(T0);
Cls T_move_constructed2(std::move(T_copy2));
T_copy2.clear();
assert(T_copy2 == Cls());
Cls T_copy3(T0);
Cls T_move_constructed3(std::move(T_copy3));
T_copy3 = T0;
assert(T_copy3 == T0);
}
// move-assignment
{
Cls T_copy4(T0);
Cls T_move_assigned;
T_move_assigned = std::move(T_copy4);
assert(T_copy4.dimension() == -2);
assert(T_copy4.number_of_vertices() + 1 == 0);
assert(T_move_assigned.dimension() == 3);
assert(T_move_assigned.number_of_vertices() == 4);
assert(T_move_assigned.is_valid());
assert(T_move_assigned == T0);
}
namespace test_tr_23 = CGAL::Testsuite::Triangulation_23;
test_tr_23::test_move_semantic(T0);
// Assignment
T1=T0;
@ -397,12 +365,14 @@ _test_cls_triangulation_3(const Triangulation &)
assert(T2_0.dimension()==1);
assert(T2_0.number_of_vertices()==3);
test_tr_23::test_move_semantic(T2_0);
v0=T2_0.insert(p4);
assert(T2_0.is_valid());
assert(T2_0.dimension()==2);
assert(T2_0.number_of_vertices()==4);
test_tr_23::test_move_semantic(T2_0);
v0=T2_0.insert(p5);
v0=T2_0.insert(p6);
@ -414,6 +384,8 @@ _test_cls_triangulation_3(const Triangulation &)
assert(T2_0.dimension()==2);
assert(T2_0.number_of_vertices()==8);
test_tr_23::test_move_semantic(T2_0);
if (! del) // to avoid doing the following tests for both Delaunay
// and non Delaunay triangulations
{
@ -437,6 +409,8 @@ _test_cls_triangulation_3(const Triangulation &)
assert( T2_1.dimension()==2 );
assert( T2_1.is_valid() );
test_tr_23::test_move_semantic(T2_1);
std::cout << " Constructor11 " << std::endl;
// 3-dimensional triangulations
// This is a simple grid :