Skip to content

Commit

Permalink
feat: tests for deprecated/not impl. functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bhosale2 committed Jun 1, 2022
1 parent 655e2f9 commit 376ece2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions elastica/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def nodes_to_elements(input):
# Remove the function beyond v0.4.0
"This function is now deprecated (issue #80). Please use "
"elastica.interaction.node_to_element_mass_or_force() "
"instead for node-to-element interpolation of mass/forces."
"instead for node-to-element interpolation of mass/forces. "
"The function will be removed in the future (v0.3.1).",
DeprecationWarning,
)
Expand Down Expand Up @@ -774,8 +774,8 @@ def node_to_element_pos_or_vel(vector_in_node_frame):
raise NotImplementedError(
"This function is removed in v0.3.0. For node-to-element interpolation please use: \n"
"elastica.interaction.node_to_element_position() for rod position \n"
"elastica.interaction.node_to_element_velocity() for rod velocity."
"For detail, look at issue #80."
"elastica.interaction.node_to_element_velocity() for rod velocity. \n"
"For detail, refer to issue #80."
)


Expand Down
35 changes: 35 additions & 0 deletions tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
find_slipping_elements,
AnisotropicFrictionalPlane,
node_to_element_mass_or_force,
nodes_to_elements,
SlenderBodyTheory,
)

Expand Down Expand Up @@ -376,6 +377,25 @@ def test_node_to_element_mass_or_force(self, n_elem):
assert_allclose(correct_output, output, atol=Tolerance.atol())
assert_allclose(np.sum(input), np.sum(output), atol=Tolerance.atol())

@pytest.mark.parametrize("n_elem", [2, 3, 5, 10, 20])
def test_deprecated_nodes_to_elements(self, n_elem):
random_vector = np.random.rand(3).reshape(3, 1)
input = np.repeat(random_vector, n_elem + 1, axis=1)
input[..., 0] *= 0.5
input[..., -1] *= 0.5
correct_output = np.repeat(random_vector, n_elem, axis=1)
correct_warning_message = (
"This function is now deprecated (issue #80). Please use "
"elastica.interaction.node_to_element_mass_or_force() "
"instead for node-to-element interpolation of mass/forces. "
"The function will be removed in the future (v0.3.1)."
)
with pytest.warns(DeprecationWarning) as record:
output = nodes_to_elements(input)
assert record[0].message.args[0] == correct_warning_message
assert_allclose(correct_output, output, atol=Tolerance.atol())
assert_allclose(np.sum(input), np.sum(output), atol=Tolerance.atol())


class TestAnisotropicFriction:
def initializer(
Expand Down Expand Up @@ -753,6 +773,7 @@ def test_static_rolling_friction_total_torque_larger_than_static_friction_force(
sum_over_elements,
node_to_element_position,
node_to_element_velocity,
node_to_element_pos_or_vel,
)

# These functions are used in the case if Numba is available
Expand Down Expand Up @@ -825,6 +846,20 @@ def test_node_to_element_velocity(self, n_elem):
)
assert_allclose(correct_output, output, atol=Tolerance.atol())

@pytest.mark.parametrize("n_elem", [2, 3, 5, 10, 20])
def test_not_impl_error_for_node_to_element_pos_or_vel(self, n_elem):
random = np.random.rand() # Adding some random numbers
input_velocity = random * np.ones((3, n_elem + 1))
error_message = (
"This function is removed in v0.3.0. For node-to-element interpolation please use: \n"
"elastica.interaction.node_to_element_position() for rod position \n"
"elastica.interaction.node_to_element_velocity() for rod velocity. \n"
"For detail, refer to issue #80."
)
with pytest.raises(NotImplementedError) as error_info:
node_to_element_pos_or_vel(input_velocity)
assert error_info.value.args[0] == error_message

except ImportError:
pass

Expand Down

0 comments on commit 376ece2

Please sign in to comment.