From 690b0d08306851048e3828969932a621e3986e95 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 3 Mar 2024 18:31:13 +0100 Subject: [PATCH] WIP: ltest --- src/include/array/array_base.cc.h | 1 + src/tests/CMakeLists.txt | 5 ++ src/tests/l_unit_test.cc | 77 +++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 src/tests/l_unit_test.cc diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index dcc1779..b8185f6 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -234,6 +234,7 @@ namespace CNORXZ template T& ArrayBase::operator[](const IndexInterface& i) { + // TODO: if format of i is non-trivial, use that format without check (checks only in at()!) if(this->formatIsTrivial()){ return data()[i.lex()]; } diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 773b306..5a5f8d5 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -27,6 +27,11 @@ add_dependencies(mautest cnorxz) target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) add_test(NAME mautest COMMAND mautest) +add_executable(lutest l_unit_test.cc) +add_dependencies(lutest cnorxz) +target_link_libraries(lutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) +add_test(NAME lutest COMMAND lutest) + add_executable(oputest operation_unit_test.cc) add_dependencies(oputest cnorxz) target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) diff --git a/src/tests/l_unit_test.cc b/src/tests/l_unit_test.cc new file mode 100644 index 0000000..a157ab2 --- /dev/null +++ b/src/tests/l_unit_test.cc @@ -0,0 +1,77 @@ +// -*- C++ -*- +/** + + @file tests/l_unit_test.cc + @brief MArray unit tests. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + +**/ + +#include +#include + +#include "gtest/gtest.h" + +#include "cnorxz.h" +#include "test_numbers.h" + +namespace +{ + using namespace CNORXZ; + using Test::Numbers; + + class L_Test : public ::testing::Test + { + protected: + + L_Test() + { + auto a4 = Arr { 0,1,2,3 }; + auto a3 = Arr { 0,1,2 }; + mSpinR = std::dynamic_pointer_cast> ( SRangeFactory(a4).create() ); + mColorR = std::dynamic_pointer_cast> ( SRangeFactory(a3).create() ); + mSpatialR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); + mTemporalR = std::dynamic_pointer_cast ( CRangeFactory(24).create() ); + mLocSR = std::dynamic_pointer_cast ( CRangeFactory(4).create() ); + mLocTR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); + mRaSR = std::dynamic_pointer_cast ( CRangeFactory(2).create() ); + mRaTR = std::dynamic_pointer_cast ( CRangeFactory(3).create() ); + mData = MArray(yrange({mRaTR,mRaSR,mRaSR,mRaSR,mLocTR,mLocSR,mLocSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR})); + mDataFormat = mData.begin().format(); + auto vf = mDataFormat.all(); + vf[0] = mDataFormat[0]; + vf[1] = mDataFormat[4]; + vf[2] = mDataFormat[1]; + vf[3] = mDataFormat[5]; + vf[4] = mDataFormat[2]; + vf[5] = mDataFormat[6]; + vf[6] = mDataFormat[3]; + vf[7] = mDataFormat[7]; + mViewFormat = YFormat(vf); + mView = Slice(yrange({mRaTR,mLocTR,mRaSR,mLocSR,mRaSR,mLocSR,mRaSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR}), &mData, mViewFormat, 0); + } + + Sptr> mSpinR; + Sptr> mColorR; + Sptr mSpatialR; + Sptr mTemporalR; + Sptr mLocSR; + Sptr mLocTR; + Sptr mRaSR; + Sptr mRaTR; + + MArray mData; + Slice mView; + YFormat mDataFormat; + YFormat mViewFormat; + }; + + TEST_F(L_Test, Basic) + { + EXPECT_EQ(mData.size(), mView.size()); + VCHECK(mData.size()); + } + +}