From 376b0b1798fb9c2002d7278bf907cd2b59a493e6 Mon Sep 17 00:00:00 2001 From: Vedant Rathore Date: Fri, 3 Feb 2017 16:36:56 +0530 Subject: [PATCH] Added exception and unittest for dist_mat_to_vec of analysis/psa.py (Part of #597) --- package/MDAnalysis/analysis/psa.py | 3 ++- testsuite/MDAnalysisTests/analysis/test_psa.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/psa.py b/package/MDAnalysis/analysis/psa.py index c0995e2024e..4850c24cf74 100644 --- a/package/MDAnalysis/analysis/psa.py +++ b/package/MDAnalysis/analysis/psa.py @@ -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" diff --git a/testsuite/MDAnalysisTests/analysis/test_psa.py b/testsuite/MDAnalysisTests/analysis/test_psa.py index 45ee8da6e27..a5cc3df74a9 100644 --- a/testsuite/MDAnalysisTests/analysis/test_psa.py +++ b/testsuite/MDAnalysisTests/analysis/test_psa.py @@ -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.''' @@ -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