Package test_suite :: Package unit_tests :: Package _prompt :: Module test_minimisation
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._prompt.test_minimisation

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from unittest import TestCase 
 24   
 25  # relax module imports. 
 26  from prompt.interpreter import Interpreter 
 27  from lib.errors import RelaxError, RelaxBoolError, RelaxIntError, RelaxIntListIntError, RelaxNoneListNumError, RelaxNoneNumError, RelaxNoneStrError, RelaxNumError, RelaxStrError 
 28  from test_suite.unit_tests.minimisation_testing_base import Minimisation_base_class 
 29   
 30  # Unit test imports. 
 31  from test_suite.unit_tests._prompt.container import Container 
 32  from test_suite.unit_tests._prompt.data_types import DATA_TYPES 
 33   
 34   
35 -class Test_minimisation(Minimisation_base_class, TestCase):
36 """Unit tests for the functions of the 'prompt.minimisation' module.""" 37
38 - def __init__(self, methodName=None):
39 """Set up the test case class for the system tests.""" 40 41 # Execute the base __init__ methods. 42 super(Test_minimisation, self).__init__(methodName) 43 44 # Load the interpreter. 45 self.interpreter = Interpreter(show_script=False, raise_relax_error=True) 46 self.interpreter.populate_self() 47 self.interpreter.on(verbose=False) 48 49 # Place the user functions into a container. 50 self.minimisation_fns = Container() 51 self.minimisation_fns.calc = self.interpreter.calc 52 self.minimisation_fns.grid_search = self.interpreter.grid_search 53 self.minimisation_fns.minimise = self.interpreter.minimise
54 55
57 """The verbosity arg test of the calc() user function.""" 58 59 # Loop over the data types. 60 for data in DATA_TYPES: 61 # Catch the int and bin arguments, and skip them. 62 if data[0] == 'int' or data[0] == 'bin': 63 continue 64 65 # The argument test. 66 self.assertRaises(RelaxIntError, self.minimisation_fns.calc, verbosity=data[1])
67 68
70 """The lower arg test of the grid_search() user function.""" 71 72 # Loop over the data types. 73 for data in DATA_TYPES: 74 # Catch the None and int, float, and number list arguments arguments, and skip them. 75 if data[0] == 'None' or data[0] == 'int list' or data[0] == 'float list' or data[0] == 'number list': 76 continue 77 78 # The argument test. 79 self.assertRaises(RelaxNoneListNumError, self.minimisation_fns.grid_search, lower=data[1])
80 81
83 """The upper arg test of the grid_search() user function.""" 84 85 # Loop over the data types. 86 for data in DATA_TYPES: 87 # Catch the None and int, float, and number list arguments arguments, and skip them. 88 if data[0] == 'None' or data[0] == 'int list' or data[0] == 'float list' or data[0] == 'number list': 89 continue 90 91 # The argument test. 92 self.assertRaises(RelaxNoneListNumError, self.minimisation_fns.grid_search, upper=data[1])
93 94
96 """The inc arg test of the grid_search() user function.""" 97 98 # Loop over the data types. 99 for data in DATA_TYPES: 100 # Catch the bin, int, and interger list arguments, and skip them. 101 if data[0] == 'bin' or data[0] == 'int' or data[0] == 'int list' or data[0] == 'none list': 102 continue 103 104 # The argument test. 105 self.assertRaises(RelaxIntListIntError, self.minimisation_fns.grid_search, inc=data[1])
106 107
109 """The constraints arg test of the grid_search() user function.""" 110 111 # Loop over the data types. 112 for data in DATA_TYPES: 113 # Catch the bool arguments, and skip them. 114 if data[0] == 'bool': 115 continue 116 117 # The argument test. 118 self.assertRaises(RelaxBoolError, self.minimisation_fns.grid_search, constraints=data[1])
119 120
122 """The verbosity arg test of the grid_search() user function.""" 123 124 # Loop over the data types. 125 for data in DATA_TYPES: 126 # Catch the int and bin arguments, and skip them. 127 if data[0] == 'int' or data[0] == 'bin': 128 continue 129 130 # The argument test. 131 self.assertRaises(RelaxIntError, self.minimisation_fns.grid_search, verbosity=data[1])
132 133
135 """The test of a bad keyword argument in the minimise() user function.""" 136 137 # Loop over the data types. 138 for data in DATA_TYPES: 139 # The argument test. 140 self.assertRaises(RelaxError, self.minimisation_fns.minimise, 'Newton', step_tol=data[1])
141 142
144 """The min_algor arg test of the minimise() user function.""" 145 146 # Loop over the data types. 147 for data in DATA_TYPES: 148 # Catch the str argument, and skip it. 149 if data[0] == 'str': 150 continue 151 152 # The argument test. 153 self.assertRaises(RelaxStrError, self.minimisation_fns.minimise, data[1])
154 155
157 """The line_search arg test of the minimise() user function.""" 158 159 # Loop over the data types. 160 for data in DATA_TYPES: 161 # Catch the None and str arguments, and skip them. 162 if data[0] == 'None' or data[0] == 'str': 163 continue 164 165 # The argument test. 166 self.assertRaises(RelaxNoneStrError, self.minimisation_fns.minimise, 'Newton', line_search=data[1])
167 168
170 """The hessian_mod arg test of the minimise() user function.""" 171 172 # Loop over the data types. 173 for data in DATA_TYPES: 174 # Catch the None and str arguments, and skip them. 175 if data[0] == 'None' or data[0] == 'str': 176 continue 177 178 # The argument test. 179 self.assertRaises(RelaxNoneStrError, self.minimisation_fns.minimise, 'Newton', hessian_mod=data[1])
180 181
183 """The hessian_type arg test of the minimise() user function.""" 184 185 # Loop over the data types. 186 for data in DATA_TYPES: 187 # Catch the None and str arguments, and skip them. 188 if data[0] == 'None' or data[0] == 'str': 189 continue 190 191 # The argument test. 192 self.assertRaises(RelaxNoneStrError, self.minimisation_fns.minimise, 'Newton', hessian_type=data[1])
193 194
196 """The func_tol arg test of the minimise() user function.""" 197 198 # Loop over the data types. 199 for data in DATA_TYPES: 200 # Catch the float, bin, and int arguments, and skip them. 201 if data[0] == 'float' or data[0] == 'bin' or data[0] == 'int': 202 continue 203 204 # The argument test. 205 self.assertRaises(RelaxNumError, self.minimisation_fns.minimise, 'Newton', func_tol=data[1])
206 207
209 """The grad_tol arg test of the minimise() user function.""" 210 211 # Loop over the data types. 212 for data in DATA_TYPES: 213 # Catch the None, float, bin, and int arguments, and skip them. 214 if data[0] == 'None' or data[0] == 'float' or data[0] == 'bin' or data[0] == 'int': 215 continue 216 217 # The argument test. 218 self.assertRaises(RelaxNoneNumError, self.minimisation_fns.minimise, 'Newton', grad_tol=data[1])
219 220
222 """The max_iter arg test of the minimise() user function.""" 223 224 # Loop over the data types. 225 for data in DATA_TYPES: 226 # Catch the bin and int arguments, and skip them. 227 if data[0] == 'bin' or data[0] == 'int': 228 continue 229 230 # The argument test. 231 self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 'Newton', max_iter=data[1])
232 233
235 """The constraints arg test of the minimise() user function.""" 236 237 # Loop over the data types. 238 for data in DATA_TYPES: 239 # Catch the bool arguments, and skip them. 240 if data[0] == 'bool': 241 continue 242 243 # The argument test. 244 self.assertRaises(RelaxBoolError, self.minimisation_fns.minimise, 'Newton', constraints=data[1])
245 246
248 """The scaling arg test of the minimise() user function.""" 249 250 # Loop over the data types. 251 for data in DATA_TYPES: 252 # Catch the bool arguments, and skip them. 253 if data[0] == 'bool': 254 continue 255 256 # The argument test. 257 self.assertRaises(RelaxBoolError, self.minimisation_fns.minimise, 'Newton', scaling=data[1])
258 259
261 """The verbosity arg test of the minimise() user function.""" 262 263 # Loop over the data types. 264 for data in DATA_TYPES: 265 # Catch the bin and int arguments, and skip them. 266 if data[0] == 'bin' or data[0] == 'int': 267 continue 268 269 # The argument test. 270 self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 'Newton', verbosity=data[1])
271