Skip to content

Commit 9a9bc93

Browse files
committed
test: add input type tests
1 parent aa89c47 commit 9a9bc93

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ testing = [
2828
"pytest>=8.3.5",
2929
"pytest-cases>=3.9.1",
3030
"shapely>=2.0.7",
31+
"numpy>=2.2.6",
3132
]
3233
scripts = [
3334
"matplotlib>=3.7.5",

tests/polygon_cases.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"""Cases for end-to-end testing of reduce_polygon."""
22

33
import pickle
4+
from collections.abc import Sequence
5+
6+
import numpy as np
7+
from numpy.typing import NDArray
8+
from shapely import Polygon as ShapelyPolygon
9+
from shapely.coords import CoordinateSequence
410

511

612
class CaseLarge:
@@ -60,3 +66,100 @@ def case_interlocking_teeth(self) -> list[tuple[float, float]]:
6066
(1.0, 0.0),
6167
(0.0, 0.0),
6268
]
69+
70+
class CaseTypes:
71+
"""Minimal polygons of various types."""
72+
73+
def case_tuple_tuple(self) -> tuple[tuple[float, float], ...]:
74+
"""A polygon as a tuple of tuples."""
75+
return (
76+
(0.0, 0.0),
77+
(0.0, 1.0),
78+
(0.5, 0.5),
79+
(1.0, 1.0),
80+
(1.0, 0.0),
81+
(0.0, 0.0),
82+
)
83+
84+
def case_tuple_list(self) -> tuple[list[float], ...]:
85+
"""A polygon as a tuple of lists."""
86+
return (
87+
[0.0, 0.0],
88+
[0.0, 1.0],
89+
[0.5, 0.5],
90+
[1.0, 1.0],
91+
[1.0, 0.0],
92+
[0.0, 0.0],
93+
)
94+
95+
def case_list_tuple(self) -> list[tuple[float, float]]:
96+
"""A polygon as a list of tuples."""
97+
return [
98+
(0.0, 0.0),
99+
(0.0, 1.0),
100+
(0.5, 0.5),
101+
(1.0, 1.0),
102+
(1.0, 0.0),
103+
(0.0, 0.0),
104+
]
105+
106+
def case_list_list(self) -> list[list[float]]:
107+
"""A polygon as a list of lists."""
108+
return [
109+
[0.0, 0.0],
110+
[0.0, 1.0],
111+
[0.5, 0.5],
112+
[1.0, 1.0],
113+
[1.0, 0.0],
114+
[0.0, 0.0],
115+
]
116+
117+
def case_array(self) -> NDArray[np.floating]:
118+
"""A polygon as a numpy array."""
119+
return np.array(
120+
[
121+
[0.0, 0.0],
122+
[0.0, 1.0],
123+
[0.5, 0.5],
124+
[1.0, 1.0],
125+
[1.0, 0.0],
126+
[0.0, 0.0],
127+
]
128+
)
129+
130+
def case_shapely_coord_sequence(self) -> CoordinateSequence:
131+
"""A polygon as a shapely CoordinateSequence."""
132+
return ShapelyPolygon(
133+
[
134+
[0.0, 0.0],
135+
[0.0, 1.0],
136+
[0.5, 0.5],
137+
[1.0, 1.0],
138+
[1.0, 0.0],
139+
[0.0, 0.0],
140+
]
141+
).exterior.coords
142+
143+
def case_sequence(self) -> Sequence[tuple[float, float]]:
144+
"""A polygon as a custom type."""
145+
146+
class CoordSequence(Sequence):
147+
def __init__(self, coords: list[tuple[float, float]]):
148+
self.coords = coords
149+
150+
def __len__(self) -> int:
151+
return len(self.coords)
152+
153+
def __getitem__(self, index: int) -> tuple[float, float]:
154+
return self.coords[index]
155+
156+
return CoordSequence(
157+
[
158+
(0.0, 0.0),
159+
(0.0, 1.0),
160+
(0.5, 0.5),
161+
(1.0, 1.0),
162+
(1.0, 0.0),
163+
(0.0, 0.0),
164+
]
165+
)

uv.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)