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

Check geometry list input lengths #80

Merged
merged 6 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions meshkernel/py_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from numpy import ndarray

from meshkernel.errors import InputError
from meshkernel.utils import plot_edges


Expand Down Expand Up @@ -178,6 +179,21 @@ def __init__(
self.geometry_separator: float = geometry_separator
self.inner_outer_separator: float = inner_outer_separator

if len(self.x_coordinates) != len(self.y_coordinates):
raise InputError(
"The length of x_coordinates is not equal to the length of y_coordinates"
)

if len(self.values) > 0 and len(self.values) != len(self.x_coordinates):
raise InputError(
"The length of values is not equal to the length of x_coordinates"
)

if len(self.values) > 0 and len(self.values) != len(self.y_coordinates):
raise InputError(
"The length of values is not equal to the length of y_coordinates"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is necessary.
line 182 checks that x_coords and y_coords are the same length, then
line 187 check values is same as x_coords (if length of values is > 0)
at this point it must be that x_coords and y_coords are the same size.


class OrthogonalizationParameters:
"""A class holding the parameters for orthogonalization.
Expand Down
15 changes: 15 additions & 0 deletions tests/test_py_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
(DeleteMeshOption.ALL_COMPLETE_FACES, 2),
]

from meshkernel.errors import InputError


@pytest.mark.parametrize("enum_val, exp_int", cases_deletemeshoption_values)
def test_deletemeshoption_values(enum_val: DeleteMeshOption, exp_int: int):
Expand Down Expand Up @@ -123,6 +125,19 @@ def test_geometrylist_constructor():
assert geometry_list.inner_outer_separator == -998.0


def test_geometrylist_constructor_raises_exception():
"""Tests `GeometryList` constructor raises an exception when coordinates and values have different lengths."""

x_coordinates = np.array([0.0, 2.0], dtype=np.double)
y_coordinates = np.array([1.0, 2.0], dtype=np.double)
values = np.array([1.0], dtype=np.double)

with pytest.raises(InputError):
GeometryList(
x_coordinates=x_coordinates, y_coordinates=y_coordinates, values=values
)


def test_orthogonalizationparameters_constructor():
"""Tests the default values after constructing a `OrthogonalizationParameters`."""

Expand Down