adze/adze/test/test_edge_cases.py

122 lines
3.2 KiB
Python

import numpy
import pytest
from numpy.testing import assert_allclose
import adze
import adze.util
from adze.boundary import planes_from_boundary
def test_boundary_from_empty_poly() -> None:
assert adze.boundary_from_poly(adze.util.build_empty()) == []
@pytest.mark.parametrize('order', [0, 1, 2, 3])
def test_empty_poly_moments_shape(order: int) -> None:
moments = adze.get_moments(adze.util.build_empty(), order)
assert moments.shape == (adze.number_of_moments(order),)
assert_allclose(moments, numpy.zeros_like(moments))
def test_planes_from_boundary_rejects_zero_area_face() -> None:
vertices = numpy.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[2.0, 0.0, 0.0],
])
with pytest.raises(adze.AdzeError, match='non-zero area'):
planes_from_boundary(vertices, [[0, 1, 2]])
def test_build_polyhedron_rejects_unused_vertices() -> None:
vertices = numpy.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
[9.0, 9.0, 9.0],
])
faces = [
[0, 1, 2],
[0, 3, 1],
[0, 2, 3],
[1, 3, 2],
]
with pytest.raises(adze.AdzeError, match='unused by any face'):
adze.build_polyhedron(vertices, faces)
def test_build_polyhedron_rejects_invalid_face_index() -> None:
vertices = numpy.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
])
faces = [
[0, 1, 2],
[0, 3, 1],
[0, 2, 3],
[1, 3, 5],
]
with pytest.raises(adze.AdzeError, match='outside the provided vertex list'):
adze.build_polyhedron(vertices, faces)
def test_build_polyhedron_rejects_inconsistent_face_winding() -> None:
vertices = numpy.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
])
faces = [
[0, 1, 2],
[0, 1, 3],
[0, 3, 2],
[1, 2, 3],
]
with pytest.raises(adze.AdzeError, match='duplicate neighbors'):
adze.build_polyhedron(vertices, faces)
def test_check_poly_rejects_row_count_mismatch() -> None:
poly = {
'vertices': numpy.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[9.0, 9.0, 9.0],
]),
'neighbors': numpy.array([
[1, 2, 0],
[2, 0, 1],
[0, 1, 2],
], dtype=int),
}
with pytest.raises(adze.AdzeError, match='Neighbors must have shape'):
adze.util.check_poly(poly, check_connectivity=False)
def test_voxelize_requires_three_axes() -> None:
poly = adze.build_box([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
with pytest.raises(adze.AdzeError, match='exactly three plane axes'):
adze.voxelize(poly, [numpy.array([0.0, 1.0]), numpy.array([0.0, 1.0])], order=0)
def test_voxelize_requires_strictly_increasing_axes() -> None:
poly = adze.build_box([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
with pytest.raises(adze.AdzeError, match='strictly increasing'):
adze.voxelize(
poly,
[numpy.array([1.0, 0.0]), numpy.array([0.0, 1.0]), numpy.array([0.0, 1.0])],
order=0,
)