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 Jan 23, 2017
1 parent 1b04205 commit 3af71be
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions testsuite/MDAnalysisTests/analysis/test_psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from numpy.testing import (TestCase, dec, assert_array_less,
assert_array_almost_equal, assert_,
assert_almost_equal)
assert_almost_equal, assert_equal)
import numpy as np

from MDAnalysisTests.datafiles import PSF, DCD, DCD2
Expand Down Expand Up @@ -94,15 +94,14 @@ def test_dendrogram_produced(self):
assert_(type(self.plot_data[1]) is dict, err_msg)

def test_dist_mat_to_vec_i_less_j(self):
"""Test that distance is correct if i < j"""
"""Test the index of corresponding distance vector is correct if i < j"""
err_msg = "dist_mat_to_vec function returning wrong values"
assert_(PSA.dist_mat_to_vec(5, 3, 4) is 9, err_msg)
assert_equal(PSA.dist_mat_to_vec(5, 3, 4), 9, err_msg)

def test_dist_mat_to_vec_i_greater_j(self):
"""Test that distance is correct if i < j"""
"""Test the index of corresponding distance vector is correct if i > j"""
err_msg = "dist_mat_to_vec function returning wrong values"
assert_(PSA.dist_mat_to_vec(5, 4, 3) is 9, err_msg)

assert_equal(PSA.dist_mat_to_vec(5, 4, 3), 9, err_msg)

class TestPSAExceptions(TestCase):
'''Tests for exceptions that should be raised
Expand All @@ -126,10 +125,12 @@ def test_get_coord_axes_bad_dims(self):
PSA.get_coord_axes(np.zeros((5,5,5,5)))

def test_dist_mat_to_vec_func_out_of_bounds(self):
"""Test that ValueError is raised when i or j is
"""Test that ValueError is raised when i or j or both are
out of bounds of N"""

with self.assertRaises(ValueError):
PSA.dist_mat_to_vec(5, 6, 4)
PSA.dist_mat_to_vec(5, 4, 6)
PSA.dist_mat_to_vec(5, 6, 6)

def test_dist_mat_to_vec_func_bad_integers(self):
Expand All @@ -138,7 +139,7 @@ def test_dist_mat_to_vec_func_bad_integers(self):

with self.assertRaises(ValueError):
PSA.dist_mat_to_vec(5, '6', '7')

PSA.dist_mat_to_vec(5, float(6), 7)

class _BaseHausdorffDistance(TestCase):
'''Base Class setup and unit tests
Expand Down

0 comments on commit 3af71be

Please sign in to comment.