Skip to content

Commit

Permalink
Added exception and unittest for dist_mat_to_vec of analysis/psa.py (…
Browse files Browse the repository at this point in the history
…Part of MDAnalysis#597)
  • Loading branch information
vedantrathore committed Feb 3, 2017
1 parent 36acf58 commit 376b0b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package/MDAnalysis/analysis/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ def dist_mat_to_vec(N, i, j):
"""

if not (isinstance(N, numbers.Integral) or isinstance(i, numbers.Integral) or isinstance(j, numbers.Integral)):
raise ValueError("N, i, j all must be of type int")
err_str = "N, i, j all must be of type int"
raise ValueError(err_str)

if i < 0 or j < 0 or N < 2:
error_str = "Matrix indices are invalid; i and j must be greater than 0 and N must be greater the 2"
Expand Down
11 changes: 11 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ def test_dist_mat_to_vec_i_greater_j(self):
err_msg = "dist_mat_to_vec function returning wrong values"
assert_equal(PSA.dist_mat_to_vec(5, 4, 3), 9, err_msg)

def test_dist_mat_to_vec_input_numpy_integer_32(self):
"""Test whether inputs are supported as numpy integers rather than normal Integers"""
err_msg = "dist_mat_to_vec function returning wrong values"
assert_equal(PSA.dist_mat_to_vec(np.int32(5), np.int32(3), np.int32(4)), err_msg)

def test_dist_mat_to_vec_input_numpy_integer_16(self):
"""Test whether inputs are supported as numpy integers rather than normal Integers"""
err_msg = "dist_mat_to_vec function returning wrong values"
assert_equal(PSA.dist_mat_to_vec(np.int16(5), np.int16(3), np.int16(4)), err_msg)

class TestPSAExceptions(TestCase):
'''Tests for exceptions that should be raised
or caught by code in the psa module.'''
Expand Down Expand Up @@ -171,6 +181,7 @@ def test_dist_mat_to_vec_func_bad_integers(self):
with self.assertRaises(ValueError):
PSA.dist_mat_to_vec(5, float(6), 7)


class _BaseHausdorffDistance(TestCase):
'''Base Class setup and unit tests
for various Hausdorff distance
Expand Down

0 comments on commit 376b0b1

Please sign in to comment.