first anonymous test works
This commit is contained in:
parent
764bcac758
commit
fcb7ce575e
5 changed files with 144 additions and 6 deletions
|
@ -38,9 +38,12 @@ namespace MultiArrayTools
|
||||||
std::shared_ptr<RangeBase> create();
|
std::shared_ptr<RangeBase> create();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec);
|
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec);
|
||||||
|
|
||||||
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;
|
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;
|
||||||
|
|
||||||
|
bool mProductCreated = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AnonymousRange : public RangeInterface<AnonymousIndex>
|
class AnonymousRange : public RangeInterface<AnonymousIndex>
|
||||||
|
@ -77,7 +80,7 @@ namespace MultiArrayTools
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AnonymousRange() = delete;
|
AnonymousRange() = delete;
|
||||||
AnonymousRange(const AnonymousRange& in) = delete;
|
AnonymousRange(const AnonymousRange& in) = default;
|
||||||
|
|
||||||
template <class... RangeTypes>
|
template <class... RangeTypes>
|
||||||
AnonymousRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
AnonymousRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
||||||
|
@ -85,7 +88,7 @@ namespace MultiArrayTools
|
||||||
template <class... RangeTypes>
|
template <class... RangeTypes>
|
||||||
AnonymousRange(std::shared_ptr<RangeTypes>... origs);
|
AnonymousRange(std::shared_ptr<RangeTypes>... origs);
|
||||||
|
|
||||||
size_t mSize;
|
size_t mSize = 0;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<RangeBase> > mOrig;
|
std::vector<std::shared_ptr<RangeBase> > mOrig;
|
||||||
};
|
};
|
||||||
|
@ -118,7 +121,12 @@ namespace MultiArrayTools
|
||||||
template <class Range>
|
template <class Range>
|
||||||
void AnonymousRangeFactory::append(std::shared_ptr<Range> r)
|
void AnonymousRangeFactory::append(std::shared_ptr<Range> r)
|
||||||
{
|
{
|
||||||
|
if(mProductCreated){
|
||||||
|
mProd = std::shared_ptr<oType>( new AnonymousRange( *std::dynamic_pointer_cast<oType>(mProd) ) );
|
||||||
|
mProductCreated = false;
|
||||||
|
}
|
||||||
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r);
|
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r);
|
||||||
|
std::dynamic_pointer_cast<oType>(mProd)->mSize *= r->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
|
@ -175,7 +183,7 @@ namespace MultiArrayTools
|
||||||
RangeInterface<AnonymousIndex>()
|
RangeInterface<AnonymousIndex>()
|
||||||
{
|
{
|
||||||
auto rst = std::make_tuple(origs...);
|
auto rst = std::make_tuple(origs...);
|
||||||
mOrig.resize(sizeof...(RangeTypes));
|
//mOrig.resize(sizeof...(RangeTypes));
|
||||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
||||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
std::vector<std::shared_ptr<RangeBase> >& v)
|
std::vector<std::shared_ptr<RangeBase> >& v)
|
||||||
{
|
{
|
||||||
setRangeToVec(v, std::get<N>(rst));
|
setRangeToVec(v, std::get<N>(rst));
|
||||||
//v[N] = std::get<N>(rst);
|
//v[N] = std::get<N>(rst);
|
||||||
|
@ -420,7 +420,7 @@ namespace MultiArrayHelper
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
std::vector<std::shared_ptr<RangeBase> >& v)
|
std::vector<std::shared_ptr<RangeBase> >& v)
|
||||||
{
|
{
|
||||||
v[0] = std::get<0>(rst);
|
setRangeToVec(v, std::get<0>(rst));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
|
|
|
@ -7,6 +7,8 @@ namespace MultiArrayTools
|
||||||
* AnonymousRangeFactory *
|
* AnonymousRangeFactory *
|
||||||
******************************/
|
******************************/
|
||||||
|
|
||||||
|
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > AnonymousRangeFactory::mAleadyCreated;
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec)
|
std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec)
|
||||||
{
|
{
|
||||||
std::shared_ptr<RangeBase> out;
|
std::shared_ptr<RangeBase> out;
|
||||||
|
@ -42,6 +44,7 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
mProd = checkIfCreated(std::dynamic_pointer_cast<AnonymousRange>(mProd)->mOrig);
|
mProd = checkIfCreated(std::dynamic_pointer_cast<AnonymousRange>(mProd)->mOrig);
|
||||||
setSelf();
|
setSelf();
|
||||||
|
mProductCreated = true;
|
||||||
return mProd;
|
return mProd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,11 @@ add_dependencies(iutest multiarray)
|
||||||
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
||||||
add_test(NAME iutest COMMAND iutest)
|
add_test(NAME iutest COMMAND iutest)
|
||||||
|
|
||||||
|
add_executable(autest ranges/anonymous_unit_test.cc)
|
||||||
|
add_dependencies(autest multiarray)
|
||||||
|
target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
||||||
|
add_test(NAME autest COMMAND autest)
|
||||||
|
|
||||||
#add_executable(mautest src/tests/ma_unit_test.cc ${MA_CC_FILES})
|
#add_executable(mautest src/tests/ma_unit_test.cc ${MA_CC_FILES})
|
||||||
add_executable(mautest ma_unit_test.cc)
|
add_executable(mautest ma_unit_test.cc)
|
||||||
add_dependencies(mautest multiarray)
|
add_dependencies(mautest multiarray)
|
||||||
|
|
122
src/tests/ranges/anonymous_unit_test.cc
Normal file
122
src/tests/ranges/anonymous_unit_test.cc
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
// -*- C++ -*-
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ranges/rheader.h"
|
||||||
|
|
||||||
|
//#include "multi_array_header.h"
|
||||||
|
|
||||||
|
namespace MAT = MultiArrayTools;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using namespace MAT;
|
||||||
|
|
||||||
|
template <class Factory, typename T>
|
||||||
|
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
|
||||||
|
{
|
||||||
|
std::vector<T> tmp = ilist;
|
||||||
|
auto nptr = std::make_shared<Factory>( tmp );
|
||||||
|
fptr = nptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Factory, class... Rs>
|
||||||
|
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
|
||||||
|
{
|
||||||
|
auto nptr = std::make_shared<Factory>( rs... );
|
||||||
|
fptr = nptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
|
||||||
|
{
|
||||||
|
return std::make_tuple(ts...);
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousIndexTest : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
|
||||||
|
typedef SRF::oType SRange;
|
||||||
|
|
||||||
|
typedef MultiRangeFactory<SRange,SRange,SRange> M3RF;
|
||||||
|
typedef M3RF::oType M3Range;
|
||||||
|
|
||||||
|
typedef MultiRangeFactory<SRange,M3Range,SRange> MasterRF;
|
||||||
|
typedef MasterRF::oType MasterRange;
|
||||||
|
|
||||||
|
typedef ContainerRangeFactory<double,M3Range,SRange> CRF;
|
||||||
|
typedef CRF::oType CRange;
|
||||||
|
typedef ContainerIndex<double,M3Range::IndexType,SRange::IndexType> CIndex;
|
||||||
|
|
||||||
|
AnonymousIndexTest()
|
||||||
|
{
|
||||||
|
swapFactory<SRF>(rfbptr, { 'e', 'b', 'n' } );
|
||||||
|
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
|
||||||
|
swapFactory<SRF>(rfbptr, { 'x', 'y', 'l', 'f' } );
|
||||||
|
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
|
||||||
|
swapFactory<SRF>(rfbptr, { 'a', 'b' } );
|
||||||
|
std::shared_ptr<SRange> temp1 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
swapFactory<SRF>(rfbptr, { '1' } );
|
||||||
|
std::shared_ptr<SRange> temp2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
swapFactory<SRF>(rfbptr, { '0', '7' } );
|
||||||
|
std::shared_ptr<SRange> temp3 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
|
||||||
|
swapMFactory<M3RF>(rfbptr, temp1, temp2, temp3 );
|
||||||
|
m3rptr = std::dynamic_pointer_cast<M3Range>( rfbptr->create() );
|
||||||
|
|
||||||
|
swapMFactory<MasterRF>(rfbptr, sr1ptr, m3rptr, sr2ptr);
|
||||||
|
mstrptr = std::dynamic_pointer_cast<MasterRange>( rfbptr->create() );
|
||||||
|
|
||||||
|
swapMFactory<CRF>(rfbptr, m3rptr, sr2ptr);
|
||||||
|
cr1ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||||
|
|
||||||
|
swapMFactory<CRF>(rfbptr, m3rptr, sr1ptr);
|
||||||
|
cr2ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||||
|
std::shared_ptr<SRange> sr1ptr;
|
||||||
|
std::shared_ptr<SRange> sr2ptr;
|
||||||
|
std::shared_ptr<M3Range> m3rptr;
|
||||||
|
std::shared_ptr<MasterRange> mstrptr;
|
||||||
|
std::shared_ptr<CRange> cr1ptr;
|
||||||
|
std::shared_ptr<CRange> cr2ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(AnonymousIndexTest, Cast1)
|
||||||
|
{
|
||||||
|
AnonymousRangeFactory arf1(sr1ptr,m3rptr);
|
||||||
|
auto ar1a = std::dynamic_pointer_cast<AnonymousRange>( arf1.create() );
|
||||||
|
|
||||||
|
arf1.append(sr2ptr);
|
||||||
|
|
||||||
|
auto ar1b = std::dynamic_pointer_cast<AnonymousRange>( arf1.create() );
|
||||||
|
|
||||||
|
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
|
||||||
|
auto ar2 = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
|
||||||
|
|
||||||
|
EXPECT_EQ(ar1b.get(), ar2.get());
|
||||||
|
EXPECT_EQ(ar1a->size(), sr1ptr->size() * m3rptr->size());
|
||||||
|
EXPECT_EQ(ar2->size(), sr1ptr->size() * m3rptr->size() * sr2ptr->size());
|
||||||
|
|
||||||
|
EXPECT_EQ(ar1a->sub(0)->size(), sr1ptr->size());
|
||||||
|
EXPECT_EQ(ar1a->sub(1)->size(), m3rptr->size());
|
||||||
|
|
||||||
|
EXPECT_EQ(ar2->sub(0)->size(), sr1ptr->size());
|
||||||
|
EXPECT_EQ(ar2->sub(1)->size(), m3rptr->size());
|
||||||
|
EXPECT_EQ(ar2->sub(2)->size(), sr2ptr->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
Loading…
Reference in a new issue