cxz cereal: more tests
This commit is contained in:
parent
36a22f51de
commit
80ac604089
11 changed files with 152 additions and 15 deletions
|
@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0)
|
||||||
project(cnorxz)
|
project(cnorxz)
|
||||||
|
|
||||||
execute_process(COMMAND bash "-c" "git rev-parse HEAD" OUTPUT_VARIABLE GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND bash "-c" "git rev-parse HEAD" OUTPUT_VARIABLE GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
execute_process(COMMAND bash "-c" "git tag -l --sort=refname v* | tail -n1" OUTPUT_VARIABLE GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND bash "-c" "git tag -l --sort=refname 'v*' | tail -n1" OUTPUT_VARIABLE GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
execute_process(COMMAND bash "-c" "git rev-list -n 1 ${GIT_TAG}" OUTPUT_VARIABLE GIT_TAG_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND bash "-c" "git rev-list -n 1 ${GIT_TAG}" OUTPUT_VARIABLE GIT_TAG_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
string(SUBSTRING ${GIT_TAG} 1 -1 VERSION)
|
string(SUBSTRING ${GIT_TAG} 1 -1 VERSION)
|
||||||
if(NOT (${GIT_HASH} EQUAL ${GIT_TAG_HASH}))
|
if(NOT (${GIT_HASH} EQUAL ${GIT_TAG_HASH}))
|
||||||
|
|
|
@ -624,10 +624,10 @@ namespace CNORXZ
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
Vector<Uuid> MRange<Ranges...>::key() const
|
Vector<Uuid> MRange<Ranges...>::key() const
|
||||||
{
|
{
|
||||||
Vector<Uuid> key = iter<0,sizeof...(Ranges)>
|
Vector<Uuid> k = iter<0,sizeof...(Ranges)>
|
||||||
( [&](auto i) { return std::get<i>( mRs ); },
|
( [&](auto i) { return std::get<i>( mRs ); },
|
||||||
[](const auto&... e) { return Vector<Uuid> { e->id()... }; } );
|
[](const auto&... e) { return Vector<Uuid> { e->id()... }; } );
|
||||||
return key;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************
|
/************************
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
#include "dindex.h"
|
#include "dindex.h"
|
||||||
#include "mrange.h"
|
#include "mrange.h"
|
||||||
|
|
||||||
|
//#include "crange.h"
|
||||||
|
|
||||||
namespace CNORXZ
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class Range>
|
template <class Range>
|
||||||
decltype(auto) RangeInterface<Range>::begin() const
|
decltype(auto) RangeInterface<Range>::begin() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,6 +68,8 @@ namespace CNORXZ
|
||||||
DIndex end() const;
|
DIndex end() const;
|
||||||
RangePtr orig() const;
|
RangePtr orig() const;
|
||||||
|
|
||||||
|
//virtual Vector<Uuid> key2() const { return Vector<Uuid>(); }
|
||||||
|
|
||||||
friend RangeFactoryBase;
|
friend RangeFactoryBase;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -75,8 +77,8 @@ namespace CNORXZ
|
||||||
RangeBase();
|
RangeBase();
|
||||||
RangeBase(const RangePtr& rel);
|
RangeBase(const RangePtr& rel);
|
||||||
|
|
||||||
virtual Vector<Uuid> key() const = 0;
|
|
||||||
|
|
||||||
|
virtual Vector<Uuid> key() const = 0;
|
||||||
// delete copy/move???
|
// delete copy/move???
|
||||||
Uuid mId = {0,0};
|
Uuid mId = {0,0};
|
||||||
Wptr<RangeBase> mThis;
|
Wptr<RangeBase> mThis;
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace CNORXZ
|
||||||
|
|
||||||
RangePtr RangeFactoryBase::getRegistered(const TypeInfo& info, const RangePtr& r)
|
RangePtr RangeFactoryBase::getRegistered(const TypeInfo& info, const RangePtr& r)
|
||||||
{
|
{
|
||||||
|
CXZ_ASSERT(r != nullptr, "got range ptr to null");
|
||||||
auto& rx = sCreated[info.hash_code()][r->key()];
|
auto& rx = sCreated[info.hash_code()][r->key()];
|
||||||
if(rx == nullptr){
|
if(rx == nullptr){
|
||||||
rx = r;
|
rx = r;
|
||||||
|
|
|
@ -425,14 +425,14 @@ namespace CNORXZ
|
||||||
|
|
||||||
void YRangeFactory::make()
|
void YRangeFactory::make()
|
||||||
{
|
{
|
||||||
Vector<Uuid> key(mRVec.size());
|
Vector<Uuid> k(mRVec.size());
|
||||||
std::transform(mRVec.begin(), mRVec.end(), key.begin(),
|
std::transform(mRVec.begin(), mRVec.end(), k.begin(),
|
||||||
[&](const RangePtr& r) { return r->id(); } );
|
[&](const RangePtr& r) { return r->id(); } );
|
||||||
mProd = this->fromCreated(typeid(YRange), key);
|
mProd = this->fromCreated(typeid(YRange), k);
|
||||||
if(mProd == nullptr){
|
if(mProd == nullptr){
|
||||||
mProd = std::shared_ptr<YRange>
|
mProd = std::shared_ptr<YRange>
|
||||||
( new YRange( std::move(mRVec) ) );
|
( new YRange( std::move(mRVec) ) );
|
||||||
this->addToCreated(typeid(YRange), key, mProd);
|
this->addToCreated(typeid(YRange), k, mProd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,10 +507,10 @@ namespace CNORXZ
|
||||||
|
|
||||||
Vector<Uuid> YRange::key() const
|
Vector<Uuid> YRange::key() const
|
||||||
{
|
{
|
||||||
Vector<Uuid> key(mRVec.size());
|
Vector<Uuid> k(mRVec.size());
|
||||||
std::transform(mRVec.begin(), mRVec.end(), key.begin(),
|
std::transform(mRVec.begin(), mRVec.end(), k.begin(),
|
||||||
[&](const RangePtr& r) { return r->id(); } );
|
[&](const RangePtr& r) { return r->id(); } );
|
||||||
return key;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
YRange::YRange(const Vector<RangePtr>& rvec) : mRVec(rvec) {}
|
YRange::YRange(const Vector<RangePtr>& rvec) : mRVec(rvec) {}
|
||||||
|
|
|
@ -20,7 +20,8 @@ namespace CNORXZ
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void MArray<T>::load(Archive& ar)
|
void MArray<T>::load(Archive& ar)
|
||||||
{
|
{
|
||||||
ar(cereal::make_nvp("range", AB::mRange));
|
save_load("range", AB::mRange);
|
||||||
|
//ar(cereal::make_nvp("range", AB::mRange));
|
||||||
ar(cereal::make_nvp("data", mCont));
|
ar(cereal::make_nvp("data", mCont));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,10 @@ namespace CNORXZ
|
||||||
ar(cereal::make_nvp("this", RB::mThis));
|
ar(cereal::make_nvp("this", RB::mThis));
|
||||||
ar(cereal::make_nvp("sub", mRVec));
|
ar(cereal::make_nvp("sub", mRVec));
|
||||||
CXZ_ASSERT(RangePtr(RB::mThis).get() == this, "got corrupted range data");
|
CXZ_ASSERT(RangePtr(RB::mThis).get() == this, "got corrupted range data");
|
||||||
|
// register range:
|
||||||
|
for(auto& r: mRVec){
|
||||||
|
r = RangeFactoryBase::getRegistered(r->type(), r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,16 @@
|
||||||
|
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "range_save_load.h"
|
#include "range_save_load.h"
|
||||||
|
#include <cereal/cereal.hpp>
|
||||||
|
|
||||||
namespace CNORXZ
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace cer
|
namespace cer
|
||||||
{
|
{
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
RangePtr save_load(Archive& ar, RangePtr& r)
|
RangePtr save_load(Archive& ar, const String& name, RangePtr& r)
|
||||||
{
|
{
|
||||||
ar(r);
|
ar(cereal::make_nvp(name, r));
|
||||||
return r = RangeFactoryBase::getRegistered(r->type(), r);
|
return r = RangeFactoryBase::getRegistered(r->type(), r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,10 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace cer
|
namespace cer
|
||||||
{
|
{
|
||||||
|
// use this function to register the range in the map of the range factories
|
||||||
|
// (otherwise there might be more than one instance of the same range)
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
RangePtr save_load(Archive& ar, RangePtr& r);
|
RangePtr save_load(Archive& ar, const String& name, RangePtr& r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,43 @@ namespace
|
||||||
std::stringstream mS;
|
std::stringstream mS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CerURange_Test : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
CerURange_Test()
|
||||||
|
{
|
||||||
|
mMeta = { "some", "random", "words", "with", "no", "meaning" };
|
||||||
|
mR = URangeFactory(mMeta).create();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<String> mMeta;
|
||||||
|
RangePtr mR;
|
||||||
|
std::stringstream mS;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CerYRange_Test : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
CerYRange_Test()
|
||||||
|
{
|
||||||
|
mSize = 7;
|
||||||
|
mMeta = { "some", "random", "words", "with", "no", "meaning" };
|
||||||
|
mR1 = CRangeFactory(mSize).create();
|
||||||
|
mR2 = URangeFactory(mMeta).create();
|
||||||
|
mR = YRangeFactory({mR1,mR2}).create();
|
||||||
|
}
|
||||||
|
|
||||||
|
SizeT mSize;
|
||||||
|
Vector<String> mMeta;
|
||||||
|
RangePtr mR1;
|
||||||
|
RangePtr mR2;
|
||||||
|
RangePtr mR;
|
||||||
|
std::stringstream mS;
|
||||||
|
std::stringstream mS2;
|
||||||
|
};
|
||||||
|
|
||||||
TEST_F(CerCRange_Test, Serialize)
|
TEST_F(CerCRange_Test, Serialize)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -50,6 +87,92 @@ namespace
|
||||||
EXPECT_TRUE(*i1 == *i2);
|
EXPECT_TRUE(*i1 == *i2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CerURange_Test, Serialize)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
cereal::JSONOutputArchive ar(mS);
|
||||||
|
ar(mR);
|
||||||
|
}
|
||||||
|
std::cout << mS.str() << std::endl;
|
||||||
|
RangePtr r = nullptr;
|
||||||
|
{
|
||||||
|
cereal::JSONInputArchive ar(mS);
|
||||||
|
ar(r);
|
||||||
|
}
|
||||||
|
EXPECT_EQ(r->size(), mR->size());
|
||||||
|
EXPECT_EQ(r->dim(), mR->dim());
|
||||||
|
auto i1 = r->begin();
|
||||||
|
auto i2 = mR->begin();
|
||||||
|
auto i1e = r->end();
|
||||||
|
auto i2e = mR->end();
|
||||||
|
for(; i1 != i1e; ++i1, ++i2){
|
||||||
|
EXPECT_TRUE(*i1 == *i2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CerYRange_Test, Serialize)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
cereal::JSONOutputArchive ar(mS);
|
||||||
|
ar(cereal::make_nvp("mR",mR));
|
||||||
|
//ar(mR);
|
||||||
|
}
|
||||||
|
std::cout << mS.str() << std::endl;
|
||||||
|
RangePtr r = nullptr;
|
||||||
|
{
|
||||||
|
cereal::JSONInputArchive ar(mS);
|
||||||
|
cer::save_load(ar, "mR", r);
|
||||||
|
}
|
||||||
|
EXPECT_EQ(r->size(), mR->size());
|
||||||
|
EXPECT_EQ(r->dim(), mR->dim());
|
||||||
|
auto i1 = r->begin();
|
||||||
|
auto i2 = mR->begin();
|
||||||
|
auto i1e = r->end();
|
||||||
|
auto i2e = mR->end();
|
||||||
|
for(; i1 != i1e; ++i1, ++i2){
|
||||||
|
EXPECT_TRUE(*i1 == *i2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CerYRange_Test, NoDuplicates)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
cereal::JSONOutputArchive ar(mS);
|
||||||
|
ar(cereal::make_nvp("mR",mR));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
cereal::JSONOutputArchive ar(mS2);
|
||||||
|
ar(cereal::make_nvp("mR",mR));
|
||||||
|
}
|
||||||
|
std::cout << mS.str() << std::endl;
|
||||||
|
RangePtr r = nullptr;
|
||||||
|
{
|
||||||
|
cereal::JSONInputArchive ar(mS);
|
||||||
|
//ar(r);
|
||||||
|
cer::save_load(ar, "mR", r);
|
||||||
|
}
|
||||||
|
RangePtr r2 = nullptr;
|
||||||
|
{
|
||||||
|
cereal::JSONInputArchive ar(mS2);
|
||||||
|
//ar(r2);
|
||||||
|
cer::save_load(ar, "mR", r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_TRUE(r == r2);
|
||||||
|
EXPECT_EQ(r->size(), r2->size());
|
||||||
|
EXPECT_EQ(r->dim(), r2->dim());
|
||||||
|
for(SizeT i = 0; i != r->dim(); ++i){
|
||||||
|
EXPECT_TRUE(r->sub(i) == r2->sub(i));
|
||||||
|
}
|
||||||
|
auto i1 = r->begin();
|
||||||
|
auto i2 = r2->begin();
|
||||||
|
auto i1e = r->end();
|
||||||
|
auto i2e = r2->end();
|
||||||
|
for(; i1 != i1e; ++i1, ++i2){
|
||||||
|
EXPECT_TRUE(*i1 == *i2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
|
Loading…
Reference in a new issue