Пример #1
0
def test_bbox_set_vertices_maintain_type_float() -> None:
    """
    Test that ndarray dtypes inherit from input float values explicitly.
    """
    # Float input coordinates (1d)
    minv = [0.]
    maxv = [1.]

    # Mock instance so as to not actually hit __init__ method.
    m_bb = mock.MagicMock(spec_set=AxisAlignedBoundingBox)
    # Invoke private method, which should set attributes onto `m_bb`.
    AxisAlignedBoundingBox._set_vertices(m_bb, minv, maxv)

    # BOTH vertices should be integer since input coordinates are integers.
    assert issubclass(m_bb.min_vertex.dtype.type, numpy.float64)
    assert issubclass(m_bb.max_vertex.dtype.type, numpy.float64)
Пример #2
0
def test_bbox_set_vertices(ndim: int, seq_type: Any) -> None:
    """
    Test constructing an AxisAlignedBoundingBox with ``ndim`` coordinates.
    """
    minv = [random.randint(0, 9) for _ in range(ndim)]
    maxv = [random.randint(10, 19) for _ in range(ndim)]
    minv_s = seq_type(minv)
    maxv_s = seq_type(maxv)

    # Mock instance so as to not actually hit __init__ method.
    m_bb = mock.MagicMock(spec_set=AxisAlignedBoundingBox)
    # Invoke private method, which should set attributes onto `m_bb`.
    AxisAlignedBoundingBox._set_vertices(m_bb, minv_s, maxv_s)

    assert isinstance(m_bb.min_vertex, numpy.ndarray)
    assert isinstance(m_bb.max_vertex, numpy.ndarray)
    numpy.testing.assert_allclose(m_bb.min_vertex, minv)
    numpy.testing.assert_allclose(m_bb.max_vertex, maxv)
Пример #3
0
def test_bbox_set_vertices_maintain_type_mixed() -> None:
    """
    Test that ndarray dtypes inherit from mixed float and integer values
    explicitly.
    """
    # Mock instance so as to not actually hit __init__ method.
    m_bb = mock.MagicMock(spec_set=AxisAlignedBoundingBox)

    # Integer/Float coordinates (3d)
    minv = [0, 1, 2]  # integer
    maxv = [1, 2.0, 3]  # float
    AxisAlignedBoundingBox._set_vertices(m_bb, minv, maxv)
    assert issubclass(m_bb.min_vertex.dtype.type, numpy.integer)
    assert issubclass(m_bb.max_vertex.dtype.type, numpy.float64)

    # Float/Integer coordinates (3d)
    minv = [0, 1, 2.0]  # type: ignore  # float
    maxv = [1, 2, 3]  # type: ignore  # integer
    AxisAlignedBoundingBox._set_vertices(m_bb, minv, maxv)
    assert issubclass(m_bb.min_vertex.dtype.type, numpy.float64)
    assert issubclass(m_bb.max_vertex.dtype.type, numpy.integer)