Skip to content

Commit

Permalink
tests: add
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Feb 20, 2024
1 parent e809368 commit 5571ed2
Show file tree
Hide file tree
Showing 5 changed files with 864 additions and 672 deletions.
69 changes: 61 additions & 8 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@

from vector import (
Abstract1DVector,
Abstract1DVectorDifferential,
Abstract2DVector,
Abstract2DVectorDifferential,
Abstract3DVector,
Abstract3DVectorDifferential,
AbstractVector,
AbstractVectorDifferential,
Cartesian1DVector,
Cartesian2DVector,
Cartesian3DVector,
CartesianDifferential1D,
CartesianDifferential2D,
CartesianDifferential3D,
CylindricalDifferential,
CylindricalVector,
IrreversibleDimensionChange,
# LnPolarVector,
# Log10PolarVector,
PolarDifferential,
PolarVector,
RadialDifferential,
RadialVector,
SphericalDifferential,
SphericalVector,
)

Expand All @@ -37,6 +46,21 @@
CylindricalVector,
]

BUILTIN_DIFFERENTIALS = [
# 1D
CartesianDifferential1D,
RadialDifferential,
# 2D
CartesianDifferential2D,
PolarDifferential,
# LnPolarDifferential,
# Log10PolarDifferential,
# 3D
CartesianDifferential3D,
SphericalDifferential,
CylindricalDifferential,
]


def context_dimension_reduction(
vector: AbstractVector, target: type[AbstractVector]
Expand Down Expand Up @@ -78,13 +102,42 @@ def test_represent_as(self, vector, target):
assert isinstance(newvec, target)


class Abstract1DVectorTest(AbstractVectorTest):
"""Test :class:`vector.Abstract1DVector`."""
class AbstractVectorDifferentialTest:
"""Test :class:`vector.AbstractVectorDifferential`."""

@pytest.fixture(scope="class")
def vector(self) -> AbstractVector: # noqa: PT004
"""Return a vector."""
raise NotImplementedError

@pytest.fixture(scope="class")
def difntl(self) -> AbstractVectorDifferential: # noqa: PT004
"""Return a vector."""
raise NotImplementedError

@pytest.mark.parametrize("target", BUILTIN_DIFFERENTIALS)
@pytest.mark.filterwarnings("ignore:Explicitly requested dtype")
def test_represent_as(self, difntl, target, vector):
"""Test :meth:`AbstractVector.represent_as`.
class Abstract2DVectorTest(AbstractVectorTest):
"""Test :class:`vector.Abstract2DVector`."""
This just tests that the machiner works.
"""
# TODO: have all the convertsions
if (
isinstance(difntl, Abstract1DVectorDifferential)
and issubclass(
target, Abstract2DVectorDifferential | Abstract3DVectorDifferential
)
) or (
isinstance(difntl, Abstract2DVectorDifferential)
and issubclass(target, Abstract3DVectorDifferential)
):
pytest.xfail("Not implemented yet")

# Perform the conversion.
# Detecting whether the conversion reduces the dimensionality.
with context_dimension_reduction(vector, target.vector_cls):
newdif = difntl.represent_as(target, vector)

class Abstract3DVectorTest(AbstractVectorTest):
"""Test :class:`vector.Abstract3DVector`."""
# Test
assert isinstance(newdif, target)
Loading

0 comments on commit 5571ed2

Please sign in to comment.