extend mr_test

This commit is contained in:
Christian Zimmermann 2022-11-14 18:47:51 +01:00
parent 3a6ffc209b
commit 3e54485b12
3 changed files with 52 additions and 10 deletions

View file

@ -16,6 +16,8 @@ namespace CNORXZ
{
static_assert(sizeof...(Is) == NI,
"sequence size does not match number of indices");
CXZ_ASSERT( ( (mRange->sub(Is) != nullptr) and ... ),
"no subranges available" );
return std::make_tuple( std::make_shared<Indices>( mRange->sub(Is) )... );
}
@ -84,27 +86,27 @@ namespace CNORXZ
template <class... Indices>
MIndex<Indices...>::MIndex(const MIndex& i) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(i.pos()),
mRange(rangeCast<RangeType>(i.range())),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})),
mRange(rangeCast<RangeType>(i.range()))
mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))
{}
template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator=(const MIndex& i)
{
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>::operator=(i);
mRange = rangeCast<RangeType>(i.range());
mIPack = mkIPack(IB::mPos, Isqr<0,NI>{});
mBlockSizes = mkBlockSizes(mIPack,Isqr<0,NI-1>{});
mRange = rangeCast<RangeType>(i.range());
return *this;
}
template <class... Indices>
MIndex<Indices...>::MIndex(const RangePtr& range, SizeT pos) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(rangeCast<RangeType>(range)),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})),
mRange(rangeCast<RangeType>(range))
mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))
{
(*this) = pos;
}

View file

@ -82,10 +82,10 @@ namespace CNORXZ
template <SizeT I, class Xpr, class F>
constexpr decltype(auto) mkIFor(const Xpr& xpr, F&& f) const;
Sptr<RangeType> mRange;
IndexPack mIPack;
typedef RemoveRef<decltype(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))> BlockTuple;
BlockTuple mBlockSizes;
Sptr<RangeType> mRange;
};
// modified blockSizes; to be used for Slices; can be created from MIndices

View file

@ -1,5 +1,4 @@
#include <cstdlib>
#include <iostream>
@ -114,7 +113,7 @@ namespace
}
SizeT cnt2 = 0;
for(auto x: *urx){
for(const auto& x: *urx){
EXPECT_EQ(x, mMeta[cnt2++]);
}
}
@ -130,12 +129,53 @@ namespace
EXPECT_EQ(mr->size(), mMeta.size()*mSize);
EXPECT_EQ(mrx->size(), mMeta.size()*mSize);
EXPECT_EQ(mr->dim(), 2u);
EXPECT_EQ(mrx->dim(), 2u);
// further tests!!!
EXPECT_TRUE(mrx->begin() != mrx->end());
EXPECT_FALSE(mrx->begin() == mrx->end());
EXPECT_EQ(mrx->begin().pos(), 0u);
EXPECT_EQ(mrx->end().pos(), mrx->size());
EXPECT_TRUE(mr->begin() != mr->end());
EXPECT_FALSE(mr->begin() == mr->end());
EXPECT_EQ(mr->begin().pos(), 0u);
EXPECT_EQ(mr->end().pos(), mr->size());
const SizeT mmsize = mMeta.size();
auto mkm = [&](SizeT i) { return Tuple<SizeT,String>(i/mmsize,mMeta[i % mmsize]); };
SizeT cnt = 0;
auto endxi = mr->end();
for(auto xi = mr->begin(); xi != endxi; ++xi){
EXPECT_EQ(xi.pos(), cnt);
auto meta = mkm(cnt);
EXPECT_TRUE(*xi == DType(meta));
EXPECT_EQ((*xi).str(), toString(meta));
++cnt;
}
cnt = 0;
auto endxxi = mrx->end();
for(auto xxi = mrx->begin(); xxi != endxxi; ++xxi){
EXPECT_EQ(xxi.pos(), cnt);
auto ci = std::get<0>(xxi.pack());
auto ui = std::get<1>(xxi.pack());
Tuple<SizeT,String> meta(*(*ci),*(*ui));
auto meta2 = mkm(cnt);
EXPECT_EQ(meta, meta2);
EXPECT_TRUE(*xxi == meta);
++cnt;
}
cnt = 0;
for(auto x: *mrx){
auto meta = mkm(cnt);
EXPECT_EQ(x, meta);
++cnt;
}
}
// UR_Test
// RCast_Test
}