mailr25272 - in /trunk/test_suite/unit_tests/_target_functions: __init__.py test_relax_fit.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on August 26, 2014 - 11:35:
Author: bugman
Date: Tue Aug 26 11:35:25 2014
New Revision: 25272

URL: http://svn.gna.org/viewcvs/relax?rev=25272&view=rev
Log:
Created 2 unit tests for the target_functions.relax_fit relax C module.

These check the func() and dfunc() Python methods exposed by the module.


Added:
    trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py
Modified:
    trunk/test_suite/unit_tests/_target_functions/__init__.py

Modified: trunk/test_suite/unit_tests/_target_functions/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_target_functions/__init__.py?rev=25272&r1=25271&r2=25272&view=diff
==============================================================================
--- trunk/test_suite/unit_tests/_target_functions/__init__.py   (original)
+++ trunk/test_suite/unit_tests/_target_functions/__init__.py   Tue Aug 26 
11:35:25 2014
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2006 Edward d'Auvergne                                       
 #
+# Copyright (C) 2006-2014 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax (http://www.nmr-relax.com).         
 #
 #                                                                            
 #
@@ -21,5 +21,5 @@
 
 
 __all__ = [
-    ''
+    'test_relax_fit'
 ]

Added: trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py?rev=25272&view=auto
==============================================================================
--- trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py     
(added)
+++ trunk/test_suite/unit_tests/_target_functions/test_relax_fit.py     Tue 
Aug 26 11:35:25 2014
@@ -0,0 +1,78 @@
+###############################################################################
+#                                                                            
 #
+# 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 numpy import array, float64, zeros
+from unittest import TestCase
+
+# relax module imports.
+from target_functions.relax_fit import setup, func, dfunc
+
+
+class Test_relax_fit(TestCase):
+    """Unit tests for the target_functions.relax_fit relax C module."""
+
+    def setUp(self):
+        """Create a number of objects for the calculation and testing of the 
relaxation curve-fitting equations."""
+
+        # The parameter values at the minimum.
+        self.I0 = 1000
+        self.R = 1
+        self.params = [self.R, self.I0]
+
+        # The time points.
+        relax_times = [0, 1, 2, 3, 4]
+
+        # The intensities for the above I0 and R.
+        I = [1000.0, 367.879441171, 135.335283237, 49.7870683679, 
18.3156388887]
+
+        # The intensity errors.
+        errors = [10, 10, 10, 10, 10]
+
+        # The parameter scaling.
+        scaling_list = [1, 1]
+
+        # Setup the C module.
+        setup(num_params=2, num_times=len(relax_times), values=I, sd=errors, 
relax_times=relax_times, scaling_matrix=scaling_list)
+
+
+    def test_func(self):
+        """Unit test for the value returned by the func() function at the 
minimum."""
+
+        # Get the chi-squared value.
+        val = func(self.params)
+
+        # Assert that the value must be 0.0.
+        self.assertAlmostEqual(val, 0.0)
+
+
+    def test_dfunc(self):
+        """Unit test for the gradient returned by the dfunc() function at 
the minimum."""
+
+        # Get the chi-squared gradient.
+        grad = dfunc(self.params)
+
+        # Printout.
+        print("The gradient at the minimum is:\n%s" % grad)
+
+        # Assert that the elements must be 0.0.
+        self.assertAlmostEqual(grad[0], 0.0, 6)
+        self.assertAlmostEqual(grad[1], 0.0, 6)




Related Messages


Powered by MHonArc, Updated Tue Aug 26 11:40:02 2014