From 53d51a7902aa71fb818b7e43522cb76f993873ec Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 30 Mar 2021 11:56:04 +0200 Subject: [PATCH] add tests for has_ functionality --- src/test.c | 24 ++++++++++++++++++++---- src/test.f90 | 20 +++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/test.c b/src/test.c index c6605fe..041bf25 100644 --- a/src/test.c +++ b/src/test.c @@ -47,12 +47,22 @@ int test_h5write() { file = trexio_open(file_name, 'w', TREXIO_HDF5); assert (file != NULL); + rc = trexio_has_nucleus_num(file); + assert (rc == TREXIO_HAS_NOT); + rc = trexio_has_nucleus_coord(file); + assert (rc == TREXIO_HAS_NOT); + // works: try writing info in an empty file rc = trexio_write_nucleus_num(file,num); assert (rc == TREXIO_SUCCESS); rc = trexio_write_nucleus_coord(file,coord); assert (rc == TREXIO_SUCCESS); + rc = trexio_has_nucleus_num(file); + assert (rc == TREXIO_SUCCESS); + rc = trexio_has_nucleus_coord(file); + assert (rc == TREXIO_SUCCESS); + // should not work: try to rewrite the nucleus_num rc = trexio_write_nucleus_num(file,25); assert (rc != TREXIO_SUCCESS); @@ -101,10 +111,6 @@ int test_h5read() { rc = trexio_read_nucleus_coord(file,coord); assert (rc == TREXIO_SUCCESS); - /*for (size_t i=0; i<3*num; i++){ - printf("%lf \n", coord[i]); - }*/ - double x = coord[30] - 2.14171677; assert( x*x < 1.e-12); @@ -159,6 +165,11 @@ int test_write() { file = trexio_open(file_name, 'w', TREXIO_TEXT); assert (file != NULL); + rc = trexio_has_nucleus_num(file); + assert (rc == TREXIO_HAS_NOT); + rc = trexio_has_nucleus_coord(file); + assert (rc == TREXIO_HAS_NOT); + rc = trexio_write_nucleus_num(file,num); assert (rc == TREXIO_SUCCESS); @@ -168,6 +179,11 @@ int test_write() { rc = trexio_write_nucleus_coord(file,coord); assert (rc == TREXIO_SUCCESS); + rc = trexio_has_nucleus_num(file); + assert (rc == TREXIO_SUCCESS); + rc = trexio_has_nucleus_coord(file); + assert (rc == TREXIO_SUCCESS); + rc = trexio_close(file); assert (rc == TREXIO_SUCCESS); diff --git a/src/test.f90 b/src/test.f90 index 3489e7f..fddf0a1 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -33,18 +33,28 @@ subroutine test_write() 2.14171677 , 1.23652075 , 0.00000000 , & 0.00000000 , 2.47304151 , 0.00000000 /) -! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT) - trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5) + trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT) +! trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5) + + rc = trexio_has_nucleus_num(trex_file) + if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 1' + rc = trexio_has_nucleus_charge(trex_file) + if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 2' rc = trexio_write_nucleus_num(trex_file, num) if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE NUM' - + rc = trexio_write_nucleus_charge(trex_file, charge) if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE CHARGE' rc = trexio_write_nucleus_coord(trex_file, coord) if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE COORD' + rc = trexio_has_nucleus_num(trex_file) + if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 1' + rc = trexio_has_nucleus_coord(trex_file) + if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 2' + rc = trexio_close(trex_file) if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE' @@ -82,8 +92,8 @@ subroutine test_read() num = 12 -! trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT) - trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5) + trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT) +! trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5) rc = trexio_read_nucleus_num(trex_file, num_read)