Commit e528b531 authored by dboe's avatar dboe
Browse files

Merge branch 'no_lists' of https://gitlab.mpcdf.mpg.de/dboe/tfields into no_lists

parents 2b3cc377 c31de806
......@@ -396,5 +396,116 @@ class Container_Test(Container_Check, unittest.TestCase):
self._inst = tfields.Container([sphere, sphere2], labels=['test'])
class TensorMaps_Indexing_Test(unittest.TestCase):
def setUp(self):
tensors = np.arange(10).reshape((-1, 1))
self._maps_tensors = [[[0, 0, 0],
[1, 2, 3],
[3, 5, 9]],
[[6, 4],
[7, 8]],
[[7]]]
self._inst = tfields.TensorMaps(tensors,
maps=self._maps_tensors)
def test_pick_indexing(self):
pick = self._inst[7]
self.assertTrue(pick.equal([7]))
self.assertTrue(np.array_equal(pick.maps[1], [[0]]))
self.assertTrue(len(pick.maps), 1)
pick = self._inst[0]
self.assertTrue(pick.equal([[0]]))
self.assertTrue(np.array_equal(pick.maps[3], [[0, 0, 0]]))
self.assertTrue(len(pick.maps), 1)
def test_slice_indexing(self):
slce = self._inst[1:7]
self.assertTrue(slce.equal([[1], [2], [3], [4], [5], [6]]))
self.assertTrue(np.array_equal(slce.maps[3], [[0, 1, 2]]))
self.assertTrue(np.array_equal(slce.maps[2], [[5, 3]]))
self.assertTrue(len(slce.maps), 2)
def test_mask_indexing(self):
mask = self._inst[np.array([False, True, True, True, True,
True, True, False, False, False])]
self.assertTrue(mask.equal([[1], [2], [3], [4], [5], [6]]))
self.assertTrue(np.array_equal(mask.maps[3], [[0, 1, 2]]))
self.assertTrue(np.array_equal(mask.maps[2], [[5, 3]]))
self.assertTrue(len(mask.maps), 2)
class TensorMaps_NoFields_Test(TensorMaps_Test):
def setUp(self):
self._inst = tfields.TensorMaps(
[[1, 2, 3], [3, 3, 3], [0, 0, 0], [5, 6, 7]],
maps=[[[0, 1, 2], [1, 2, 3]], [[1]], [[0, 1, 2, 3]]]
)
class Maps_Test(Base_Check, unittest.TestCase):
def demand_equal(self, other):
super().demand_equal(other)
self._inst.equal(other)
def setUp(self):
self._inst = tfields.Maps(
[[[0, 0, 0],
[1, 2, 3],
[1, 5, 9]],
[[0, 4],
[1, 3]],
[[42]]])
class Maps_Init_Test(Maps_Test):
def setUp(self):
self._inst = tfields.Maps({3: [[0, 1, 2]], 0: [[]]})
class Maps_Rigid_Test(Maps_Test):
def setUp(self):
rig = tfields.Maps({0: [[1, 2, 42]], 3: [1]})
self.assertIsInstance(rig[0], tfields.TensorFields)
self.assertIsInstance(rig[3], tfields.TensorFields)
self.assertEqual(tfields.dim(rig[0]), 3)
self.assertEqual(tfields.dim(rig[3]), 1)
self.assertEqual(tfields.rank(rig[0]), 1)
self.assertEqual(tfields.rank(rig[3]), 0)
self._inst = rig
class Container_Check(AbstractNdarray_Check):
def demand_equal(self, other):
super().demand_equal(other)
for i, item in enumerate(self._inst.items):
if issubclass(type(item), tfields.core.AbstractNdarray):
self.assertTrue(other.items[i].equal(item))
else:
self.assertEqual(other.items[i], item)
try:
self._inst.labels[i]
except (IndexError, TypeError):
pass
else:
self.assertEqual(other.labels[i], self._inst.labels[i])
def test_item(self):
if len(self._inst.items) > 0:
self.assertEqual(len(self._inst), len(self._inst))
self.assertEqual(type(self._inst), type(self._inst))
class Container_Test(Container_Check, unittest.TestCase):
def setUp(self):
sphere = tfields.Mesh3D.grid(
(1, 1, 1),
(-np.pi, np.pi, 3),
(-np.pi / 2, np.pi / 2, 3),
coord_sys='spherical')
sphere2 = sphere.copy() * 3
self._inst = tfields.Container([sphere, sphere2], labels=['test'])
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment