Skip to content

Commit

Permalink
MNT: solve minor test placement issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmbressan committed Dec 19, 2023
1 parent 8fdfa55 commit 34ed384
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
50 changes: 50 additions & 0 deletions tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,56 @@ def test_multivariable_dataset(a, b):
assert np.isclose(func(a, b), a + b, atol=1e-6)


@pytest.mark.parametrize(
"x,y,z_expected",
[
(0, 0, 1),
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(0.5, 0.5, 1 / 3),
(0.25, 0.25, 25 / (25 + 2 * 5**0.5)),
([0, 0.5], [0, 0.5], [1, 1 / 3]),
],
)
def test_2d_shepard_interpolation(x, y, z_expected):
"""Test the shepard interpolation method of the Function class."""
# Test plane x + y + z = 1
source = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
func = Function(
source=source, inputs=["x", "y"], outputs=["z"], interpolation="shepard"
)
z = func(x, y)
z_opt = func.get_value_opt(x, y)
assert np.isclose(z, z_opt, atol=1e-8).all()
assert np.isclose(z_expected, z, atol=1e-8).all()


@pytest.mark.parametrize(
"x,y,z,w_expected",
[
(0, 0, 0, 1),
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(0.5, 0.5, 0.5, 1 / 4),
(0.25, 0.25, 0.25, 0.700632626832),
([0, 0.5], [0, 0.5], [0, 0.5], [1, 1 / 4]),
],
)
def test_3d_shepard_interpolation(x, y, z, w_expected):
"""Test the shepard interpolation method of the Function class."""
# Test plane x + y + z + w = 1
source = [(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)]
func = Function(
source=source, inputs=["x", "y", "z"], outputs=["w"], interpolation="shepard"
)
w = func(x, y, z)
w_opt = func.get_value_opt(x, y, z)
assert np.isclose(w, w_opt, atol=1e-8).all()
assert np.isclose(w_expected, w, atol=1e-8).all()


@pytest.mark.parametrize("a", [-1, -0.5, 0, 0.5, 1])
@pytest.mark.parametrize("b", [-1, -0.5, 0, 0.5, 1])
def test_multivariable_function(a, b):
Expand Down
46 changes: 0 additions & 46 deletions tests/unit/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,6 @@ def test_integral_spline_interpolation(request, func, a, b):
)


@pytest.mark.parametrize(
"x,y,z_expected",
[
(0, 0, 1),
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(0.5, 0.5, 1 / 3),
(0.25, 0.25, 25 / (25 + 2 * 5**0.5)),
([0, 0.5], [0, 0.5], [1, 1 / 3]),
],
)
def test_2d_shepard_interpolation(x, y, z_expected):
"""Test the shepard interpolation method of the Function class."""
# Test plane x + y + z = 1
source = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
func = Function(source=source, inputs=["x", "y"], outputs=["z"])
z = func(x, y)
z_opt = func.get_value_opt(x, y)
assert np.isclose(z, z_opt, atol=1e-8).all()
assert np.isclose(z, z_expected, atol=1e-8).all()


@pytest.mark.parametrize(
"x,y,z,w_expected",
[
(0, 0, 0, 1),
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(0.5, 0.5, 0.5, 1 / 4),
(0.25, 0.25, 0.25, 0.700632626832),
([0, 0.5], [0, 0.5], [0, 0.5], [1, 1 / 4]),
],
)
def test_3d_shepard_interpolation(x, y, z, w_expected):
"""Test the shepard interpolation method of the Function class."""
# Test plane x + y + z + w = 1
source = [(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)]
func = Function(source=source, inputs=["x", "y", "z"], outputs=["w"])
w = func(x, y, z)
w_opt = func.get_value_opt(x, y, z)
assert np.isclose(w, w_opt, atol=1e-8).all()
assert np.isclose(w_expected, w, atol=1e-8).all()


@pytest.mark.parametrize(
"func_input, derivative_input, expected_derivative",
[
Expand Down

0 comments on commit 34ed384

Please sign in to comment.