Skip to content

Commit

Permalink
add pytest for integration by range in Cp2kCube class
Browse files Browse the repository at this point in the history
  • Loading branch information
robinzyb committed Jul 12, 2024
1 parent 5c56022 commit 83fd6b4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
5 changes: 2 additions & 3 deletions tests/test_cell/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ def test_get_volume(self, sample_data):
expected_volume = np.linalg.det(self._create_expected_cell_matrix(cell_param))
assert cell.get_volume() == expected_volume

def test_get_dv(self, sample_data, capsys):
def test_get_dv(self, sample_data, caplog):
cell_param, grid_point, grid_spacing_matrix = sample_data
cell = Cp2kCell(cell_param, grid_point, grid_spacing_matrix)
if (grid_point is None) and (grid_spacing_matrix is None):
cell.get_dv()
captured = capsys.readouterr()
assert captured.out.splitlines()[-1] == "No grid point information is available"
assert caplog.messages[-1] == "No grid point information is available"
else:
print(cell.cell_matrix, grid_point, grid_spacing_matrix)
expected_grid_spacing_matrix = self._create_expected_grid_spacing_matrix(cell.cell_matrix, grid_point, grid_spacing_matrix)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_cube/answer_Si_bulk8-v_hartree-1_0.cube/mav.npy
Binary file not shown.
5 changes: 4 additions & 1 deletion tests/test_cube/gen_test_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
np.save(os.path.join(dir_name, "grid_point.npy"), cube.cell.grid_point)
np.save(os.path.join(dir_name, "gs_matrix.npy"), cube.cell.grid_spacing_matrix)
np.save(os.path.join(dir_name, "num_atoms.npy"), cube.num_atoms)
np.save(os.path.join(dir_name, "integral.npy"), cube.get_integration())
np.save(os.path.join(dir_name, "integration_all.npy"), cube.get_integration())
np.save(os.path.join(dir_name, "integration_x_5.0_7.0.npy"), cube.get_integration(start_x=5.0, end_x=7.0))
np.save(os.path.join(dir_name, "integration_y_5.0_7.0.npy"), cube.get_integration(start_y=5.0, end_y=7.0))
np.save(os.path.join(dir_name, "integration_z_5.0_7.0.npy"), cube.get_integration(start_z=5.0, end_z=7.0))
np.save(os.path.join(dir_name, "pav.npy"), cube.get_pav())
np.save(os.path.join(dir_name, "mav.npy"), cube.get_mav(l1=1, l2=1, ncov=2))
29 changes: 29 additions & 0 deletions tests/test_cube/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ def test_cube_vals(self, cube_and_answer):
cube_vals = cube.cube_vals
cube_vals_answer = np.load(os.path.join(answer_dir, "cube_vals.npy"))
assert np.all(cube_vals == cube_vals_answer)

def test_integration(self, cube_and_answer):
cube = cube_and_answer[0]
answer_dir = cube_and_answer[1]
integration = cube.get_integration()
integration_answer = np.load(os.path.join(answer_dir, "integration_all.npy"))
assert np.all(integration == integration_answer)

def test_integration_by_range_x(self, cube_and_answer):
cube = cube_and_answer[0]
answer_dir = cube_and_answer[1]
integration = cube.get_integration(start_x=5.0, end_x=7.0)
integration_answer = np.load(os.path.join(answer_dir, "integration_x_5.0_7.0.npy"))
assert np.all(integration == integration_answer)

def test_integration_by_range_y(self, cube_and_answer):
cube = cube_and_answer[0]
answer_dir = cube_and_answer[1]
integration = cube.get_integration(start_y=5.0, end_y=7.0)
integration_answer = np.load(os.path.join(answer_dir, "integration_y_5.0_7.0.npy"))
assert np.all(integration == integration_answer)

def test_integration_by_range_z(self, cube_and_answer):
cube = cube_and_answer[0]
answer_dir = cube_and_answer[1]
integration = cube.get_integration(start_z=5.0, end_z=7.0)
integration_answer = np.load(os.path.join(answer_dir, "integration_z_5.0_7.0.npy"))
assert np.all(integration == integration_answer)

def test_pav(self, cube_and_answer):
cube = cube_and_answer[0]
answer_dir = cube_and_answer[1]
Expand Down

0 comments on commit 83fd6b4

Please sign in to comment.