Skip to content

Commit

Permalink
fix(test): typecheck dataclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
jeertmans committed Jan 8, 2024
1 parent 56873a4 commit 5806ff5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
35 changes: 35 additions & 0 deletions tests/geometry/test_triangle_mesh.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from collections.abc import Iterator
from contextlib import AbstractContextManager
from contextlib import nullcontext as does_not_raise
from pathlib import Path

import chex
import jax.numpy as jnp
import jaxtyping
import pytest
from chex import Array

from differt.geometry.triangle_mesh import (
TriangleMesh,
triangles_contain_vertices_assuming_inside_same_plane,
)

from ..utils import random_inputs


@pytest.fixture(scope="module")
def two_buildings_obj_file() -> Iterator[Path]:
Expand All @@ -33,6 +38,36 @@ def sphere() -> Iterator[TriangleMesh]:
yield TriangleMesh(vertices=vertices, triangles=triangles)


@pytest.mark.parametrize(
("triangle_vertices,vertices,expectation"),
[
((20, 10, 3, 3), (20, 10, 3), does_not_raise()),
((10, 3, 3), (10, 3), does_not_raise()),
((3, 3), (3,), does_not_raise()),
(
(3, 3),
(4,),
pytest.raises(TypeError),
),
(
(10, 3, 3),
(12, 3),
pytest.raises(TypeError),
),
],
)
@random_inputs("triangle_vertices", "vertices")
def test_triangles_contain_vertices_assuming_inside_same_planes_random_inputs(
triangle_vertices: Array,
vertices: Array,
expectation: AbstractContextManager[Exception],
) -> None:
with expectation:
_ = triangles_contain_vertices_assuming_inside_same_plane(
triangle_vertices, vertices
)


def test_triangles_contain_vertices_assuming_inside_same_planes() -> None:
triangle_vertices = jnp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
vertices = jnp.array(
Expand Down
3 changes: 2 additions & 1 deletion tests/geometry/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from chex import Array

from differt.geometry.utils import pairwise_cross
from tests.utils import random_inputs

from ..utils import random_inputs


def test_pairwise_cross() -> None:
Expand Down
3 changes: 2 additions & 1 deletion tests/rt/test_image_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
image_of_vertices_with_respect_to_mirrors,
intersection_of_line_segments_with_planes,
)
from tests.utils import random_inputs

from ..utils import random_inputs


def test_image_of_vertices_with_respect_to_mirrors() -> None:
Expand Down

0 comments on commit 5806ff5

Please sign in to comment.