Commit 3c0ecff7 authored by dboe's avatar dboe
Browse files

test_templating added

parent 52acd28b
import unittest
import tfields
class Base_Check(object):
def test_merging(self):
merged_without_templates = self._instances[0].\
__class__.merged(*self._instances)
merged, templates = self._instances[0].\
__class__.merged(*self._instances, return_templates=True)
self.assertTrue(merged_without_templates.equal(merged))
self.assertTrue(len(templates), len(self._instances))
for template, inst in zip(templates, self._instances):
merged_cut = merged.cut(template)
self.assertEqual(len(inst.maps), len(merged_cut.maps))
self.assertEqual(len(merged_cut.maps), len(template.maps))
for i, mp in enumerate(inst.maps):
self.assertEqual(len(mp),
len(merged_cut.maps[i]))
self.assertEqual(tfields.core.dim(mp),
tfields.core.dim(merged_cut.maps[i]))
self.assertEqual(tfields.core.dim(template.maps[i]),
tfields.core.dim(merged_cut.maps[i]))
self.assertTrue(tfields.TensorFields(inst).equal(
tfields.TensorFields(merged_cut)))
self.assertTrue(inst.equal(merged_cut))
# class Tensors_Empty_Test(Base_Check, unittest.TestCase):
# def setUp(self):
# self._instances = [tfields.Tensors([], dim=3) for i in range(3)]
#
#
# class TensorFields_Empty_Test(Base_Check, unittest.TestCase):
# def setUp(self):
# self._fields = []
# self._instances = [tfields.TensorFields([], dim=3) for i in range(3)]
# class TensorMaps_Empty_Test(Base_Check, unittest.TestCase):
# def setUp(self):
# self._instances = [tfields.TensorMaps([], dim=3) for i in range(3)]
#class TensorFields_Test(TensorFields_Empty_Test):
# def setUp(self):
# base = [(-5, 5, 7)] * 3
# self._fields = [tfields.Tensors.grid(*base, coord_sys='cylinder'),
# tfields.Tensors(range(7**3))]
# tensors = tfields.Tensors.grid(*base)
# self._instances = [tfields.TensorFields(tensors, *self._fields)
# for i in range(3)]
# class TensorMaps_Test(TensorMaps_Empty_Test):
class TensorMaps_Empty_Test(Base_Check, unittest.TestCase):
def setUp(self):
base = [(-1, 1, 3)] * 3
tensors = tfields.Tensors.grid(*base)
self._fields = [tfields.Tensors.grid(*base, coord_sys='cylinder'),
tfields.Tensors(range(len(tensors)))]
self._maps_tensors = [
[[0, 4],
[1, 3]],
[[42]],
[[0, 0, 0],
[1, 2, 3],
[1, 5, 9]],
]
self._maps_fields = [
[[3, 25]],
[[111]],
[[42., 21., 11]],
]
self._maps = [tfields.TensorFields(map_tensors,
*map_fields) for map_tensors,
map_fields in zip(self._maps_tensors, self._maps_fields)]
self._instances = [tfields.TensorMaps(tensors, *self._fields,
maps=self._maps)
for i in range(3)]
if __name__ == '__main__':
a = TensorMaps_Empty_Test()
a.setUp()
print("DONE SETUPT")
a.test_merging()
# 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