Skip to content

Commit

Permalink
Ensure warning raised when zero vector passed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlainKadar committed Dec 4, 2023
1 parent 236f99e commit 5e1cbc3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_order_Nematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ def test_imperfect(self):
npt.assert_allclose(op_perp.nematic_tensor, np.diag([-0.5, 1, -0.5]), atol=1e-1)
assert not np.all(op_perp.nematic_tensor == np.diag([-0.5, 1, -0.5]))

def test_warning(self):
"""Test that supplying a zero orientation vector raises a warning."""
N = 10000
np.random.seed(0)
u = [1, 0, 0]

# Generate orientations close to the u
orientations = np.random.normal(
np.repeat(np.expand_dims(u, axis=0), repeats=N, axis=0), 0.1
)

# Change first orientation to zero vector
orientations[0] = np.array([0,0,0])

op = freud.order.Nematic()

with pytest.warns(UserWarning):
op.compute(orientations)

def test_repr(self):
op = freud.order.Nematic()
assert str(op) == str(eval(repr(op)))

0 comments on commit 5e1cbc3

Please sign in to comment.