Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Jan 4, 2024
1 parent 1471eac commit 0cf4e1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions symfem/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ def get_mapping(
"""
function_name = mapname
if inverse:
mapname += "_inverse"
function_name += "_inverse"
if transpose:
mapname += "_transpose"
function_name += "_transpose"

if mapname not in globals():
raise ValueError(f"Invalid map name: {mapname}")
if function_name not in globals():
raise ValueError(f"Invalid map name: {function_name}")

return globals()[mapname]
return globals()[function_name]
22 changes: 22 additions & 0 deletions test/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,25 @@ def test_push_forward(
assert allequal(e.map_to_cell(vertices), e2.get_basis_functions())
except MappingNotImplemented:
pytest.xfail("Mapping not implemented for this element.")


@pytest.mark.parametrize("name, inverse, transpose, mapping", [
("identity", False, False, symfem.mappings.identity),
("l2", False, False, symfem.mappings.l2),
("covariant", False, False, symfem.mappings.covariant),
("contravariant", False, False, symfem.mappings.contravariant),
("double_covariant", False, False, symfem.mappings.double_covariant),
("double_contravariant", False, False, symfem.mappings.double_contravariant),
("identity", True, True, symfem.mappings.identity_inverse_transpose),
("l2", True, True, symfem.mappings.l2_inverse_transpose),
("covariant", True, True, symfem.mappings.covariant_inverse_transpose),
("contravariant", True, True, symfem.mappings.contravariant_inverse_transpose),
("identity", True, False, symfem.mappings.identity_inverse),
("l2", True, False, symfem.mappings.l2_inverse),
("covariant", True, False, symfem.mappings.covariant_inverse),
("contravariant", True, False, symfem.mappings.contravariant_inverse),
("double_covariant", True, False, symfem.mappings.double_covariant_inverse),
("double_contravariant", True, False, symfem.mappings.double_contravariant_inverse),
])
def test_get_mapping(name, inverse, transpose, mapping):
assert symfem.mappings.get_mapping(name, inverse=inverse, transpose=transpose) == mapping

0 comments on commit 0cf4e1f

Please sign in to comment.