fix bug in DType + further yrange test
This commit is contained in:
parent
da4bf39c83
commit
99eb72bb76
4 changed files with 44 additions and 26 deletions
|
@ -30,21 +30,21 @@ namespace CNORXZ
|
|||
template <typename T>
|
||||
void DType::_mkToStr()
|
||||
{
|
||||
mToStr = [&](){
|
||||
return toString(std::any_cast<T>(mD));
|
||||
mToStr = [](const std::any& d){
|
||||
return toString(std::any_cast<T>(d));
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DType::_mkComp()
|
||||
{
|
||||
mComp = [&](const std::any& a){
|
||||
if(mD.type() != a.type()){
|
||||
mComp = [](const std::any& d, const std::any& a){
|
||||
if(d.type() != a.type()){
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
auto& at = std::any_cast<const T&>(a);
|
||||
auto& dt = std::any_cast<const T&>(mD);
|
||||
auto& dt = std::any_cast<const T&>(d);
|
||||
if(std::equal_to<T>{}(dt,at)){
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ namespace CNORXZ
|
|||
{
|
||||
private:
|
||||
std::any mD;
|
||||
std::function<String()> mToStr;
|
||||
std::function<Int(std::any)> mComp;
|
||||
std::function<String(const std::any&)> mToStr;
|
||||
std::function<Int(const std::any&,const std::any&)> mComp;
|
||||
|
||||
template <typename T>
|
||||
void _mkToStr();
|
||||
|
@ -35,15 +35,15 @@ namespace CNORXZ
|
|||
template <typename T>
|
||||
DType& operator=(const T& d);
|
||||
|
||||
String str() const { return mToStr(); }
|
||||
String str() const { return mToStr(mD); }
|
||||
const std::any& get() const { return mD; }
|
||||
|
||||
bool operator==(const DType& a) const { return mComp(a.mD) == 0; }
|
||||
bool operator!=(const DType& a) const { return mComp(a.mD) != 0; }
|
||||
bool operator<(const DType& a) const { return mComp(a.mD) == -1; }
|
||||
bool operator>(const DType& a) const { return mComp(a.mD) == 1; }
|
||||
bool operator<=(const DType& a) const { auto c = mComp(a.mD); return c <= 0; }
|
||||
bool operator>=(const DType& a) const { auto c = mComp(a.mD); return c == 1 or c == 0; }
|
||||
bool operator==(const DType& a) const { return mComp(mD,a.mD) == 0; }
|
||||
bool operator!=(const DType& a) const { return mComp(mD,a.mD) != 0; }
|
||||
bool operator<(const DType& a) const { return mComp(mD,a.mD) == -1; }
|
||||
bool operator>(const DType& a) const { return mComp(mD,a.mD) == 1; }
|
||||
bool operator<=(const DType& a) const { auto c = mComp(mD,a.mD); return c <= 0; }
|
||||
bool operator>=(const DType& a) const { auto c = mComp(mD,a.mD); return c == 1 or c == 0; }
|
||||
};
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
|
|
@ -260,7 +260,8 @@ namespace CNORXZ
|
|||
DType YIndex::meta() const
|
||||
{
|
||||
Vector<DType> v(mIs.size());
|
||||
std::transform(mIs.begin(), mIs.end(), v.begin(), [](const auto& x) { return x->meta(); });
|
||||
std::transform(mIs.begin(), mIs.end(), v.begin(),
|
||||
[](const auto& x) { return x->meta(); });
|
||||
return DType(v);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@ namespace
|
|||
CR_Test()
|
||||
{
|
||||
mSize = 7;
|
||||
cr = CRangeFactory(mSize).create();
|
||||
}
|
||||
|
||||
SizeT mSize;
|
||||
RangePtr cr;
|
||||
};
|
||||
|
||||
class UR_Test : public ::testing::Test
|
||||
|
@ -32,9 +34,11 @@ namespace
|
|||
{
|
||||
mMeta = { "These", "are", "test", "strings", "foo", "bar", "baz" };
|
||||
std::sort(mMeta.begin(), mMeta.end(), std::less<String>());
|
||||
ur = URangeFactory<String>(mMeta).create();
|
||||
}
|
||||
|
||||
Vector<String> mMeta;
|
||||
RangePtr ur;
|
||||
};
|
||||
|
||||
class MR_Test : public ::testing::Test
|
||||
|
@ -46,10 +50,16 @@ namespace
|
|||
mMeta = { "test", "strings", "foo" };
|
||||
std::sort(mMeta.begin(), mMeta.end(), std::less<String>());
|
||||
mSize = 7;
|
||||
auto cr = CRangeFactory(mSize).create();
|
||||
auto crx = std::dynamic_pointer_cast<CRange>(cr);
|
||||
auto ur = URangeFactory<String>(mMeta).create();
|
||||
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
|
||||
mr = mrange(crx,urx);
|
||||
}
|
||||
|
||||
Vector<String> mMeta;
|
||||
SizeT mSize;
|
||||
RangePtr mr;
|
||||
};
|
||||
|
||||
class YR_Test : public ::testing::Test
|
||||
|
@ -61,15 +71,18 @@ namespace
|
|||
mMeta = { "test", "strings", "foo" };
|
||||
std::sort(mMeta.begin(), mMeta.end(), std::less<String>());
|
||||
mSize = 7;
|
||||
auto cr = CRangeFactory(mSize).create();
|
||||
auto ur = URangeFactory<String>(mMeta).create();
|
||||
yr = cr * ur;
|
||||
}
|
||||
|
||||
Vector<String> mMeta;
|
||||
SizeT mSize;
|
||||
RangePtr yr;
|
||||
};
|
||||
|
||||
TEST_F(CR_Test, Basics)
|
||||
{
|
||||
auto cr = CRangeFactory(mSize).create();
|
||||
auto crx = std::dynamic_pointer_cast<CRange>(cr);
|
||||
EXPECT_EQ(cr->size(), mSize);
|
||||
EXPECT_EQ(crx->size(), mSize);
|
||||
|
@ -103,7 +116,6 @@ namespace
|
|||
|
||||
TEST_F(UR_Test, Basics)
|
||||
{
|
||||
auto ur = URangeFactory<String>(mMeta).create();
|
||||
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
|
||||
EXPECT_EQ(ur->size(), mMeta.size());
|
||||
EXPECT_EQ(urx->size(), mMeta.size());
|
||||
|
@ -135,11 +147,6 @@ namespace
|
|||
|
||||
TEST_F(MR_Test, Basics)
|
||||
{
|
||||
auto cr = CRangeFactory(mSize).create();
|
||||
auto crx = std::dynamic_pointer_cast<CRange>(cr);
|
||||
auto ur = URangeFactory<String>(mMeta).create();
|
||||
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
|
||||
auto mr = mrange(crx,urx);
|
||||
auto mrx = std::dynamic_pointer_cast<MRange<CRange,URange<String>>>(mr);
|
||||
|
||||
EXPECT_EQ(mr->size(), mMeta.size()*mSize);
|
||||
|
@ -193,9 +200,6 @@ namespace
|
|||
|
||||
TEST_F(YR_Test, Basics)
|
||||
{
|
||||
auto cr = CRangeFactory(mSize).create();
|
||||
auto ur = URangeFactory<String>(mMeta).create();
|
||||
auto yr = cr * ur;
|
||||
|
||||
EXPECT_EQ(yr->size(), mMeta.size()*mSize);
|
||||
EXPECT_EQ(yr->dim(), 2u);
|
||||
|
@ -205,6 +209,19 @@ namespace
|
|||
EXPECT_EQ(yr->begin().pos(), 0u);
|
||||
EXPECT_EQ(yr->end().pos(), yr->size());
|
||||
|
||||
const SizeT mmsize = mMeta.size();
|
||||
auto mkm = [&](SizeT i) { return Vector<DType>({DType(i/mmsize),DType(mMeta[i % mmsize])}); };
|
||||
|
||||
SizeT cnt = 0;
|
||||
auto endxi = yr->end();
|
||||
for(auto xi = yr->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;
|
||||
}
|
||||
|
||||
}
|
||||
// RCast_Test
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue