Skip to content

Commit

Permalink
finalize the tests for the new Python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed Apr 16, 2024
1 parent 3bb7843 commit 27f83ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/polyhedralGravityPython/PolyhedralGravityPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "polyhedralGravity/model/GravityModelData.h"
#include "polyhedralGravity/model/GravityModel.h"
#include "polyhedralGravity/model/GravityEvaluable.h"
#include "polyhedralGravity/input/TetgenAdapter.h"


namespace py = pybind11;
Expand Down
27 changes: 19 additions & 8 deletions test/python/test_polyhedral_gravity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Tuple, List, Union
import polyhedral_gravity
from polyhedral_gravity import Polyhedron, GravityEvaluable, evaluate, PolyhedronIntegrity, NormalOrientation
import numpy as np
import pickle
import pytest
Expand Down Expand Up @@ -59,11 +59,16 @@ def test_polyhedral_gravity(
is callable with file/ array inputs.
"""
points, expected_potential, expected_acceleration = reference_solution
sol = polyhedral_gravity.evaluate(
polyhedron = Polyhedron(
polyhedral_source=polyhedral_source,
density=DENSITY,
normal_orientation=NormalOrientation.OUTWARDS,
integrity_check=PolyhedronIntegrity.VERIFY,
)
sol = evaluate(
polyhedron=polyhedron,
computation_points=points,
parallel=True
parallel=True,
)
potential = np.array([result[0] for result in sol])
acceleration = np.array([result[1] for result in sol])
Expand All @@ -82,13 +87,16 @@ def test_polyhedral_gravity_evaluable(
is instantiable with file/ array inputs.
"""
points, expected_potential, expected_acceleration = reference_solution
evaluable = polyhedral_gravity.GravityEvaluable(
polyhedron = Polyhedron(
polyhedral_source=polyhedral_source,
density=DENSITY,
normal_orientation=NormalOrientation.OUTWARDS,
integrity_check=PolyhedronIntegrity.VERIFY,
)
evaluable = GravityEvaluable(polyhedron=polyhedron)
sol = evaluable(
computation_points=points,
parallel=True
parallel=True,
)
potential = np.array([result[0] for result in sol])
acceleration = np.array([result[1] for result in sol])
Expand All @@ -109,10 +117,13 @@ def test_polyhedral_evaluable_pickle(
pickled and unpicked as well).
"""
points, expected_potential, expected_acceleration = reference_solution
initial_evaluable = polyhedral_gravity.GravityEvaluable(
polyhedron = Polyhedron(
polyhedral_source=polyhedral_source,
density=DENSITY
density=DENSITY,
normal_orientation=NormalOrientation.OUTWARDS,
integrity_check=PolyhedronIntegrity.DISABLE,
)
initial_evaluable = GravityEvaluable(polyhedron=polyhedron)
pickle_output = tmp_path.joinpath("evaluable.pk")
with open(pickle_output, "wb") as f:
pickle.dump(initial_evaluable, f, pickle.HIGHEST_PROTOCOL)
Expand All @@ -122,7 +133,7 @@ def test_polyhedral_evaluable_pickle(

sol = read_evaluable(
computation_points=points,
parallel=True
parallel=True,
)
potential = np.array([result[0] for result in sol])
acceleration = np.array([result[1] for result in sol])
Expand Down

0 comments on commit 27f83ed

Please sign in to comment.