diff --git a/tests/BlockUniTensor_test.h b/tests/BlockUniTensor_test.h index 75c874f9..f4b975a1 100644 --- a/tests/BlockUniTensor_test.h +++ b/tests/BlockUniTensor_test.h @@ -9,7 +9,7 @@ using namespace cytnx; using namespace TestTools; class BlockUniTensorTest : public ::testing::Test { public: - std::string data_dir = "../../tests/test_data_base/common/BlockUniTensor/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/common/BlockUniTensor/"; Bond B1 = Bond(BD_IN, {Qs(0) >> 1, Qs(1) >> 2}); Bond B2 = Bond(BD_IN, {Qs(0), Qs(1)}, {3, 4}); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 94e198dd..965365e7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,6 +2,12 @@ if(BACKEND_TORCH) else() +# Define the path to the test data directory +set(CYTNX_TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_data_base") + +# Add the preprocessor definition for CYTNX_TEST_DATA_DIR +add_compile_definitions(CYTNX_TEST_DATA_DIR="${CYTNX_TEST_DATA_DIR}") + add_executable( test_main test_tools.cpp diff --git a/tests/DenseUniTensor_test.h b/tests/DenseUniTensor_test.h index cab2ff0a..f859a588 100644 --- a/tests/DenseUniTensor_test.h +++ b/tests/DenseUniTensor_test.h @@ -10,7 +10,7 @@ using namespace std; using namespace TestTools; class DenseUniTensorTest : public ::testing::Test { public: - std::string data_dir = "../../tests/test_data_base/common/DenseUniTensor/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/common/DenseUniTensor/"; UniTensor ut_uninit; UniTensor utzero345; diff --git a/tests/Storage_test.cpp b/tests/Storage_test.cpp index d07cd33c..227f1f45 100644 --- a/tests/Storage_test.cpp +++ b/tests/Storage_test.cpp @@ -96,7 +96,7 @@ TEST_F(StorageTest, from_vec_cf) { // create suite for all real types (exclude bool) using vector_typelist = testing::Types; + cytnx_double, cytnx_float, cytnx_uint16, cytnx_int16>; template struct vector_suite : testing::Test {}; TYPED_TEST_SUITE(vector_suite, vector_typelist); diff --git a/tests/Tensor_test.h b/tests/Tensor_test.h index 8a91068d..3388f159 100644 --- a/tests/Tensor_test.h +++ b/tests/Tensor_test.h @@ -8,7 +8,7 @@ using namespace cytnx; using namespace std; class TensorTest : public ::testing::Test { public: - std::string data_dir = "../../tests/test_data_base/common/Tensor/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/common/Tensor/"; Tensor tzero345; Tensor tone345; diff --git a/tests/common_data_generator.cpp b/tests/common_data_generator.cpp index e8991ef5..ac95dee3 100644 --- a/tests/common_data_generator.cpp +++ b/tests/common_data_generator.cpp @@ -18,7 +18,7 @@ using namespace TestTools; namespace CommonDataGen { - std::string dataRoot = "../../tests/test_data_base/common/"; + std::string dataRoot = CYTNX_TEST_DATA_DIR "/common/"; static std::vector dtype_list1 = { Type.ComplexDouble, Type.Double, diff --git a/tests/gpu/BlockUniTensor_test.h b/tests/gpu/BlockUniTensor_test.h index e558330f..8a633514 100644 --- a/tests/gpu/BlockUniTensor_test.h +++ b/tests/gpu/BlockUniTensor_test.h @@ -10,7 +10,7 @@ using namespace TestTools; class BlockUniTensorTest : public ::testing::Test { public: - std::string data_dir = "../../../tests/test_data_base/common/BlockUniTensor/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/common/BlockUniTensor/"; Bond B1 = Bond(BD_IN, {Qs(0) >> 1, Qs(1) >> 2}); Bond B2 = Bond(BD_IN, {Qs(0), Qs(1)}, {3, 4}); diff --git a/tests/gpu/DenseUniTensor_test.h b/tests/gpu/DenseUniTensor_test.h index 26970711..388e664b 100644 --- a/tests/gpu/DenseUniTensor_test.h +++ b/tests/gpu/DenseUniTensor_test.h @@ -10,7 +10,7 @@ using namespace std; using namespace TestTools; class DenseUniTensorTest : public ::testing::Test { public: - std::string data_dir = "../../../tests/test_data_base/common/DenseUniTensor/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/common/DenseUniTensor/"; UniTensor utzero345; UniTensor utone345; diff --git a/tests/gpu/Tensor_test.h b/tests/gpu/Tensor_test.h index 09805f99..36c61b9b 100644 --- a/tests/gpu/Tensor_test.h +++ b/tests/gpu/Tensor_test.h @@ -8,7 +8,7 @@ using namespace cytnx; using namespace std; class TensorTest : public ::testing::Test { public: - std::string data_dir = "../../../tests/test_data_base/common/Tensor/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/common/Tensor/"; Tensor tzero345; Tensor tone345; diff --git a/tests/gpu/common_data_generator.cpp b/tests/gpu/common_data_generator.cpp index e8991ef5..ac95dee3 100644 --- a/tests/gpu/common_data_generator.cpp +++ b/tests/gpu/common_data_generator.cpp @@ -18,7 +18,7 @@ using namespace TestTools; namespace CommonDataGen { - std::string dataRoot = "../../tests/test_data_base/common/"; + std::string dataRoot = CYTNX_TEST_DATA_DIR "/common/"; static std::vector dtype_list1 = { Type.ComplexDouble, Type.Double, diff --git a/tests/gpu/linalg_test/GeSvd_test.cpp b/tests/gpu/linalg_test/GeSvd_test.cpp index 385b9aab..3437b5a9 100644 --- a/tests/gpu/linalg_test/GeSvd_test.cpp +++ b/tests/gpu/linalg_test/GeSvd_test.cpp @@ -14,9 +14,8 @@ namespace GesvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& Tout); bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans); - std::string data_root = "../../../tests/test_data_base/"; - std::string src_data_root = data_root + "common/"; - std::string ans_data_root = data_root + "linalg/Gesvd/"; + std::string src_data_root = CYTNX_TEST_DATA_DIR "/common/"; + std::string ans_data_root = CYTNX_TEST_DATA_DIR "/linalg/Gesvd/"; // normal test /*=====test info===== diff --git a/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp b/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp index a922b63b..f58c241c 100644 --- a/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp +++ b/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp @@ -19,11 +19,11 @@ class MyOp2 : public LinOp { public: UniTensor H; MyOp2(int dim) : LinOp("mv", dim) { - Tensor A = Tensor::Load("../../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_A.cytn") + Tensor A = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_A.cytn") .to(cytnx::Device.cuda); - Tensor B = Tensor::Load("../../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_B.cytn") + Tensor B = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_B.cytn") .to(cytnx::Device.cuda); - Tensor C = Tensor::Load("../../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_C.cytn") + Tensor C = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_C.cytn") .to(cytnx::Device.cuda); Bond lan_I = Bond(BD_IN, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9}); Bond lan_J = Bond(BD_OUT, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9}); diff --git a/tests/gpu/linalg_test/Svd_test.cpp b/tests/gpu/linalg_test/Svd_test.cpp index ed7848b8..917a07d7 100644 --- a/tests/gpu/linalg_test/Svd_test.cpp +++ b/tests/gpu/linalg_test/Svd_test.cpp @@ -14,9 +14,8 @@ namespace SvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& Tout); bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans); - std::string data_root = "../../../tests/test_data_base/"; - std::string src_data_root = data_root + "common/"; - std::string ans_data_root = data_root + "linalg/Svd/"; + std::string src_data_root = CYTNX_TEST_DATA_DIR "/common/"; + std::string ans_data_root = CYTNX_TEST_DATA_DIR "/linalg/Svd/"; // normal test /*=====test info===== diff --git a/tests/gpu/linalg_test/linalg_test.h b/tests/gpu/linalg_test/linalg_test.h index f2fe0976..183cc180 100644 --- a/tests/gpu/linalg_test/linalg_test.h +++ b/tests/gpu/linalg_test/linalg_test.h @@ -22,7 +22,7 @@ class linalg_Test : public ::testing::Test { Tensor eye3x3cd = eye(3, Type.ComplexDouble).to(cytnx::Device.cuda); Tensor zeros3x3cd = zeros(9, Type.ComplexDouble).reshape(3, 3).to(cytnx::Device.cuda); - std::string data_dir = "../../../tests/test_data_base/linalg/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/linalg/"; // ==================== svd_truncate =================== Bond svd_I = Bond(BD_OUT, {Qs(1), Qs(-1)}, {1, 1}); Bond svd_J = diff --git a/tests/linalg_test/GeSvd_test.cpp b/tests/linalg_test/GeSvd_test.cpp index c72ed186..6782f584 100644 --- a/tests/linalg_test/GeSvd_test.cpp +++ b/tests/linalg_test/GeSvd_test.cpp @@ -14,9 +14,8 @@ namespace GesvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& Tout); bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans); - std::string data_root = "../../tests/test_data_base/"; - std::string src_data_root = data_root + "common/"; - std::string ans_data_root = data_root + "linalg/Gesvd/"; + std::string src_data_root = CYTNX_TEST_DATA_DIR "/common/"; + std::string ans_data_root = CYTNX_TEST_DATA_DIR "/linalg/Gesvd/"; // normal test /*=====test info===== diff --git a/tests/linalg_test/Lanczos_Gnd_test.cpp b/tests/linalg_test/Lanczos_Gnd_test.cpp index 4e602bcb..05fceefd 100644 --- a/tests/linalg_test/Lanczos_Gnd_test.cpp +++ b/tests/linalg_test/Lanczos_Gnd_test.cpp @@ -17,9 +17,9 @@ class MyOp2 : public LinOp { public: UniTensor H; MyOp2(int dim) : LinOp("mv", dim) { - Tensor A = Tensor::Load("../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_A.cytn"); - Tensor B = Tensor::Load("../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_B.cytn"); - Tensor C = Tensor::Load("../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_C.cytn"); + Tensor A = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_A.cytn"); + Tensor B = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_B.cytn"); + Tensor C = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_C.cytn"); Bond lan_I = Bond(BD_IN, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9}); Bond lan_J = Bond(BD_OUT, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9}); H = UniTensor({lan_I, lan_J}); diff --git a/tests/linalg_test/Svd_test.cpp b/tests/linalg_test/Svd_test.cpp index 8addd4fc..4c38febd 100644 --- a/tests/linalg_test/Svd_test.cpp +++ b/tests/linalg_test/Svd_test.cpp @@ -14,9 +14,8 @@ namespace SvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& Tout); bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans); - std::string data_root = "../../tests/test_data_base/"; - std::string src_data_root = data_root + "common/"; - std::string ans_data_root = data_root + "linalg/Svd/"; + std::string src_data_root = CYTNX_TEST_DATA_DIR "/common/"; + std::string ans_data_root = CYTNX_TEST_DATA_DIR "/linalg/Svd/"; // normal test /*=====test info===== diff --git a/tests/linalg_test/linalg_test.h b/tests/linalg_test/linalg_test.h index 773c84fe..e45b0da3 100644 --- a/tests/linalg_test/linalg_test.h +++ b/tests/linalg_test/linalg_test.h @@ -27,7 +27,7 @@ class linalg_Test : public ::testing::Test { UniTensor ones3x3cd_ut = UniTensor(ones3x3cd, false, -1); UniTensor invertable3x3cd_ut = UniTensor(invertable3x3cd, false, -1); - std::string data_dir = "../../tests/test_data_base/linalg/"; + std::string data_dir = CYTNX_TEST_DATA_DIR "/linalg/"; // ==================== svd_truncate =================== Bond svd_I = Bond(BD_OUT, {Qs(1), Qs(-1)}, {1, 1}); Bond svd_J =