diff --git a/include/tensor/indices.h b/include/tensor/indices.h index 75800e2d..bed0a1d1 100644 --- a/include/tensor/indices.h +++ b/include/tensor/indices.h @@ -151,6 +151,10 @@ class Dimensions { std::equal(begin(), end(), other.begin()); } + bool operator!=(const Dimensions &other) const { + return !(*this == other); + } + private: template index_t column_major_inner(index n, index in, index_like... irest) const { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 073f3047..443377cb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -76,6 +76,7 @@ package_add_test(test_tensor_unop test_tensor_unop.cc) package_add_test(test_vector test_vector.cc) package_add_test(test_indices test_indices.cc) package_add_test(test_indices_comparisons test_indices_comparisons.cc) +package_add_test(test_dimensions test_dimensions.cc) package_add_test(test_range test_range.cc) package_add_test(test_range_iterator test_range_iterator.cc) package_add_test(test_view_read test_view_read.cc) diff --git a/tests/test_dimensions.cc b/tests/test_dimensions.cc new file mode 100644 index 00000000..9a801ff8 --- /dev/null +++ b/tests/test_dimensions.cc @@ -0,0 +1,43 @@ +/* + Copyright (c) 2010 Juan Jose Garcia Ripoll + + Tensor is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 Library General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include + + +namespace tensor_test { + +using namespace tensor; + +TEST(Dimensions, equality) { + Dimensions base{1, 2, 3}; + + Dimensions same{1, 2, 3}; + Dimensions otherSize{1, 2, 4}; + Dimensions otherRank{1, 2, 3, 1}; + + ASSERT_TRUE(base == same); + ASSERT_FALSE(base == otherSize); + ASSERT_FALSE(base == otherRank); + + ASSERT_FALSE(base != same); + ASSERT_TRUE(base != otherSize); + ASSERT_TRUE(base != otherRank); +} + +}