From 81c4283353117a3f37ce177d8281d8408f84a0c2 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 12 Apr 2022 00:45:59 +0200 Subject: [PATCH] Add tests --- Makefile.am | 1 + tests/CMakeLists.txt | 2 + tests/io_determinant_hdf5.c | 202 ++++++++++++++++++++++++++++++++++++ tests/io_determinant_text.c | 202 ++++++++++++++++++++++++++++++++++++ 4 files changed, 407 insertions(+) create mode 100644 tests/io_determinant_hdf5.c create mode 100644 tests/io_determinant_text.c diff --git a/Makefile.am b/Makefile.am index 8cb5e01..8769674 100644 --- a/Makefile.am +++ b/Makefile.am @@ -127,6 +127,7 @@ TESTS_C += \ tests/io_dset_float_hdf5 \ tests/io_dset_int_hdf5 \ tests/io_dset_sparse_hdf5 \ + tests/io_determinant_hdf5 \ tests/io_safe_dset_float_hdf5 \ tests/io_str_hdf5 \ tests/io_dset_str_hdf5 \ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 26b3634..2d5e68b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,7 @@ set(Tests_text io_dset_float_text io_dset_str_text io_dset_sparse_text + io_determinant_text io_safe_dset_float_text io_dset_int_text io_num_text @@ -22,6 +23,7 @@ if(ENABLE_HDF5) io_dset_float_hdf5 io_dset_str_hdf5 io_dset_sparse_hdf5 + io_determinant_hdf5 io_safe_dset_float_hdf5 io_dset_int_hdf5 io_num_hdf5 diff --git a/tests/io_determinant_hdf5.c b/tests/io_determinant_hdf5.c new file mode 100644 index 0000000..298a673 --- /dev/null +++ b/tests/io_determinant_hdf5.c @@ -0,0 +1,202 @@ +#include "trexio.h" +#include +#include +#include +#include + +#define TEST_BACKEND TREXIO_HDF5 +#define TREXIO_FILE "test_determinant.h5" +#define RM_COMMAND "rm -f " TREXIO_FILE +#define SIZE 100 +#define N_CHUNKS 5 + +static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) { + +/* Try to write an array of sparse data into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // parameters to be written + int64_t* det_list; + + int mo_num = 150; + + det_list = (int64_t*) calloc(2*3*SIZE, sizeof(int64_t)); + + for(int i=0; i size_max) + offset_file_read = 97L; + offset_data_read = 1; + int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 + + if (offset != 0L) offset_file_read += offset; + + // read one chunk that will reach EOF and return TREXIO_END code + rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[6*offset_data_read]); + /* + printf("%s\n", trexio_string_of_error(rc)); + for (int i=0; i +#include +#include +#include + +#define TEST_BACKEND TREXIO_TEXT +#define TREXIO_FILE "test_determinant.dir" +#define RM_COMMAND "rm -rf " TREXIO_FILE +#define SIZE 100 +#define N_CHUNKS 5 + +static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) { + +/* Try to write an array of sparse data into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // parameters to be written + int64_t* det_list; + + int mo_num = 150; + + det_list = (int64_t*) calloc(2*3*SIZE, sizeof(int64_t)); + + for(int i=0; i size_max) + offset_file_read = 97L; + offset_data_read = 1; + int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 + + if (offset != 0L) offset_file_read += offset; + + // read one chunk that will reach EOF and return TREXIO_END code + rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[6*offset_data_read]); + /* + printf("%s\n", trexio_string_of_error(rc)); + for (int i=0; i