Author: bugman Date: Mon Jan 21 16:56:58 2008 New Revision: 4876 URL: http://svn.gna.org/viewcvs/relax?rev=4876&view=rev Log: Wrote a unit test for the maths_fns.n_state_model.func() optimisation target function. Added: branches/N_state_model/test_suite/unit_tests/_maths_fns/test_n_state_model.py Added: branches/N_state_model/test_suite/unit_tests/_maths_fns/test_n_state_model.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/unit_tests/_maths_fns/test_n_state_model.py?rev=4876&view=auto ============================================================================== --- branches/N_state_model/test_suite/unit_tests/_maths_fns/test_n_state_model.py (added) +++ branches/N_state_model/test_suite/unit_tests/_maths_fns/test_n_state_model.py Mon Jan 21 16:56:58 2008 @@ -1,0 +1,55 @@ +############################################################################### +# # +# Copyright (C) 2008 Edward d'Auvergne # +# # +# This file is part of the program relax. # +# # +# relax 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 2 of the License, or # +# (at your option) any later version. # +# # +# relax 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 relax; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +############################################################################### + +# Python module imports. +from numpy import array, float64, ones +from unittest import TestCase + +# relax module imports. +from maths_fns.n_state_model import N_state_opt + + +class Test_n_state_model(TestCase): + """Unit tests for the maths_fns.n_state_model relax module.""" + + def test_func1(self): + """Unit test 1 of the func() method.""" + + # Init vals. + N = 2 + init_params = array([0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], float64) + full_tensors = array([[[1.0, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, -1.5]], + [[1.0, 1.0, 0.0], [1.0, 0.5, 0.0], [0.0, 0.0, -1.5]], + [[1.0, 0.0, 1.0], [0.0, 0.5, 0.0], [1.0, 0.0, -1.5]]], float64) + red_data = array([1.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0], float64) + err = ones(3*5, float64) + + # Set up the class. + model = N_state_opt(N=2, init_params=init_params, full_tensors=full_tensors, red_data=red_data, red_errors=err) + + # Call the target function 3 times. + for i in xrange(3): + # Target function. + chi2 = model.func(init_params) + + # Test that the chi2 value is zero each time! + self.assertEqual(chi2, 0.0)