Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test and code for inequality comparison for Dimensions #36

Open
wants to merge 1 commit into
base: cmake
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/tensor/indices.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ class Dimensions {
std::equal(begin(), end(), other.begin());
}

bool operator!=(const Dimensions &other) const {
return !(*this == other);
}

private:
template <typename... index_like>
index_t column_major_inner(index n, index in, index_like... irest) const {
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_dimensions.cc
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <tensor/indices.h>


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);
}

}