fix multi_index bugs...

This commit is contained in:
Christian Zimmermann 2017-08-07 11:22:42 +02:00
parent 7a16f22f78
commit 40864ace00
6 changed files with 43 additions and 10 deletions

View file

@ -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)

View file

@ -175,7 +175,8 @@ namespace MultiArrayTools
ContainerIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = 0;
i = 0;
return i;
}
template <class... Ranges>
@ -184,7 +185,8 @@ namespace MultiArrayTools
ContainerIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = size();
i = size();
return i;
}
template <class... Ranges>

View file

@ -94,6 +94,32 @@ namespace {
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)

View file

@ -120,6 +120,7 @@ namespace MultiArrayTools
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MultiIndex<Indices...>::MetaType& metaPos)
{
PackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this;
}
@ -206,7 +207,8 @@ namespace MultiArrayTools
MultiIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = 0;
i = 0;
return i;
}
template <class... Ranges>
@ -215,7 +217,8 @@ namespace MultiArrayTools
MultiIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) );
return i = size();
i = size();
return i;
}
template <class... Ranges>

View file

@ -89,7 +89,7 @@ namespace MultiArrayHelper
template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos)
{
auto i = *std::get<N>(iPack).get();
auto& i = *std::get<N>(iPack).get();
const size_t ownPos = pos % i.max();
i = ownPos;
if(ownPos == pos){
@ -195,7 +195,7 @@ namespace MultiArrayHelper
template <class IndexPack>
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;
}

View file

@ -124,7 +124,8 @@ namespace MultiArrayTools
{
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = 0;
i = 0;
return i;
}
template <typename U, RangeType TYPE>
@ -132,7 +133,8 @@ namespace MultiArrayTools
{
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = size();
i = size();
return i;
}
// put this in the interface class !!!