mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-04-25 09:54:44 +02:00
Adapt the tests
This commit is contained in:
parent
0bbe16efce
commit
405f19c4bc
@ -35,7 +35,7 @@ def test_void():
|
||||
def test_orbital_list():
|
||||
"""Convert one determinant into a list of orbitals."""
|
||||
orb_list_up, orb_list_dn = trexio.to_orbital_list_up_dn(int64_num, det_test)
|
||||
assert orb_list_up[0] == 0
|
||||
assert orb_list_up[0] == 0
|
||||
assert orb_list_dn[0] == 1
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ class TestIO:
|
||||
self.filename = filename
|
||||
if not mode:
|
||||
mode = self.mode
|
||||
else:
|
||||
else:
|
||||
self.mode = mode
|
||||
if not back_end:
|
||||
back_end = self.back_end
|
||||
@ -73,7 +73,7 @@ class TestIO:
|
||||
|
||||
self.test_file = trexio.File(filename, mode, back_end)
|
||||
assert self.test_file.exists
|
||||
|
||||
|
||||
|
||||
def test_close(self):
|
||||
"""Close the file."""
|
||||
@ -82,7 +82,7 @@ class TestIO:
|
||||
self.test_file.close()
|
||||
assert not self.test_file.isOpen
|
||||
|
||||
|
||||
|
||||
def test_errors(self):
|
||||
"""Test some exceptions based on trexio.Error class."""
|
||||
self.open(filename='unsafe_' + self.filename, mode='w', back_end=self.back_end)
|
||||
@ -103,7 +103,7 @@ class TestIO:
|
||||
trexio.write_nucleus_num(self.test_file, nucleus_num)
|
||||
assert trexio.has_nucleus_num(self.test_file)
|
||||
|
||||
|
||||
|
||||
def test_str(self):
|
||||
"""Write a string."""
|
||||
self.open()
|
||||
@ -133,7 +133,7 @@ class TestIO:
|
||||
"""Write array of coordinates."""
|
||||
self.open()
|
||||
if not trexio.has_nucleus_num(self.test_file):
|
||||
self.test_num()
|
||||
self.test_num()
|
||||
trexio.write_nucleus_coord(self.test_file, nucleus_coord)
|
||||
assert trexio.has_nucleus_coord(self.test_file)
|
||||
|
||||
@ -192,11 +192,21 @@ class TestIO:
|
||||
self.test_array_1D()
|
||||
self.test_array_2D()
|
||||
|
||||
assert trexio.has_nucleus(self.test_file)
|
||||
|
||||
trexio.delete_nucleus(self.test_file)
|
||||
|
||||
assert not trexio.has_nucleus_num(self.test_file)
|
||||
assert not trexio.has_nucleus_charge(self.test_file)
|
||||
assert not trexio.has_nucleus_coord(self.test_file)
|
||||
assert not trexio.has_nucleus(self.test_file)
|
||||
|
||||
|
||||
def test_has_group(self):
|
||||
"""Check existense of a group."""
|
||||
self.open()
|
||||
assert trexio.has_nucleus(self.test_file)
|
||||
assert not trexio.has_rdm(self.test_file)
|
||||
|
||||
|
||||
def test_context_manager(self):
|
||||
@ -315,6 +325,6 @@ class TestIO:
|
||||
|
||||
def test_str_read(self):
|
||||
"""Read a string."""
|
||||
self.open(mode='r')
|
||||
self.open(mode='r')
|
||||
point_group_r = trexio.read_nucleus_point_group(self.test_file)
|
||||
assert point_group_r == point_group
|
||||
|
@ -27,7 +27,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) {
|
||||
// write numerical attribute in an empty file
|
||||
rc = trexio_write_basis_shell_num(file, num);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
|
||||
// write numerical (integer) dataset in a file
|
||||
rc = trexio_write_basis_nucleus_index(file, nucl_index);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -51,10 +51,18 @@ static int test_has_dset (const char* file_name, const back_end_t backend) {
|
||||
|
||||
/*================= START OF TEST ==================*/
|
||||
|
||||
// open file
|
||||
// open file
|
||||
file = trexio_open(file_name, 'r', backend, &rc);
|
||||
assert (file != NULL);
|
||||
|
||||
// check that the group exists
|
||||
rc = trexio_has_basis(file);
|
||||
assert(rc==TREXIO_SUCCESS);
|
||||
|
||||
// check that the group does not exist
|
||||
rc = trexio_has_mo(file);
|
||||
assert(rc==TREXIO_HAS_NOT);
|
||||
|
||||
// check that the previously written dataset exists
|
||||
rc = trexio_has_basis_nucleus_index(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -130,5 +138,3 @@ int main(void) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) {
|
||||
// write numerical attribute in an empty file
|
||||
rc = trexio_write_basis_shell_num(file, num);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
|
||||
// write numerical (integer) dataset in a file
|
||||
rc = trexio_write_basis_nucleus_index(file, nucl_index);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -51,10 +51,18 @@ static int test_has_dset (const char* file_name, const back_end_t backend) {
|
||||
|
||||
/*================= START OF TEST ==================*/
|
||||
|
||||
// open file
|
||||
// open file
|
||||
file = trexio_open(file_name, 'r', backend, &rc);
|
||||
assert (file != NULL);
|
||||
|
||||
// check that the group exists
|
||||
rc = trexio_has_basis(file);
|
||||
assert(rc==TREXIO_SUCCESS);
|
||||
|
||||
// check that the group does not exist
|
||||
rc = trexio_has_mo(file);
|
||||
assert(rc==TREXIO_HAS_NOT);
|
||||
|
||||
// check that the previously written dataset exists
|
||||
rc = trexio_has_basis_nucleus_index(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -130,5 +138,3 @@ int main(void) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,6 +86,14 @@ static int test_has_dset_sparse (const char* file_name, const back_end_t backend
|
||||
assert (file != NULL);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
// check that the group exists
|
||||
rc = trexio_has_mo_2e_int(file);
|
||||
assert(rc==TREXIO_SUCCESS);
|
||||
|
||||
// check that the group does not exist
|
||||
rc = trexio_has_rdm(file);
|
||||
assert(rc==TREXIO_HAS_NOT);
|
||||
|
||||
// first check that mo_2e_int_eri_lr (we only write non-lr component in this unit test)
|
||||
rc = trexio_has_mo_2e_int_eri_lr(file);
|
||||
assert(rc==TREXIO_HAS_NOT);
|
||||
@ -147,7 +155,7 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
|
||||
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));
|
||||
|
||||
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
||||
offset_file_read = 97;
|
||||
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
|
||||
|
||||
@ -159,11 +167,6 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
|
||||
assert(chunk_read == eof_read_size_check);
|
||||
assert(index_read[4*size_r-1] == 0);
|
||||
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));
|
||||
/*
|
||||
for(int i=0; i<size_r; ++i){
|
||||
printf("%d %lf\n", index_read[4*i], value_read[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
|
@ -86,6 +86,14 @@ static int test_has_dset_sparse (const char* file_name, const back_end_t backend
|
||||
assert (file != NULL);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
// check that the group exists
|
||||
rc = trexio_has_mo_2e_int(file);
|
||||
assert(rc==TREXIO_SUCCESS);
|
||||
|
||||
// check that the group does not exist
|
||||
rc = trexio_has_rdm(file);
|
||||
assert(rc==TREXIO_HAS_NOT);
|
||||
|
||||
// first check that mo_2e_int_eri_lr (we only write non-lr component in this unit test)
|
||||
rc = trexio_has_mo_2e_int_eri_lr(file);
|
||||
assert(rc==TREXIO_HAS_NOT);
|
||||
|
@ -143,6 +143,12 @@ subroutine test_write(file_name, back_end)
|
||||
rc = trexio_has_determinant_list(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 4')
|
||||
|
||||
rc = trexio_has_nucleus(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 5')
|
||||
|
||||
rc = trexio_has_ao_2e_int(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 6')
|
||||
|
||||
rc = trexio_write_nucleus_num(trex_file, nucleus_num)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE NUM')
|
||||
|
||||
@ -207,6 +213,12 @@ subroutine test_write(file_name, back_end)
|
||||
rc = trexio_has_determinant_list(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 4')
|
||||
|
||||
rc = trexio_has_nucleus(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 5')
|
||||
|
||||
rc = trexio_has_ao_2e_int(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 6')
|
||||
|
||||
rc = trexio_close(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS CLOSE')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user