Author: bugman Date: Fri Mar 21 17:26:06 2014 New Revision: 22519 URL: http://svn.gna.org/viewcvs/relax?rev=22519&view=rev Log: Addition of a number of unit tests for the new lib.geometry.vectors.vector_angle() function. Added: trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py Modified: trunk/test_suite/unit_tests/_lib/_geometry/__init__.py Modified: trunk/test_suite/unit_tests/_lib/_geometry/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_lib/_geometry/__init__.py?rev=22519&r1=22518&r2=22519&view=diff ============================================================================== --- trunk/test_suite/unit_tests/_lib/_geometry/__init__.py (original) +++ trunk/test_suite/unit_tests/_lib/_geometry/__init__.py Fri Mar 21 17:26:06 2014 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2013 Edward d'Auvergne # +# Copyright (C) 2013-2014 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -24,5 +24,6 @@ 'test___init_', 'test_lines', 'test_pec', - 'test_rotations' + 'test_rotations', + 'test_vectors' ] Added: trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py?rev=22519&view=auto ============================================================================== --- trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py (added) +++ trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py Fri Mar 21 17:26:06 2014 @@ -0,0 +1,109 @@ +############################################################################### +# # +# Copyright (C) 2014 Edward d'Auvergne # +# # +# This file is part of the program relax (http://www.nmr-relax.com). # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +############################################################################### + +# Python module imports. +from math import pi +from numpy import array, float64 +from unittest import TestCase + +# relax module imports. +from lib.geometry.vectors import vector_angle + + +class Test_vectors(TestCase): + """Unit tests for the lib.geometry.vectors relax module.""" + + def test_vector_angle1(self): + """Test the vector_angle() function with the vectors [1, 0, 0] and [0, 1, 0].""" + + # Calculate the angle. + v1 = array([1, 0, 0], float64) + v2 = array([0, 1, 0], float64) + normal = array([0, 0, 1], float64) + angle = vector_angle(v1, v2, normal) + + # Check the angle. + self.assertAlmostEqual(angle, pi/2.0) + + + def test_vector_angle2(self): + """Test the vector_angle() function with the vectors [1, 0, 0] and [0, 2, 0].""" + + # Calculate the angle. + v1 = array([1, 0, 0], float64) + v2 = array([0, 2, 0], float64) + normal = array([0, 0, 1], float64) + angle = vector_angle(v1, v2, normal) + + # Check the angle. + self.assertAlmostEqual(angle, pi/2.0) + + + def test_vector_angle3(self): + """Test the vector_angle() function with the vectors [2, 0, 0] and [0, -2, 0].""" + + # Calculate the angle. + v1 = array([2, 0, 0], float64) + v2 = array([0, -2, 0], float64) + normal = array([0, 0, 1], float64) + angle = vector_angle(v1, v2, normal) + + # Check the angle. + self.assertAlmostEqual(angle, -pi/2.0) + + + def test_vector_angle4(self): + """Test the vector_angle() function with the vectors [2, 0, 0] and [2, 2, 0].""" + + # Calculate the angle. + v1 = array([2, 0, 0], float64) + v2 = array([2, 2, 0], float64) + normal = array([0, 0, 2], float64) + angle = vector_angle(v1, v2, normal) + + # Check the angle. + self.assertAlmostEqual(angle, pi/4.0) + + + def test_vector_angle5(self): + """Test the vector_angle() function with the vectors [2, 0, 0] and [2, 2, 0].""" + + # Calculate the angle. + v1 = array([2, 0, 0], float64) + v2 = array([2, 2, 0], float64) + normal = array([0, 0, -2], float64) + angle = vector_angle(v1, v2, normal) + + # Check the angle. + self.assertAlmostEqual(angle, -pi/4.0) + + + def test_vector_angle6(self): + """Test the vector_angle() function with the vectors [2, 2, 0] and [2, -2, 0].""" + + # Calculate the angle. + v1 = array([2, 2, 0], float64) + v2 = array([2, -2, 0], float64) + normal = array([0, 0, 2], float64) + angle = vector_angle(v1, v2, normal) + + # Check the angle. + self.assertAlmostEqual(angle, -pi/2.0)