diff --git a/test/test_common/CMakeLists.txt b/test/test_common/CMakeLists.txt index 5f8d5e30d..12dfc0122 100644 --- a/test/test_common/CMakeLists.txt +++ b/test/test_common/CMakeLists.txt @@ -1,50 +1,51 @@ #=============================================================================== # @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_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_zip_iterator test_zip_iterator.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_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_zip_iterator.cc b/test/test_common/test_zip_iterator.cc index 5798ef277..4f627cec1 100644 --- a/test/test_common/test_zip_iterator.cc +++ b/test/test_common/test_zip_iterator.cc @@ -1,94 +1,133 @@ /** * @file test_zip_iterator.cc * * @author Nicolas Richart * * @date creation Fri Jul 21 2017 * * @brief test the zip container and iterator * * @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 #include /* -------------------------------------------------------------------------- */ using namespace akantu; template class A { public: A() = default; A(T a) : a(a){}; - A(const A & other) : a(other.a), counter(other.counter + 1) {} + A(const A & other) + : a(other.a), copy_counter(other.copy_counter + 1), + move_counter(other.move_counter) {} A & operator=(const A & other) { - a = other.a; - counter = other.counter + 1; + if (this != &other) { + a = other.a; + copy_counter = other.copy_counter + 1; + } + return *this; + } + + A(A && other) + : a(std::move(other.a)), copy_counter(std::move(other.copy_counter)), + move_counter(std::move(other.move_counter) + 1) {} + + A & operator=(A && other) { + if (this != &other) { + a = std::move(other.a); + copy_counter = std::move(other.copy_counter); + move_counter = std::move(other.move_counter) + 1; + } return *this; } A & operator*=(const T & b) { a *= b; return *this; } - void to_stream(std::ostream & stream) const { - stream << a << " [" << counter << "]"; - } -private: T a; - size_t counter{0}; + size_t copy_counter{0}; + size_t move_counter{0}; }; -template -std::ostream & operator<<(std::ostream & stream, const A & a) { - a.to_stream(stream); - return stream; -} +class TestZipFixutre : public ::testing::Test { + void SetUp() override { + a.reserve(size); + b.reserve(size); -/* -------------------------------------------------------------------------- */ -int main() { - std::vector> a{1, 2, 3, 4, 5}; - const std::vector> b{6., 7., 8., 9., 10.}; + for (size_t i = 0; i < size; ++i) { + a.emplace_back(i); + b.emplace_back(i + size); + } + } - auto aend = a.end(); +protected: + size_t size{20}; + std::vector> a; + std::vector> b; +}; - auto ait = a.begin(); - auto bit = b.begin(); +TEST_F(TestZipFixutre, SimpleTest) { + size_t i = 0; + std::reference_wrapper> a; + std::reference_wrapper> b; + for (auto && pair : zip(a, b)) { + auto && a = std::get<0>(pair); + auto && b = std::get<1>(pair); - for (; ait != aend; ++ait, ++bit) { - std::cout << *ait << " " << *bit << std::endl; - } + EXPECT_EQ(i, a.a); + EXPECT_EQ(0, a.copy_counter); + EXPECT_EQ(0, a.move_counter); - for (auto pair : zip(a, b)) { - std::cout << std::get<0>(pair) << " " << std::get<1>(pair) << std::endl; - std::get<0>(pair) *= 10; + EXPECT_FLOAT_EQ(i + this->size, b.a); + EXPECT_EQ(0, b.copy_counter); + EXPECT_EQ(0, b.move_counter); + ++i; } +} - ait = a.begin(); - bit = b.begin(); - for (; ait != aend; ++ait, ++bit) { - std::cout << *ait << " " << *bit << std::endl; - } +// /* -------------------------------------------------------------------------- +// */ int main() { +// auto ait = a.begin(); +// auto bit = b.begin(); +// auto aend = a.end(); +// for (; ait != aend; ++ait, ++bit) { - return 0; -} +// } + +// for (auto pair : zip(a, b)) { +// std::cout << std::get<0>(pair) << " " << std::get<1>(pair) << std::endl; +// std::get<0>(pair) *= 10; +// } + +// ait = a.begin(); +// bit = b.begin(); +// for (; ait != aend; ++ait, ++bit) { +// std::cout << *ait << " " << *bit << std::endl; +// } + +// return 0; +// }