diff --git a/test/test_common/CMakeLists.txt b/test/test_common/CMakeLists.txt index 12dfc0122..80caaeb04 100644 --- a/test/test_common/CMakeLists.txt +++ b/test/test_common/CMakeLists.txt @@ -1,51 +1,49 @@ #=============================================================================== # @file CMakeLists.txt # # @author Nicolas Richart # # @date creation: Fri Sep 03 2010 # @date last modification: Mon Dec 07 2015 # # @brief configurations for common tests # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu 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 Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== -add_akantu_test(test_vector "Test akantu vector") +#add_akantu_test(test_vector "Test akantu vector") add_mesh(test_grid_mesh circle.geo 2 1) -register_test(test_csr test_csr.cc PACKAGE core) register_test(test_grid test_grid.cc DEPENDS test_grid_mesh PACKAGE core) -register_test(test_math test_math.cc PACKAGE core) -register_test(test_types test_types.cc PACKAGE core) +#register_test(test_math test_math.cc PACKAGE core) +#register_test(test_types test_types.cc PACKAGE core) - -register_test(test_arange_iterator test_arange_iterator.cc PACKAGE core) - -register_gtest_sources(test_zip_iterator.cc PACKAGE core) +register_gtest_sources(SOURCES test_csr.cc PACKAGE core) +register_gtest_sources(SOURCES test_arange_iterator.cc PACKAGE core) +register_gtest_sources(SOURCES test_zip_iterator.cc PACKAGE core) register_gtest_sources(SOURCES test_array.cc PACKAGE core) register_gtest_sources(SOURCES test_tensors.cc PACKAGE core) register_gtest_test(test_common) diff --git a/test/test_common/test_arange_iterator.cc b/test/test_common/test_arange_iterator.cc index 94463e101..62b3d13f2 100644 --- a/test/test_common/test_arange_iterator.cc +++ b/test/test_common/test_arange_iterator.cc @@ -1,48 +1,69 @@ /** * @file test_arange_iterator.cc * * @author Nicolas Richart * * @date creation Fri Aug 11 2017 * * @brief A Documented file. * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "aka_iterators.hh" /* -------------------------------------------------------------------------- */ -#include +#include /* -------------------------------------------------------------------------- */ using namespace akantu; -int main() { - for (auto i : arange(10)) - std::cout << i << std::endl; +TEST(TestArangeIterator, Stop) { + size_t ref_i = 0; + for (auto i : arange(10)) { + EXPECT_EQ(ref_i, i); + ++ref_i; + } +} - for (auto i : arange(1, 22, 2)) - std::cout << i << std::endl; +TEST(TestArangeIterator, StartStop) { + size_t ref_i = 1; + for (auto i : arange(1, 10)) { + EXPECT_EQ(ref_i, i); + ++ref_i; + } +} - for (auto && i : zip(arange(-1, -10, -1), arange(1, 18, 2))) - std::cout << std::get<0>(i) << " " << std::get<1>(i) << std::endl; +TEST(TestArangeIterator, StartStopStep) { + size_t ref_i = 1; + for (auto i : arange(1, 22, 2)) { + EXPECT_EQ(ref_i, i); + ref_i += 2; + } +} - return 0; +TEST(TestArangeIterator, StartStopStepZipped) { + int ref_i1 = -1, ref_i2 = 1; + for (auto && i : zip(arange(-1, -10, -1), arange(1, 18, 2))) { + EXPECT_EQ(ref_i1, std::get<0>(i)); + EXPECT_EQ(ref_i2, std::get<1>(i)); + ref_i1 += -1; + ref_i2 += 2; + } } diff --git a/test/test_common/test_csr.cc b/test/test_common/test_csr.cc index 7a4d13232..a04264867 100644 --- a/test/test_common/test_csr.cc +++ b/test/test_common/test_csr.cc @@ -1,117 +1,105 @@ /** * @file test_csr.cc * * @author Nicolas Richart * * @date creation: Mon Jul 30 2012 * @date last modification: Sun Oct 19 2014 * * @brief Test the CSR (compressed sparse row) data structure * * @section LICENSE * * Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ -#include - -#include "aka_common.hh" #include "aka_csr.hh" +/* -------------------------------------------------------------------------- */ +#include +/* -------------------------------------------------------------------------- */ using namespace akantu; -#define N 1000 - -int main() { - - CSR csr; - - std::vector nb_cols_per_row; - - csr.resizeRows(N); - csr.clearRows(); - - for (UInt i = 0; i < N; ++i) { - UInt nb_cols(UInt(rand() * double(N) / (RAND_MAX + 1.))); - nb_cols_per_row.push_back(nb_cols); - for (UInt j = 0; j < nb_cols; ++j) { - ++csr.rowOffset(i); +class TestCsrFixture : public ::testing::Test { +protected: + void SetUp() override { + csr.resizeRows(N); + csr.clearRows(); + + for (UInt i = 0; i < N; ++i) { + UInt nb_cols(UInt(rand() * double(N) / (RAND_MAX + 1.))); + nb_cols_per_row.push_back(nb_cols); + for (UInt j = 0; j < nb_cols; ++j) { + ++csr.rowOffset(i); + } } - } - csr.countToCSR(); - csr.resizeCols(); + csr.countToCSR(); + csr.resizeCols(); - csr.beginInsertions(); - for (UInt i = 0; i < N; ++i) { - UInt nb_cols = nb_cols_per_row[i]; - for (UInt j = 0; j < nb_cols; ++j) { - csr.insertInRow(i, nb_cols - j); + csr.beginInsertions(); + for (UInt i = 0; i < N; ++i) { + UInt nb_cols = nb_cols_per_row[i]; + for (UInt j = 0; j < nb_cols; ++j) { + csr.insertInRow(i, nb_cols - j); + } } + csr.endInsertions(); } - csr.endInsertions(); - if (csr.getNbRows() != N) { - AKANTU_DEBUG_ERROR("The number of rows does not correspond: " - << csr.getNbRows() << " != " << N); - } + std::vector nb_cols_per_row; + CSR csr; + size_t N = 1000; +}; - for (UInt i = 0; i < csr.getNbRows(); ++i) { - CSR::iterator it = csr.begin(i); - CSR::iterator end = csr.end(i); - UInt nb_cols = nb_cols_per_row[i]; +TEST_F(TestCsrFixture, CheckInsertion) { + EXPECT_EQ(N, this->csr.getNbRows()); +} + +TEST_F(TestCsrFixture, Iteration) { + for (UInt i = 0; i < this->csr.getNbRows(); ++i) { + auto it = this->csr.begin(i); + auto end = this->csr.end(i); + UInt nb_cols = this->nb_cols_per_row[i]; for (; it != end; ++it) { - if (nb_cols != *it) { - AKANTU_DEBUG_ERROR("The numbers stored in the row " - << i << " are not correct: " << nb_cols - << " != " << *it); - } + EXPECT_EQ(nb_cols, *it); nb_cols--; } - if (nb_cols != 0) { - AKANTU_DEBUG_ERROR("Not enough columns in the row " << i << ": " - << nb_cols); - } + EXPECT_EQ(0, nb_cols); } +} +TEST_F(TestCsrFixture, ReverseIteration) { for (UInt i = 0; i < csr.getNbRows(); ++i) { - CSR::iterator it = csr.rbegin(i); - CSR::iterator end = csr.rend(i); + auto it = csr.rbegin(i); + auto end = csr.rend(i); UInt nb_cols = nb_cols_per_row[i]; UInt j = nb_cols; for (; it != end; --it) { - if ((nb_cols - j + 1) != *it) { - AKANTU_DEBUG_ERROR("Reverse: The numbers stored in the row " - << i << " are not correct: " << (nb_cols - j + 1) - << " != " << *it); - } + EXPECT_EQ((nb_cols - j + 1), *it); j--; } - if (j != 0) - AKANTU_DEBUG_ERROR("Reverse: Not enough columns in the row " << i << ": " - << j); + EXPECT_EQ(0, j); } - - return EXIT_SUCCESS; } diff --git a/test/test_common/test_grid.cc b/test/test_common/test_grid.cc index 6dff392f9..2a8095e4a 100644 --- a/test/test_common/test_grid.cc +++ b/test/test_common/test_grid.cc @@ -1,107 +1,107 @@ /** * @file test_grid.cc * * @author Nicolas Richart * * @date creation: Thu Jul 15 2010 * @date last modification: Thu Aug 06 2015 * * @brief Test the grid object * * @section LICENSE * * Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_grid_dynamic.hh" #include "mesh.hh" #include "mesh_io.hh" using namespace akantu; int main(int argc, char *argv[]) { const UInt spatial_dimension = 2; akantu::initialize(argc, argv); Mesh circle(spatial_dimension); circle.read("circle.msh"); - const Vector & l = circle.getLocalLowerBounds(); - const Vector & u = circle.getLocalUpperBounds(); + const auto & l = circle.getLocalLowerBounds(); + const auto & u = circle.getLocalUpperBounds(); Real spacing[spatial_dimension] = {0.2, 0.2}; Vector s(spacing, spatial_dimension); Vector c = u; c += l; c /= 2.; SpatialGrid grid(spatial_dimension, s, c); Vector bary(spatial_dimension); Element el; el.ghost_type = _not_ghost; - Mesh::type_iterator it = circle.firstType(spatial_dimension); - Mesh::type_iterator last_type = circle.lastType (spatial_dimension); + auto it = circle.firstType(spatial_dimension); + auto last_type = circle.lastType (spatial_dimension); for(; it != last_type; ++it) { UInt nb_element = circle.getNbElement(*it); el.type = *it; for (UInt e = 0; e < nb_element; ++e) { circle.getBarycenter(e, el.type, bary.storage()); el.element = e; grid.insert(el, bary); } } std::cout << grid << std::endl; Mesh mesh(spatial_dimension, "save"); grid.saveAsMesh(mesh); mesh.write("grid.msh"); Vector pos(spatial_dimension); // const SpatialGrid::CellID & id = grid.getCellID(pos); // #if !defined AKANTU_NDEBUG // SpatialGrid::neighbor_cells_iterator nit = grid.beginNeighborCells(id); // SpatialGrid::neighbor_cells_iterator nend = grid.endNeighborCells(id); // for(;nit != nend; ++nit) { // std::cout << std::endl; // const SpatialGrid::Cell & cell = grid.getCell(*nit); // SpatialGrid::Cell::const_iterator cit = cell.begin(); // SpatialGrid::Cell::position_iterator pit = cell.begin_pos(); // SpatialGrid::Cell::const_iterator cend = cell.end(); // for (; cit != cend; ++cit, ++pit) { // std::cout << *cit << " " << *pit << std::endl; // } // } // #endif akantu::finalize(); return EXIT_SUCCESS; }