start writing new unit tests regarding new behaviour... rewriting still not finished

This commit is contained in:
Christian Zimmermann 2017-05-30 17:49:18 +02:00
parent b63d56e315
commit 2793b8c774
3 changed files with 88 additions and 6 deletions

View file

@ -15,9 +15,13 @@ endif()
include_directories(src)
add_executable(utest src/unit_test.cc)
target_link_libraries(utest ${GTEST_BOTH_LIBRARIES})
add_test(NAME utest COMMAND utest)
#add_executable(utest src/unit_test.cc)
#target_link_libraries(utest ${GTEST_BOTH_LIBRARIES})
#add_test(NAME utest COMMAND utest)
add_executable(iutest src/index_unit_test.cc)
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES})
add_test(NAME iutest COMMAND utest)
#install(TARGETS testm DESTINATION install)

52
src/index_unit_test.cc Normal file
View file

@ -0,0 +1,52 @@
// -*- C++ -*-
#include <cstdlib>
#include "gtest/gtest.h"
#include <iostream>
#include "multi_array_header.h"
namespace MAT = MultiArrayTools;
namespace {
class ConnectionTest : public ::testing::Test
{
protected:
typedef MAT::SingleRange<char,MAT::RangeType::ANY> SingleRc;
typedef MAT::SingleRange<int,MAT::RangeType::ANY> SingleRi;
typedef MAT::MultiRange<SingleRc,SingleRc,SingleRi> MultiR3d;
typedef MAT::MultiRange<SingleRi,SingleRc> MultiR2d;
ConnectionTest() : sri1({0,1,2,3}),
src1({'a','b'}),
src2({'a','b','c'}),
mr3d1(src1,src2,sri1) {}
SingleRi sri1;
SingleRc src1;
SingleRc src2;
MultiR3d mr3d1;
};
TEST_F(ConnectionTest, UnlinkedIteration)
{
auto i3d = mr3d1.begin();
auto& ii1 = i3d.template getIndex<2>();
EXPECT_EQ(i3d.pos(), 0);
++ii1;
EXPECT_EQ(i3d.pos(), 1);
++ii1;
EXPECT_EQ(i3d.pos(), 2);
++ii1;
EXPECT_EQ(i3d.pos(), 3);
}
} // end namespace
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -324,6 +324,18 @@ namespace MultiArrayTools
}
}
template <class IndexPack, class... Indices>
static auto setFromPointerList(IndexPack& ipack,
std::vector<std::shared_ptr<IndefinitIndexBase> >& ptrList,
std::shared_ptr<Indices>&... inds)
-> decltype(IndexPackSetter<N-1>::setFromPointerList(ipack,
std::shared_ptr<decltype(std::get<N>(ipack))>,
newPtr, inds...))
{
typedef std::shared_ptr<decltype(std::get<N>(ipack))> NewIndexPtrType;
NewIndexPtrType newPtr = dynamic_pointer_cast<NewIndexPtrType>(ptrList.at(N));
return IndexPackSetter<N-1>::setFromPointerList(ipack, ptrList, newPtr, inds...);
}
};
template <>
@ -337,6 +349,17 @@ namespace MultiArrayTools
i = ownPos;
}
template <class IndexPack, class... Indices>
static auto setFromPointerList(IndexPack& ipack,
std::vector<std::shared_ptr<IndefinitIndexBase> >& ptrList,
std::shared_ptr<Indices>&... inds)
-> decltype(std::make_tuple(std::shared_ptr<decltype(std::get<0>(ipack))>, inds...))
{
typedef std::shared_ptr<decltype(std::get<0>(ipack))> NewIndexPtrType;
NewIndexPtrType newPtr = dynamic_pointer_cast<NewIndexPtrType>(ptrList.at(0));
return std::make_tuple(newPtr, inds...);
}
};
}
@ -391,8 +414,11 @@ namespace MultiArrayTools
}
template <class... Indices>
MultiIndex<Indices...>::MultiIndex(std::vector<std::shared_ptr<IndefinitIndexBase> >& indexList) :
// !!!!
MultiIndex<Indices...>::MultiIndex(std::vector<std::shared_ptr<IndefinitIndexBase> >& indexList)
{
mIPack = IndexPackSetter<sizeof...(Indices)-1>::setFromPointerList(mIPack, indexList);
IndexSubOrder<sizeof...(Indices)-1>::subOrd(mIPack, this);
}
template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()