From 40864ace00f9979bc4c9ba9fae9e008dabed9fad Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 7 Aug 2017 11:22:42 +0200 Subject: [PATCH] fix multi_index bugs... --- CMakeLists.txt | 2 +- src/container_range.cc | 6 ++++-- src/index_unit_test.cc | 28 +++++++++++++++++++++++++++- src/multi_range.cc | 7 +++++-- src/pack_num.h | 4 ++-- src/single_range.cc | 6 ++++-- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e52e5ea..b02fd02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ include_directories(src) add_executable(iutest src/index_unit_test.cc) target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES}) -add_test(NAME iutest COMMAND utest) +add_test(NAME iutest COMMAND iutest) #install(TARGETS testm DESTINATION install) diff --git a/src/container_range.cc b/src/container_range.cc index 5ac4a1b..b124652 100644 --- a/src/container_range.cc +++ b/src/container_range.cc @@ -175,7 +175,8 @@ namespace MultiArrayTools ContainerIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); - return i = 0; + i = 0; + return i; } template @@ -184,7 +185,8 @@ namespace MultiArrayTools ContainerIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); - return i = size(); + i = size(); + return i; } template diff --git a/src/index_unit_test.cc b/src/index_unit_test.cc index b9a6842..308c393 100644 --- a/src/index_unit_test.cc +++ b/src/index_unit_test.cc @@ -93,7 +93,33 @@ namespace { EXPECT_EQ(si == si3, false); EXPECT_EQ(si != si3, true); } - + + TEST_F(IndexTest, MultiIndex_SimpleCall) + { + auto mi = m3rptr->begin(); + EXPECT_EQ(mi.max(), 4); + EXPECT_EQ(mi.pos(), 0); + EXPECT_EQ(mi.first(), true); + EXPECT_EQ(mi.last(), false); + EXPECT_EQ(mi.meta() == std::make_tuple('a','1','0'), true); + mi.at(std::make_tuple('b','1','7')); + EXPECT_EQ(mi.pos(), mi.max()-1); + EXPECT_EQ(mi.first(), false); + EXPECT_EQ(mi.last(), true); + mi = 1; + EXPECT_EQ(mi.meta() == std::make_tuple('a','1','7'), true); + ++mi; + EXPECT_EQ(mi.meta() == std::make_tuple('b','1','0'), true); + ++mi; + auto mi2 = m3rptr->end(); + --mi2; + EXPECT_EQ(mi == mi2, true); + EXPECT_EQ(mi != mi2, false); + --mi2; + EXPECT_EQ(mi == mi2, false); + EXPECT_EQ(mi != mi2, true); + } + } // end namespace int main(int argc, char** argv) diff --git a/src/multi_range.cc b/src/multi_range.cc index 7235ff4..05b04e8 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -120,6 +120,7 @@ namespace MultiArrayTools MultiIndex& MultiIndex::at(const MultiIndex::MetaType& metaPos) { PackNum::setMeta(mIPack, metaPos); + IB::mPos = PackNum::makePos(mIPack); return *this; } @@ -206,7 +207,8 @@ namespace MultiArrayTools MultiIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); - return i = 0; + i = 0; + return i; } template @@ -215,7 +217,8 @@ namespace MultiArrayTools MultiIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis )) ); - return i = size(); + i = size(); + return i; } template diff --git a/src/pack_num.h b/src/pack_num.h index c3f3227..20d5a7c 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -89,7 +89,7 @@ namespace MultiArrayHelper template static void setIndexPack(IndexPack& iPack, size_t pos) { - auto i = *std::get(iPack).get(); + auto& i = *std::get(iPack).get(); const size_t ownPos = pos % i.max(); i = ownPos; if(ownPos == pos){ @@ -195,7 +195,7 @@ namespace MultiArrayHelper template static void setIndexPack(IndexPack& iPack, size_t pos) { - auto i = *std::get<0>(iPack); + auto& i = *std::get<0>(iPack); const size_t ownPos = pos % i.max(); i = ownPos; } diff --git a/src/single_range.cc b/src/single_range.cc index 048eb4f..98cdab6 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -124,7 +124,8 @@ namespace MultiArrayTools { SingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); - return i = 0; + i = 0; + return i; } template @@ -132,7 +133,8 @@ namespace MultiArrayTools { SingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); - return i = size(); + i = size(); + return i; } // put this in the interface class !!!