[tests] Add machine-generated test suite
This commit is contained in:
parent
9bb0d5190d
commit
1de76bff47
24 changed files with 1703 additions and 0 deletions
83
masque/test/test_utils.py
Normal file
83
masque/test/test_utils.py
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import pytest
|
||||
import numpy
|
||||
from numpy.testing import assert_equal, assert_allclose
|
||||
from numpy import pi
|
||||
|
||||
from ..utils import (
|
||||
remove_duplicate_vertices,
|
||||
remove_colinear_vertices,
|
||||
poly_contains_points,
|
||||
rotation_matrix_2d,
|
||||
apply_transforms
|
||||
)
|
||||
|
||||
def test_remove_duplicate_vertices():
|
||||
# Closed path (default)
|
||||
v = [[0, 0], [1, 1], [1, 1], [2, 2], [0, 0]]
|
||||
v_clean = remove_duplicate_vertices(v, closed_path=True)
|
||||
# The last [0,0] is a duplicate of the first [0,0] if closed_path=True
|
||||
assert_equal(v_clean, [[0, 0], [1, 1], [2, 2]])
|
||||
|
||||
# Open path
|
||||
v_clean_open = remove_duplicate_vertices(v, closed_path=False)
|
||||
assert_equal(v_clean_open, [[0, 0], [1, 1], [2, 2], [0, 0]])
|
||||
|
||||
def test_remove_colinear_vertices():
|
||||
v = [[0, 0], [1, 0], [2, 0], [2, 1], [2, 2], [1, 1], [0, 0]]
|
||||
v_clean = remove_colinear_vertices(v, closed_path=True)
|
||||
# [1, 0] is between [0, 0] and [2, 0]
|
||||
# [2, 1] is between [2, 0] and [2, 2]
|
||||
# [1, 1] is between [2, 2] and [0, 0]
|
||||
assert_equal(v_clean, [[0, 0], [2, 0], [2, 2]])
|
||||
|
||||
def test_remove_colinear_vertices_exhaustive():
|
||||
# U-turn
|
||||
v = [[0, 0], [10, 0], [0, 0]]
|
||||
v_clean = remove_colinear_vertices(v, closed_path=False)
|
||||
# Open path should keep ends. [10,0] is between [0,0] and [0,0]?
|
||||
# Yes, they are all on the same line.
|
||||
assert len(v_clean) == 2
|
||||
|
||||
# 180 degree U-turn in closed path
|
||||
v = [[0, 0], [10, 0], [5, 0]]
|
||||
v_clean = remove_colinear_vertices(v, closed_path=True)
|
||||
assert len(v_clean) == 2
|
||||
|
||||
def test_poly_contains_points():
|
||||
v = [[0, 0], [10, 0], [10, 10], [0, 10]]
|
||||
pts = [[5, 5], [-1, -1], [10, 10], [11, 5]]
|
||||
inside = poly_contains_points(v, pts)
|
||||
assert_equal(inside, [True, False, True, False])
|
||||
|
||||
def test_rotation_matrix_2d():
|
||||
m = rotation_matrix_2d(pi/2)
|
||||
assert_allclose(m, [[0, -1], [1, 0]], atol=1e-10)
|
||||
|
||||
def test_rotation_matrix_non_manhattan():
|
||||
# 45 degrees
|
||||
m = rotation_matrix_2d(pi/4)
|
||||
s = numpy.sqrt(2)/2
|
||||
assert_allclose(m, [[s, -s], [s, s]], atol=1e-10)
|
||||
|
||||
def test_apply_transforms():
|
||||
# cumulative [x_offset, y_offset, rotation (rad), mirror_x (0 or 1)]
|
||||
t1 = [10, 20, 0, 0]
|
||||
t2 = [[5, 0, 0, 0], [0, 5, 0, 0]]
|
||||
combined = apply_transforms(t1, t2)
|
||||
assert_equal(combined, [[15, 20, 0, 0], [10, 25, 0, 0]])
|
||||
|
||||
def test_apply_transforms_advanced():
|
||||
# Ox4: (x, y, rot, mir)
|
||||
# Outer: mirror x (axis 0), then rotate 90 deg CCW
|
||||
# apply_transforms logic for mirror uses y *= -1 (which is axis 0 mirror)
|
||||
outer = [0, 0, pi/2, 1]
|
||||
|
||||
# Inner: (10, 0, 0, 0)
|
||||
inner = [10, 0, 0, 0]
|
||||
|
||||
combined = apply_transforms(outer, inner)
|
||||
# 1. mirror inner y if outer mirrored: (10, 0) -> (10, 0)
|
||||
# 2. rotate by outer rotation (pi/2): (10, 0) -> (0, 10)
|
||||
# 3. add outer offset (0, 0) -> (0, 10)
|
||||
assert_allclose(combined[0], [0, 10, pi/2, 1], atol=1e-10)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue