def test_bbox_set_vertices_maintain_type_float(): """ 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.float) assert issubclass(m_bb.max_vertex.dtype.type, numpy.float)
def test_bbox_set_vertices(ndim, seq_type): """ 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)
def test_bbox_set_vertices_maintain_type_mixed(): """ 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.float) # Float/Integer coordinates (3d) minv = [0, 1, 2.0] # float maxv = [1, 2, 3] # integer AxisAlignedBoundingBox._set_vertices(m_bb, minv, maxv) assert issubclass(m_bb.min_vertex.dtype.type, numpy.float) assert issubclass(m_bb.max_vertex.dtype.type, numpy.integer)