-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test for interpolator builder
- Loading branch information
1 parent
169545b
commit 3d7ac4e
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pytest | ||
import numpy as np | ||
from LoopStructural.datatypes import BoundingBox | ||
from LoopStructural.interpolators._interpolator_builder import InterpolatorBuilder | ||
from LoopStructural.interpolators import InterpolatorType | ||
|
||
|
||
@pytest.fixture | ||
def setup_builder(): | ||
bounding_box = BoundingBox(np.array([0, 0, 0]), np.array([1, 1, 1])) | ||
interpolatortype = InterpolatorType.FINITE_DIFFERENCE | ||
nelements = 1000 | ||
buffer = 0.2 | ||
builder = InterpolatorBuilder( | ||
interpolatortype=interpolatortype, | ||
bounding_box=bounding_box, | ||
nelements=nelements, | ||
buffer=buffer, | ||
) | ||
return builder | ||
|
||
|
||
def test_create_interpolator(setup_builder): | ||
builder = setup_builder | ||
builder.create_interpolator() | ||
assert builder.interpolator is not None, "Interpolator should be created" | ||
|
||
|
||
def test_set_value_constraints(setup_builder): | ||
builder = setup_builder | ||
builder.create_interpolator() | ||
value_constraints = np.array([[0.5, 0.5, 0.5, 1.0,1.]]) | ||
builder.set_value_constraints(value_constraints) | ||
assert np.array_equal( | ||
builder.interpolator.data['value'], value_constraints | ||
), "Value constraints should be set correctly" | ||
|
||
|
||
def test_set_gradient_constraints(setup_builder): | ||
builder = setup_builder | ||
builder.create_interpolator() | ||
gradient_constraints = np.array([[0.5, 0.5, 0.5, 1.0, 0.0, 0.0,1.]]) | ||
builder.set_gradient_constraints(gradient_constraints) | ||
assert np.array_equal( | ||
builder.interpolator.data['gradient'], gradient_constraints | ||
), "Gradient constraints should be set correctly" | ||
|
||
|
||
def test_set_normal_constraints(setup_builder): | ||
builder = setup_builder | ||
builder.create_interpolator() | ||
normal_constraints = np.array([[0.5, 0.5, 0.5, 1.0, 0.0, 0.0,1.]]) | ||
builder.set_normal_constraints(normal_constraints) | ||
assert np.array_equal( | ||
builder.interpolator.data['normal'], normal_constraints | ||
), "Normal constraints should be set correctly" | ||
|
||
|
||
def test_setup_interpolator(setup_builder): | ||
builder = setup_builder | ||
builder.create_interpolator() | ||
value_constraints = np.array([[0.5, 0.5, 0.5, 1.0,1.]]) | ||
interpolator = builder.set_value_constraints(value_constraints).setup_interpolator() | ||
assert interpolator is not None, "Interpolator should be set up" | ||
assert np.array_equal( | ||
interpolator.data['value'], value_constraints | ||
), "Value constraints should be set correctly after setup" | ||
|
||
|
||
def test_evaluate_scalar_value(setup_builder): | ||
builder = setup_builder | ||
builder.create_interpolator() | ||
value_constraints = np.array([[0.5, 0.5, 0.5, 1.0]]) | ||
interpolator = builder.set_value_constraints(value_constraints).setup_interpolator() | ||
locations = np.array([[0.5, 0.5, 0.5]]) | ||
values = interpolator.evaluate_value(locations) | ||
assert values is not None, "Evaluation should return values" | ||
assert values.shape == (1,), "Evaluation should return correct shape" |