[test] refactor tests
This commit is contained in:
parent
51c7fa9add
commit
4d57936da8
31 changed files with 1735 additions and 2032 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from numpy.testing import assert_equal, assert_allclose
|
||||
|
||||
from ..shapes import Path
|
||||
from ..shapes import Path, Path as MPath
|
||||
|
||||
|
||||
def test_path_init() -> None:
|
||||
|
|
@ -14,7 +14,6 @@ def test_path_to_polygons_flush() -> None:
|
|||
p = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.Flush)
|
||||
polys = p.to_polygons()
|
||||
assert len(polys) == 1
|
||||
# Rectangle from (0, -1) to (10, 1)
|
||||
bounds = polys[0].get_bounds_single()
|
||||
assert_equal(bounds, [[0, -1], [10, 1]])
|
||||
|
||||
|
|
@ -23,8 +22,6 @@ def test_path_to_polygons_square() -> None:
|
|||
p = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.Square)
|
||||
polys = p.to_polygons()
|
||||
assert len(polys) == 1
|
||||
# Square cap adds width/2 = 1 to each end
|
||||
# Rectangle from (-1, -1) to (11, 1)
|
||||
bounds = polys[0].get_bounds_single()
|
||||
assert_equal(bounds, [[-1, -1], [11, 1]])
|
||||
|
||||
|
|
@ -32,11 +29,8 @@ def test_path_to_polygons_square() -> None:
|
|||
def test_path_to_polygons_circle() -> None:
|
||||
p = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.Circle)
|
||||
polys = p.to_polygons(num_vertices=32)
|
||||
# Path.to_polygons for Circle cap returns 1 polygon for the path + polygons for the caps
|
||||
assert len(polys) >= 3
|
||||
|
||||
# Combined bounds should be from (-1, -1) to (11, 1)
|
||||
# But wait, Path.get_bounds_single() handles this more directly
|
||||
bounds = p.get_bounds_single()
|
||||
assert_equal(bounds, [[-1, -1], [11, 1]])
|
||||
|
||||
|
|
@ -45,32 +39,21 @@ def test_path_custom_cap() -> None:
|
|||
p = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.SquareCustom, cap_extensions=(5, 10))
|
||||
polys = p.to_polygons()
|
||||
assert len(polys) == 1
|
||||
# Extends 5 units at start, 10 at end
|
||||
# Starts at -5, ends at 20
|
||||
bounds = polys[0].get_bounds_single()
|
||||
assert_equal(bounds, [[-5, -1], [20, 1]])
|
||||
|
||||
|
||||
def test_path_bend() -> None:
|
||||
# L-shaped path
|
||||
p = Path(vertices=[[0, 0], [10, 0], [10, 10]], width=2)
|
||||
polys = p.to_polygons()
|
||||
assert len(polys) == 1
|
||||
bounds = polys[0].get_bounds_single()
|
||||
# Outer corner at (11, -1) is not right.
|
||||
# Segments: (0,0)-(10,0) and (10,0)-(10,10)
|
||||
# Corners of segment 1: (0,1), (10,1), (10,-1), (0,-1)
|
||||
# Corners of segment 2: (9,0), (9,10), (11,10), (11,0)
|
||||
# Bounds should be [[-1 (if start is square), -1], [11, 11]]?
|
||||
# Flush cap start at (0,0) with width 2 means y from -1 to 1.
|
||||
# Vertical segment end at (10,10) with width 2 means x from 9 to 11.
|
||||
# So bounds should be x: [0, 11], y: [-1, 10]
|
||||
assert_equal(bounds, [[0, -1], [11, 10]])
|
||||
|
||||
|
||||
def test_path_mirror() -> None:
|
||||
p = Path(vertices=[[10, 5], [20, 10]], width=2)
|
||||
p.mirror(0) # Mirror across x axis (y -> -y)
|
||||
p.mirror(0)
|
||||
assert_equal(p.vertices, [[10, -5], [20, -10]])
|
||||
|
||||
|
||||
|
|
@ -109,3 +92,10 @@ def test_path_normalized_form_distinguishes_custom_caps() -> None:
|
|||
p2 = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.SquareCustom, cap_extensions=(3, 4))
|
||||
|
||||
assert p1.normalized_form(1)[0] != p2.normalized_form(1)[0]
|
||||
|
||||
|
||||
def test_path_edge_cases() -> None:
|
||||
p = MPath(vertices=[[0, 0], [0, 0], [10, 0]], width=2)
|
||||
polys = p.to_polygons()
|
||||
assert len(polys) == 1
|
||||
assert_equal(polys[0].get_bounds_single(), [[0, -1], [10, 1]])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue