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-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from unittest import TestCase 
 25   
 26  # relax module imports. 
 27  from prompt.interpreter import Interpreter 
 28  from relax_errors import RelaxError, RelaxBoolError, RelaxIntError, RelaxIntListIntError, RelaxListError, RelaxListNumError, RelaxNoneError, RelaxNoneListNumError, RelaxNoneNumError, RelaxNoneStrError, RelaxNumError, RelaxStrError 
 29  from test_suite.unit_tests.minimisation_testing_base import Minimisation_base_class 
 30   
 31  # Unit test imports. 
 32  from container import Container 
 33  from data_types import DATA_TYPES 
 34   
 35   
36 -class Test_minimisation(Minimisation_base_class, TestCase):
37 """Unit tests for the functions of the 'prompt.minimisation' module.""" 38
39 - def __init__(self, methodName=None):
40 """Set up the test case class for the system tests.""" 41 42 # Execute the base __init__ methods. 43 super(Test_minimisation, self).__init__(methodName) 44 45 # Load the interpreter. 46 self.interpreter = Interpreter(show_script=False, quit=False, raise_relax_error=True) 47 self.interpreter.populate_self() 48 self.interpreter.on(verbose=False) 49 50 # Place the user functions into a container. 51 self.minimisation_fns = Container() 52 self.minimisation_fns.calc = self.interpreter.calc 53 self.minimisation_fns.grid_search = self.interpreter.grid_search 54 self.minimisation_fns.minimise = self.interpreter.minimise
55 56
58 """The verbosity arg test of the calc() user function.""" 59 60 # Loop over the data types. 61 for data in DATA_TYPES: 62 # Catch the int and bin arguments, and skip them. 63 if data[0] == 'int' or data[0] == 'bin': 64 continue 65 66 # The argument test. 67 self.assertRaises(RelaxIntError, self.minimisation_fns.calc, verbosity=data[1])
68 69
71 """The lower arg test of the grid_search() user function.""" 72 73 # Loop over the data types. 74 for data in DATA_TYPES: 75 # Catch the None and int, float, and number list arguments arguments, and skip them. 76 if data[0] == 'None' or data[0] == 'int list' or data[0] == 'float list' or data[0] == 'number list': 77 continue 78 79 # The argument test. 80 self.assertRaises(RelaxNoneListNumError, self.minimisation_fns.grid_search, lower=data[1])
81 82
84 """The upper arg test of the grid_search() user function.""" 85 86 # Loop over the data types. 87 for data in DATA_TYPES: 88 # Catch the None and int, float, and number list arguments arguments, and skip them. 89 if data[0] == 'None' or data[0] == 'int list' or data[0] == 'float list' or data[0] == 'number list': 90 continue 91 92 # The argument test. 93 self.assertRaises(RelaxNoneListNumError, self.minimisation_fns.grid_search, upper=data[1])
94 95
97 """The inc arg test of the grid_search() user function.""" 98 99 # Loop over the data types. 100 for data in DATA_TYPES: 101 # Catch the bin, int, and interger list arguments, and skip them. 102 if data[0] == 'bin' or data[0] == 'int' or data[0] == 'int list' or data[0] == 'none list': 103 continue 104 105 # The argument test. 106 self.assertRaises(RelaxIntListIntError, self.minimisation_fns.grid_search, inc=data[1])
107 108
110 """The constraints arg test of the grid_search() user function.""" 111 112 # Loop over the data types. 113 for data in DATA_TYPES: 114 # Catch the bool arguments, and skip them. 115 if data[0] == 'bool': 116 continue 117 118 # The argument test. 119 self.assertRaises(RelaxBoolError, self.minimisation_fns.grid_search, constraints=data[1])
120 121
123 """The verbosity arg test of the grid_search() user function.""" 124 125 # Loop over the data types. 126 for data in DATA_TYPES: 127 # Catch the int and bin arguments, and skip them. 128 if data[0] == 'int' or data[0] == 'bin': 129 continue 130 131 # The argument test. 132 self.assertRaises(RelaxIntError, self.minimisation_fns.grid_search, verbosity=data[1])
133 134
136 """The test of a bad keyword argument in the minimise() user function.""" 137 138 # Loop over the data types. 139 for data in DATA_TYPES: 140 # The argument test. 141 self.assertRaises(RelaxError, self.minimisation_fns.minimise, 'Newton', step_tol=data[1])
142 143
145 """The min_algor arg test of the minimise() user function.""" 146 147 # Loop over the data types. 148 for data in DATA_TYPES: 149 # Catch the str argument, and skip it. 150 if data[0] == 'str': 151 continue 152 153 # The argument test. 154 self.assertRaises(RelaxStrError, self.minimisation_fns.minimise, data[1])
155 156
158 """The line_search arg test of the minimise() user function.""" 159 160 # Loop over the data types. 161 for data in DATA_TYPES: 162 # Catch the None and str arguments, and skip them. 163 if data[0] == 'None' or data[0] == 'str': 164 continue 165 166 # The argument test. 167 self.assertRaises(RelaxNoneStrError, self.minimisation_fns.minimise, 'Newton', line_search=data[1])
168 169
171 """The hessian_mod arg test of the minimise() user function.""" 172 173 # Loop over the data types. 174 for data in DATA_TYPES: 175 # Catch the None and str arguments, and skip them. 176 if data[0] == 'None' or data[0] == 'str': 177 continue 178 179 # The argument test. 180 self.assertRaises(RelaxNoneStrError, self.minimisation_fns.minimise, 'Newton', hessian_mod=data[1])
181 182
184 """The hessian_type arg test of the minimise() user function.""" 185 186 # Loop over the data types. 187 for data in DATA_TYPES: 188 # Catch the None and str arguments, and skip them. 189 if data[0] == 'None' or data[0] == 'str': 190 continue 191 192 # The argument test. 193 self.assertRaises(RelaxNoneStrError, self.minimisation_fns.minimise, 'Newton', hessian_type=data[1])
194 195
197 """The func_tol arg test of the minimise() user function.""" 198 199 # Loop over the data types. 200 for data in DATA_TYPES: 201 # Catch the float, bin, and int arguments, and skip them. 202 if data[0] == 'float' or data[0] == 'bin' or data[0] == 'int': 203 continue 204 205 # The argument test. 206 self.assertRaises(RelaxNumError, self.minimisation_fns.minimise, 'Newton', func_tol=data[1])
207 208
210 """The grad_tol arg test of the minimise() user function.""" 211 212 # Loop over the data types. 213 for data in DATA_TYPES: 214 # Catch the None, float, bin, and int arguments, and skip them. 215 if data[0] == 'None' or data[0] == 'float' or data[0] == 'bin' or data[0] == 'int': 216 continue 217 218 # The argument test. 219 self.assertRaises(RelaxNoneNumError, self.minimisation_fns.minimise, 'Newton', grad_tol=data[1])
220 221
223 """The max_iter arg test of the minimise() user function.""" 224 225 # Loop over the data types. 226 for data in DATA_TYPES: 227 # Catch the bin and int arguments, and skip them. 228 if data[0] == 'bin' or data[0] == 'int': 229 continue 230 231 # The argument test. 232 self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 'Newton', max_iter=data[1])
233 234
236 """The constraints arg test of the minimise() user function.""" 237 238 # Loop over the data types. 239 for data in DATA_TYPES: 240 # Catch the bool arguments, and skip them. 241 if data[0] == 'bool': 242 continue 243 244 # The argument test. 245 self.assertRaises(RelaxBoolError, self.minimisation_fns.minimise, 'Newton', constraints=data[1])
246 247
249 """The scaling arg test of the minimise() user function.""" 250 251 # Loop over the data types. 252 for data in DATA_TYPES: 253 # Catch the bool arguments, and skip them. 254 if data[0] == 'bool': 255 continue 256 257 # The argument test. 258 self.assertRaises(RelaxBoolError, self.minimisation_fns.minimise, 'Newton', scaling=data[1])
259 260
262 """The verbosity arg test of the minimise() user function.""" 263 264 # Loop over the data types. 265 for data in DATA_TYPES: 266 # Catch the bin and int arguments, and skip them. 267 if data[0] == 'bin' or data[0] == 'int': 268 continue 269 270 # The argument test. 271 self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 'Newton', verbosity=data[1])
272