Add test_gridsys_get_double_grid_address

This commit is contained in:
Atsushi Togo 2023-01-22 22:09:03 +09:00
parent 11a4955f33
commit 616f2ba0c3
1 changed files with 26 additions and 8 deletions

View File

@ -6,16 +6,13 @@ extern "C" {
/**
* @brief gridsys_get_all_grid_addresses test
* Return all GR-grid addresses of {(X, Y, Z)} where X runs fastest.
* Return all GR-grid addresses of {(x, y, z)} where x runs fastest.
*/
TEST(test_gridsys, test_gridsys_get_all_grid_addresses) {
long(*gr_grid_addresses)[3];
long D_diag[3];
long D_diag[3] = {3, 4, 5};
long n, i, j, k, count;
D_diag[0] = 3;
D_diag[1] = 4;
D_diag[2] = 5;
n = D_diag[0] * D_diag[1] * D_diag[2];
gr_grid_addresses = (long(*)[3])malloc(sizeof(long[3]) * n);
gridsys_get_all_grid_addresses(gr_grid_addresses, D_diag);
@ -31,6 +28,28 @@ TEST(test_gridsys, test_gridsys_get_all_grid_addresses) {
}
}
}
free(gr_grid_addresses);
gr_grid_addresses = NULL;
}
/**
* @brief gridsys_get_double_grid_address
* Return double grid address of single grid address with shift in GR-grid.
* PS can be other than 0 and 1 for non-diagonal grid matrix.
*/
TEST(test_gridsys, test_gridsys_get_double_grid_address) {
long address_double[3];
long address[3] = {1, 2, 3};
long PS[8][3] = {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1},
{1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}};
long i, j;
for (i = 0; i < 8; i++) {
gridsys_get_double_grid_address(address_double, address, PS[i]);
for (j = 0; j < 3; j++) {
ASSERT_EQ(address_double[j], address[j] * 2 + PS[i][j]);
}
}
}
/* TEST(test_gridsys, test_gridsys_get_all_grid_addresses) {
@ -56,9 +75,8 @@ TEST(test_gridsys, test_gridsys_get_all_grid_addresses) {
printf("*** spg_get_ir_reciprocal_mesh of Rutile structure ***:\n");
num_ir = spg_get_ir_reciprocal_mesh(grid_address, grid_mapping_table, mesh,
is_shift, 1, lattice, position, types,
num_atom, 1e-5);
num_ir = spg_get_ir_reciprocal_mesh(grid_address, grid_mapping_table,
mesh, is_shift, 1, lattice, position, types, num_atom, 1e-5);
ASSERT_EQ(num_ir, 4200);
free(grid_address);