Skip to content
GitLab
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
d2080189
Commit
d2080189
authored
May 18, 2020
by
dboe
Browse files
rebased TensorMaps tests
parent
e528b531
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/test_core.py
View file @
d2080189
...
...
@@ -245,7 +245,7 @@ class TensorMaps_Empty_Test(TensorMaps_Check, unittest.TestCase):
self
.
_maps_fields
=
[]
class
TensorFields_Test
(
Tensor
Fields_Empty_Test
):
class
TensorFields_Test
(
Tensor
s_Check
,
unittest
.
TestCase
):
def
setUp
(
self
):
base
=
[(
-
5
,
5
,
11
)]
*
3
self
.
_fields
=
[
tfields
.
Tensors
.
grid
(
*
base
,
coord_sys
=
'cylinder'
),
...
...
@@ -257,7 +257,7 @@ class TensorFields_Test(TensorFields_Empty_Test):
self
.
assertTrue
(
self
.
_fields
[
1
].
coord_sys
,
'cartesian'
)
class
TensorMaps_Test
(
Tensor
Maps_Empty_Test
):
class
TensorMaps_Test
(
Tensor
s_Check
,
unittest
.
TestCase
):
def
setUp
(
self
):
base
=
[(
-
1
,
1
,
3
)]
*
3
tensors
=
tfields
.
Tensors
.
grid
(
*
base
)
...
...
@@ -324,118 +324,7 @@ class TensorMaps_Indexing_Test(unittest.TestCase):
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'
])
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
):
class
TensorMaps_NoFields_Test
(
Tensors_Check
,
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
_inst
=
tfields
.
TensorMaps
(
[[
1
,
2
,
3
],
[
3
,
3
,
3
],
[
0
,
0
,
0
],
[
5
,
6
,
7
]],
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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