WIP: reformat tests
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Christian Zimmermann 2023-12-25 15:08:40 +01:00
parent df2a8e5a0b
commit 62b75c01a0
7 changed files with 89 additions and 20 deletions

View file

@ -99,6 +99,8 @@ namespace CNORXZ
private: private:
Vector<UPos> mB; Vector<UPos> mB;
}; };
bool formatIsTrivial(const Vector<SizeT>& f, const Vector<SizeT>& s);
} }
#endif #endif

View file

@ -186,11 +186,10 @@ namespace CNORXZ
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>
SIndex<MetaT,S> SIndex<MetaT,S>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const SIndex<MetaT,S> SIndex<MetaT,S>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
{ {
CXZ_ASSERT(f.size() == 1, "expected format of dimension 1, got " << toString(f)); CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
CXZ_ASSERT(s.size() == 1, "expected sizes of dimension 1, got " << toString(s)); << " vs " << lmax().val());
CXZ_ASSERT(f[0] == 1, "trivial format ([1]), got " << toString(f)); CXZ_ASSERT(CNORXZ::formatIsTrivial(f,s), "format is not trivial: f = " << toString(f)
CXZ_ASSERT(s[0] == lmax().val(), "expected size to be equal to index size (" << << ", s = " << toString(s));
lmax().val() << "), got " << s[0]);
return *this; return *this;
} }

View file

@ -172,16 +172,10 @@ namespace CNORXZ
template <typename MetaT> template <typename MetaT>
UIndex<MetaT> UIndex<MetaT>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const UIndex<MetaT> UIndex<MetaT>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
{ {
// can also get multi dim stuff, but: CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
// * overall extension must match << " vs " << lmax().val());
// * f must be trivial CXZ_ASSERT(CNORXZ::formatIsTrivial(f,s), "format is not trivial: f = " << toString(f)
/* << ", s = " << toString(s));
CXZ_ASSERT(f.size() == 1, "expected format of dimension 1, got " << toString(f));
CXZ_ASSERT(s.size() == 1, "expected sizes of dimension 1, got " << toString(s));
CXZ_ASSERT(f[0] == 1, "trivial format ([1]), got " << toString(f));
CXZ_ASSERT(s[0] == lmax().val(), "expected size to be equal to index size (" <<
lmax().val() << "), got " << s[0]);
*/
return *this; return *this;
} }

View file

@ -146,11 +146,10 @@ namespace CNORXZ
CIndex CIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const CIndex CIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
{ {
CXZ_ASSERT(f.size() == 1, "expected format of dimension 1, got " << toString(f)); CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
CXZ_ASSERT(s.size() == 1, "expected sizes of dimension 1, got " << toString(s)); << " vs " << lmax().val());
CXZ_ASSERT(f[0] == 1, "trivial format ([1]), got " << toString(f)); CXZ_ASSERT(CNORXZ::formatIsTrivial(f,s), "format is not trivial: f = " << toString(f)
CXZ_ASSERT(s[0] == lmax().val(), "expected size to be equal to index size (" << << ", s = " << toString(s));
lmax().val() << "), got " << s[0]);
return *this; return *this;
} }

View file

@ -27,4 +27,18 @@ namespace CNORXZ
return mB[i]; return mB[i];
} }
bool formatIsTrivial(const Vector<SizeT>& f, const Vector<SizeT>& s)
{
CXZ_ASSERT(f.size() == s.size(), "got vectors with different size ("
<< f.size() << " vs " << s.size() << ")");
SizeT x = 1;
for(SizeT i_ = f.size(); i_ != 0; --i_) {
const SizeT i = i_-1;
if(f[i] != x) {
return false;
}
x *= s[i];
}
return true;
}
} }

View file

@ -17,6 +17,11 @@ add_dependencies(rutest cnorxz)
target_link_libraries(rutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) target_link_libraries(rutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME rutest COMMAND rutest) add_test(NAME rutest COMMAND rutest)
add_executable(iftest index_format_test.cc)
add_dependencies(iftest cnorxz)
target_link_libraries(iftest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME iftest COMMAND iftest)
add_executable(mautest marray_unit_test.cc) add_executable(mautest marray_unit_test.cc)
add_dependencies(mautest cnorxz) add_dependencies(mautest cnorxz)
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)

View file

@ -0,0 +1,56 @@
#include <cstdlib>
#include <iostream>
#include "gtest/gtest.h"
//#include "cnorxz.h"
#include "ranges/ranges.h"
#include "array/array.h"
namespace
{
using namespace CNORXZ;
class Format_Test : public ::testing::Test
{
protected:
Format_Test()
{
mMeta7 = { "These", "are", "test", "strings", "foo", "bar", "baz" };
auto sr2 = SRangeFactory<SizeT,2>(Arr<SizeT,2>{0,1}).create();
auto ur3x = std::dynamic_pointer_cast<URange<Real>>
(URangeFactory<Real>(Vector<Real>{3.141,1.6,2.7}).create());
auto cr5x = std::dynamic_pointer_cast<CRange>(CRangeFactory(5).create());
auto ur7x = std::dynamic_pointer_cast<URange<String>>
(URangeFactory<String>(mMeta7).create());
auto mr105 = mrange(ur3x,ur7x,cr5x);
auto cr11 = CRangeFactory(11).create();
auto cr13 = CRangeFactory(13).create();
mRange = yrange({cr11,mr105,cr13,sr2});
}
Vector<String> mMeta7;
RangePtr mRange;
};
TEST_F(Format_Test, RangeCheck)
{
EXPECT_EQ(mRange->size(), 2*105*11*13);
auto yi = mRange->begin();
EXPECT_EQ(yi.lmax().val(), mRange->size());
EXPECT_EQ(yi.pmax().val(), mRange->size());
}
TEST_F(Format_Test, CFormat)
{
CIndex ci(mRange);
EXPECT_EQ(ci.lmax().val(), mRange->size());
auto yi = mRange->begin();
auto rfi = ci.reformat( yi.deepFormat(), yi.deepMax() );
VCHECK(toString(yi.deepFormat()));
VCHECK(toString(yi.deepMax()));
EXPECT_EQ(rfi.lmax().val(), mRange->size());
}
}