Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial test #21

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ compile_commands.json
CTestTestfile.cmake
_deps
build*
/examples/__pycache__
# pixi environments
.pixi
*.egg-info
37 changes: 37 additions & 0 deletions examples/test_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from itertools import pairwise
import os
from pathlib import Path
import numpy as np
import pytest

@pytest.mark.parametrize("filename", ["A", "Ciap", "pVp", "SENT"])
def test_output(filename):
# Convert from the script location to where the output files should be located.
script_dir = Path(os.path.abspath(__file__)).parent
example_output_dir = script_dir.parent / "build" / "examples" / "geom_1"

with open(example_output_dir / f"{filename}_ref") as reference_output:
reference_output_lines = reference_output.readlines()

matrix_boundaries = [
line_num
for line_num, line in enumerate(reference_output_lines)
# Get header lines for matrices and blank last line.
if line.strip().endswith(":")
] + [len(reference_output_lines)]

# Loop over each matrix in the file and compare to the reference.
for header_row, end_row in pairwise(matrix_boundaries):
start_row = header_row + 1
num_rows = end_row - start_row
matrix = np.loadtxt(
example_output_dir / filename,
skiprows=start_row,
max_rows=num_rows,
)
reference_matrix = np.loadtxt(
example_output_dir / f"{filename}_ref",
skiprows=start_row,
max_rows=num_rows,
)
assert matrix == pytest.approx(reference_matrix, rel=1e-6, abs=1e-6)
Loading