Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
309bb161
Commit
309bb161
authored
May 13, 2020
by
dboe
Browse files
doctest maps except paths
parent
ab1b51d9
Changes
3
Show whitespace changes
Inline
Side-by-side
test/test_core.py
View file @
309bb161
...
@@ -126,6 +126,7 @@ class Tensors_Check(AbstractNdarray_Check):
...
@@ -126,6 +126,7 @@ class Tensors_Check(AbstractNdarray_Check):
class
TensorFields_Check
(
Tensors_Check
):
class
TensorFields_Check
(
Tensors_Check
):
def
test_fields
(
self
):
def
test_fields
(
self
):
if
self
.
_inst
.
fields
:
# field is of type list
# field is of type list
self
.
assertTrue
(
isinstance
(
self
.
_inst
.
fields
,
list
))
self
.
assertTrue
(
isinstance
(
self
.
_inst
.
fields
,
list
))
self
.
assertTrue
(
len
(
self
.
_inst
.
fields
)
==
len
(
self
.
_fields
))
self
.
assertTrue
(
len
(
self
.
_inst
.
fields
)
==
len
(
self
.
_fields
))
...
...
test/test_mesh3D.py
View file @
309bb161
...
@@ -10,7 +10,7 @@ THIS_DIR = os.path.dirname(
...
@@ -10,7 +10,7 @@ THIS_DIR = os.path.dirname(
sys
.
path
.
append
(
os
.
path
.
normpath
(
os
.
path
.
join
(
THIS_DIR
)))
sys
.
path
.
append
(
os
.
path
.
normpath
(
os
.
path
.
join
(
THIS_DIR
)))
class
Mesh3D_Check
(
TensorFields_Check
,
unittest
.
TestCase
):
class
Mesh3D_Check
(
TensorFields_Check
):
def
test_cut_split
(
self
):
def
test_cut_split
(
self
):
x
,
y
,
z
=
sympy
.
symbols
(
'x y z'
)
x
,
y
,
z
=
sympy
.
symbols
(
'x y z'
)
self
.
_inst
.
cut
(
x
+
1.
/
100
*
y
>
0
,
at_intersection
=
'split'
)
self
.
_inst
.
cut
(
x
+
1.
/
100
*
y
>
0
,
at_intersection
=
'split'
)
...
@@ -25,7 +25,12 @@ class Mesh3D_Check(TensorFields_Check, unittest.TestCase):
...
@@ -25,7 +25,12 @@ class Mesh3D_Check(TensorFields_Check, unittest.TestCase):
self
.
assertTrue
(
self
.
_inst
.
equal
(
mesh
))
self
.
assertTrue
(
self
.
_inst
.
equal
(
mesh
))
class
Sphere_Test
(
Mesh3D_Check
):
class
Square_Test
(
Mesh3D_Check
,
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
_inst
=
tfields
.
Mesh3D
.
plane
((
0
,
1
,
2j
),
(
0
,
1
,
2j
),
(
0
,
0
,
1j
))
class
Sphere_Test
(
Mesh3D_Check
,
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_inst
=
tfields
.
Mesh3D
.
grid
(
self
.
_inst
=
tfields
.
Mesh3D
.
grid
(
(
1
,
1
,
1
),
(
1
,
1
,
1
),
...
@@ -36,12 +41,7 @@ class Sphere_Test(Mesh3D_Check):
...
@@ -36,12 +41,7 @@ class Sphere_Test(Mesh3D_Check):
self
.
_inst
[:,
1
]
+=
2
self
.
_inst
[:,
1
]
+=
2
class
Square_Test
(
Mesh3D_Check
):
class
IO_Stl_test
(
unittest
.
TestCase
):
# no Mesh3D_Check for speed
def
setUp
(
self
):
self
.
_inst
=
tfields
.
Mesh3D
.
plane
((
0
,
1
,
2j
),
(
0
,
1
,
2j
),
(
0
,
0
,
1j
))
class
IO_Stl_test
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_inst
=
tfields
.
Mesh3D
.
load
(
os
.
path
.
join
(
THIS_DIR
,
self
.
_inst
=
tfields
.
Mesh3D
.
load
(
os
.
path
.
join
(
THIS_DIR
,
'../data/baffle.stl'
))
'../data/baffle.stl'
))
...
...
tfields/core.py
View file @
309bb161
...
@@ -143,7 +143,7 @@ class AbstractObject(object):
...
@@ -143,7 +143,7 @@ class AbstractObject(object):
>>> m1 = tfields.TensorMaps.load(out_file_maps.name,
>>> m1 = tfields.TensorMaps.load(out_file_maps.name,
... allow_pickle=True)
... allow_pickle=True)
>>> assert m.equal(m1)
>>> assert m.equal(m1)
>>> assert m.maps[
0
].dtype == m1.maps[
0
].dtype
>>> assert m.maps[
3
].dtype == m1.maps[
3
].dtype
Names are preserved
Names are preserved
>>> assert p.name == 'my_points'
>>> assert p.name == 'my_points'
...
@@ -561,7 +561,7 @@ class AbstractNdarray(np.ndarray, AbstractObject):
...
@@ -561,7 +561,7 @@ class AbstractNdarray(np.ndarray, AbstractObject):
>>> mc = m.copy()
>>> mc = m.copy()
>>> mc is m
>>> mc is m
False
False
>>> mc.maps[
0
].fields[0] is m.maps[
0
].fields[0]
>>> mc.maps[
3
].fields[0] is m.maps[
3
].fields[0]
False
False
TODO:
TODO:
...
@@ -807,7 +807,7 @@ class Tensors(AbstractNdarray):
...
@@ -807,7 +807,7 @@ class Tensors(AbstractNdarray):
>>> assert tm_a.coord_sys == 'cylinder'
>>> assert tm_a.coord_sys == 'cylinder'
>>> tm_merge = tfields.TensorMaps.merged(tm_a, tm_b)
>>> tm_merge = tfields.TensorMaps.merged(tm_a, tm_b)
>>> assert tm_merge.coord_sys == 'cylinder'
>>> assert tm_merge.coord_sys == 'cylinder'
>>> assert tm_merge.maps[
0
].equal([[0, 1, 2],
>>> assert tm_merge.maps[
3
].equal([[0, 1, 2],
... list(range(len(merge),
... list(range(len(merge),
... len(merge) + 3,
... len(merge) + 3,
... 1))])
... 1))])
...
@@ -1684,9 +1684,9 @@ def as_tensors_list(tensors_list):
...
@@ -1684,9 +1684,9 @@ def as_tensors_list(tensors_list):
... tfields.TensorFields([[1], [2]], [-42, -21])]
... tfields.TensorFields([[1], [2]], [-42, -21])]
>>> mesh = tfields.TensorMaps(vectors, scalars,
>>> mesh = tfields.TensorMaps(vectors, scalars,
... maps=maps)
... maps=maps)
>>> mesh.maps[
0
].fields = [[42, 21]]
>>> mesh.maps[
3
].fields = [[42, 21]]
>>> assert len(mesh.maps[
0
].fields) == 1
>>> assert len(mesh.maps[
3
].fields) == 1
>>> assert mesh.maps[
0
].fields[0].equal([42, 21])
>>> assert mesh.maps[
3
].fields[0].equal([42, 21])
"""
"""
if
tensors_list
is
not
None
:
if
tensors_list
is
not
None
:
...
@@ -2224,7 +2224,7 @@ class TensorMaps(TensorFields):
...
@@ -2224,7 +2224,7 @@ class TensorMaps(TensorFields):
>>> assert len(mesh.maps) == 2
>>> assert len(mesh.maps) == 2
>>> assert mesh.equal(tfields.TensorFields(vectors, scalars))
>>> assert mesh.equal(tfields.TensorFields(vectors, scalars))
>>> assert mesh.maps[
0
].fields[0].equal(maps[
0
].fields[0])
>>> assert mesh.maps[
3
].fields[0].equal(maps[
3
].fields[0])
Copy constructor
Copy constructor
...
@@ -2309,7 +2309,7 @@ class TensorMaps(TensorFields):
...
@@ -2309,7 +2309,7 @@ class TensorMaps(TensorFields):
if
issubclass
(
type
(
item
),
TensorMaps
):
if
issubclass
(
type
(
item
),
TensorMaps
):
if
isinstance
(
index
,
tuple
):
if
isinstance
(
index
,
tuple
):
index
=
index
[
0
]
index
=
index
[
0
]
if
len
(
item
.
maps
)
==
0
:
if
item
.
maps
:
item
.
maps
=
Maps
(
item
.
maps
)
item
.
maps
=
Maps
(
item
.
maps
)
indices
=
np
.
array
(
range
(
len
(
self
)))
indices
=
np
.
array
(
range
(
len
(
self
)))
keep_indices
=
indices
[
index
]
keep_indices
=
indices
[
index
]
...
@@ -2486,7 +2486,7 @@ class TensorMaps(TensorFields):
...
@@ -2486,7 +2486,7 @@ class TensorMaps(TensorFields):
Examples:
Examples:
>>> import tfields
>>> import tfields
>>> maps = [tfields.TensorFields([[1]], [42])]
>>> maps = [tfields.TensorFields([[1]], [42])]
>>> tm = tfields.TensorMaps(maps[
0
], maps=maps)
>>> tm = tfields.TensorMaps(maps[
3
], maps=maps)
# >>> assert tm.equal(tm)
# >>> assert tm.equal(tm)
...
@@ -2552,7 +2552,7 @@ class TensorMaps(TensorFields):
...
@@ -2552,7 +2552,7 @@ class TensorMaps(TensorFields):
... [2., 2., 2.],
... [2., 2., 2.],
... [3., 3., 3.],
... [3., 3., 3.],
... [4., 4., 4.]])
... [4., 4., 4.]])
>>> assert np.array_equal(c.maps[
0
], [[0, 1, 2], [0, 3, 4]])
>>> assert np.array_equal(c.maps[
3
], [[0, 1, 2], [0, 3, 4]])
>>> assert np.array_equal(c.maps[1], [[0], [0]])
>>> assert np.array_equal(c.maps[1], [[0], [0]])
...
@@ -2604,9 +2604,9 @@ class TensorMaps(TensorFields):
...
@@ -2604,9 +2604,9 @@ class TensorMaps(TensorFields):
... [4, 4, 4],
... [4, 4, 4],
... [5, 5, 5]])
... [5, 5, 5]])
True
True
>>> assert c.maps[
0
].equal([[0, 1, 2], [0, 1, 3]])
>>> assert c.maps[
3
].equal([[0, 1, 2], [0, 1, 3]])
>>> assert c.maps[
0
].fields[0].equal([5, 9])
>>> assert c.maps[
3
].fields[0].equal([5, 9])
>>> assert c.maps[
0
].fields[1].equal([6, 0])
>>> assert c.maps[
3
].fields[1].equal([6, 0])
"""
"""
remove_condition
=
np
.
array
(
remove_condition
)
remove_condition
=
np
.
array
(
remove_condition
)
...
@@ -2646,9 +2646,9 @@ class TensorMaps(TensorFields):
...
@@ -2646,9 +2646,9 @@ class TensorMaps(TensorFields):
... [4, 4, 4],
... [4, 4, 4],
... [5, 5, 5]])
... [5, 5, 5]])
True
True
>>> assert c.maps[
0
].equal(np.array([[0, 1, 2], [0, 1, 3]]))
>>> assert c.maps[
3
].equal(np.array([[0, 1, 2], [0, 1, 3]]))
>>> assert c.maps[
0
].fields[0].equal([5, 9])
>>> assert c.maps[
3
].fields[0].equal([5, 9])
>>> assert c.maps[
0
].fields[1].equal([6, 0])
>>> assert c.maps[
3
].fields[1].equal([6, 0])
"""
"""
keep_condition
=
np
.
array
(
keep_condition
)
keep_condition
=
np
.
array
(
keep_condition
)
...
@@ -2746,7 +2746,7 @@ class TensorMaps(TensorFields):
...
@@ -2746,7 +2746,7 @@ class TensorMaps(TensorFields):
>>> mp_description = m.disjoint_map(0)
>>> mp_description = m.disjoint_map(0)
>>> parts = m.parts(mp_description)
>>> parts = m.parts(mp_description)
>>> aa, ba = parts
>>> aa, ba = parts
>>> assert aa.maps[
0
].equal(ba.maps[
0
])
>>> assert aa.maps[
3
].equal(ba.maps[
3
])
>>> assert aa.equal(a)
>>> assert aa.equal(a)
>>> assert ba.equal(b)
>>> assert ba.equal(b)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment