1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00

add tests for has_ functionality

This commit is contained in:
q-posev 2021-03-30 11:56:04 +02:00
parent 0d0bed0585
commit 53d51a7902
2 changed files with 35 additions and 9 deletions

View File

@ -47,12 +47,22 @@ int test_h5write() {
file = trexio_open(file_name, 'w', TREXIO_HDF5); file = trexio_open(file_name, 'w', TREXIO_HDF5);
assert (file != NULL); 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 // works: try writing info in an empty file
rc = trexio_write_nucleus_num(file,num); rc = trexio_write_nucleus_num(file,num);
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
rc = trexio_write_nucleus_coord(file,coord); rc = trexio_write_nucleus_coord(file,coord);
assert (rc == TREXIO_SUCCESS); 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 // should not work: try to rewrite the nucleus_num
rc = trexio_write_nucleus_num(file,25); rc = trexio_write_nucleus_num(file,25);
assert (rc != TREXIO_SUCCESS); assert (rc != TREXIO_SUCCESS);
@ -101,10 +111,6 @@ int test_h5read() {
rc = trexio_read_nucleus_coord(file,coord); rc = trexio_read_nucleus_coord(file,coord);
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
/*for (size_t i=0; i<3*num; i++){
printf("%lf \n", coord[i]);
}*/
double x = coord[30] - 2.14171677; double x = coord[30] - 2.14171677;
assert( x*x < 1.e-12); assert( x*x < 1.e-12);
@ -159,6 +165,11 @@ int test_write() {
file = trexio_open(file_name, 'w', TREXIO_TEXT); file = trexio_open(file_name, 'w', TREXIO_TEXT);
assert (file != NULL); 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); rc = trexio_write_nucleus_num(file,num);
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);
@ -168,6 +179,11 @@ int test_write() {
rc = trexio_write_nucleus_coord(file,coord); rc = trexio_write_nucleus_coord(file,coord);
assert (rc == TREXIO_SUCCESS); 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); rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS); assert (rc == TREXIO_SUCCESS);

View File

@ -33,18 +33,28 @@ subroutine test_write()
2.14171677 , 1.23652075 , 0.00000000 , & 2.14171677 , 1.23652075 , 0.00000000 , &
0.00000000 , 2.47304151 , 0.00000000 /) 0.00000000 , 2.47304151 , 0.00000000 /)
! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT) 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('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) rc = trexio_write_nucleus_num(trex_file, num)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE NUM' if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE NUM'
rc = trexio_write_nucleus_charge(trex_file, charge) rc = trexio_write_nucleus_charge(trex_file, charge)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE CHARGE' if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE CHARGE'
rc = trexio_write_nucleus_coord(trex_file, coord) rc = trexio_write_nucleus_coord(trex_file, coord)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE 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) rc = trexio_close(trex_file)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE' if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE'
@ -82,8 +92,8 @@ subroutine test_read()
num = 12 num = 12
! trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT) 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('test_hdf5_fort.h5', 'r', TREXIO_HDF5)
rc = trexio_read_nucleus_num(trex_file, num_read) rc = trexio_read_nucleus_num(trex_file, num_read)