Skip to content

Commit

Permalink
tests: add test for interpolator builder
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed Jan 15, 2025
1 parent 169545b commit 3d7ac4e
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/unit/interpolator/test_interpolator_builder.py
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"

0 comments on commit 3d7ac4e

Please sign in to comment.