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, 2010 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.minimisation import Minimisation 
 28  from relax_errors import RelaxError, RelaxBoolError, RelaxIntError, RelaxIntListIntError, RelaxListError, RelaxListNumError, RelaxNoneError, RelaxNoneListNumError, RelaxNoneNumError, RelaxNumError, RelaxStrError 
 29  from test_suite.unit_tests.minimisation_testing_base import Minimisation_base_class 
 30   
 31  # Unit test imports. 
 32  from 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 # Instantiate the user function class. 39 minimisation_fns = Minimisation() 40 41
43 """The verbosity arg test of the calc() user function.""" 44 45 # Loop over the data types. 46 for data in DATA_TYPES: 47 # Catch the int and bin arguments, and skip them. 48 if data[0] == 'int' or data[0] == 'bin': 49 continue 50 51 # The argument test. 52 self.assertRaises(RelaxIntError, self.minimisation_fns.calc, verbosity=data[1])
53 54
56 """The lower arg test of the grid_search() user function.""" 57 58 # Loop over the data types. 59 for data in DATA_TYPES: 60 # Catch the None and int, float, and number list arguments arguments, and skip them. 61 if data[0] == 'None' or data[0] == 'int list' or data[0] == 'float list' or data[0] == 'number list': 62 continue 63 64 # The argument test. 65 self.assertRaises(RelaxNoneListNumError, self.minimisation_fns.grid_search, lower=data[1])
66 67
69 """The upper arg test of the grid_search() user function.""" 70 71 # Loop over the data types. 72 for data in DATA_TYPES: 73 # Catch the None and int, float, and number list arguments arguments, and skip them. 74 if data[0] == 'None' or data[0] == 'int list' or data[0] == 'float list' or data[0] == 'number list': 75 continue 76 77 # The argument test. 78 self.assertRaises(RelaxNoneListNumError, self.minimisation_fns.grid_search, upper=data[1])
79 80
82 """The inc arg test of the grid_search() user function.""" 83 84 # Loop over the data types. 85 for data in DATA_TYPES: 86 # Catch the bin, int, and interger list arguments, and skip them. 87 if data[0] == 'bin' or data[0] == 'int' or data[0] == 'int list' or data[0] == 'none list': 88 continue 89 90 # The argument test. 91 self.assertRaises(RelaxIntListIntError, self.minimisation_fns.grid_search, inc=data[1])
92 93
95 """The constraints arg test of the grid_search() user function.""" 96 97 # Loop over the data types. 98 for data in DATA_TYPES: 99 # Catch the bool arguments, and skip them. 100 if data[0] == 'bool': 101 continue 102 103 # The argument test. 104 self.assertRaises(RelaxBoolError, self.minimisation_fns.grid_search, constraints=data[1])
105 106
108 """The verbosity arg test of the grid_search() user function.""" 109 110 # Loop over the data types. 111 for data in DATA_TYPES: 112 # Catch the int and bin arguments, and skip them. 113 if data[0] == 'int' or data[0] == 'bin': 114 continue 115 116 # The argument test. 117 self.assertRaises(RelaxIntError, self.minimisation_fns.grid_search, verbosity=data[1])
118 119
121 """The test of the arguments of the minimise() user function.""" 122 123 # No arguments. 124 self.assertRaises(RelaxNoneError, self.minimisation_fns.minimise) 125 126 # Loop over the data types. 127 for data in DATA_TYPES: 128 # Catch the str arguments, and skip them. 129 if data[0] == 'str': 130 continue 131 132 # The argument test. 133 self.assertRaises(RelaxStrError, self.minimisation_fns.minimise, data[1]) 134 self.assertRaises(RelaxStrError, self.minimisation_fns.minimise, 'a', data[1]) 135 self.assertRaises(RelaxStrError, self.minimisation_fns.minimise, 'a', 'b', data[1])
136 137
139 """The test of a bad keyword argument in the minimise() user function.""" 140 141 # Loop over the data types. 142 for data in DATA_TYPES: 143 # The argument test. 144 self.assertRaises(RelaxError, self.minimisation_fns.minimise, 'Newton', step_tol=data[1])
145 146
148 """The func_tol arg test of the minimise() user function.""" 149 150 # Loop over the data types. 151 for data in DATA_TYPES: 152 # Catch the float, bin, and int arguments, and skip them. 153 if data[0] == 'float' or data[0] == 'bin' or data[0] == 'int': 154 continue 155 156 # The argument test. 157 self.assertRaises(RelaxNumError, self.minimisation_fns.minimise, 'Newton', func_tol=data[1])
158 159
161 """The grad_tol arg test of the minimise() user function.""" 162 163 # Loop over the data types. 164 for data in DATA_TYPES: 165 # Catch the None, float, bin, and int arguments, and skip them. 166 if data[0] == 'None' or data[0] == 'float' or data[0] == 'bin' or data[0] == 'int': 167 continue 168 169 # The argument test. 170 self.assertRaises(RelaxNoneNumError, self.minimisation_fns.minimise, 'Newton', grad_tol=data[1])
171 172
174 """The max_iterations arg test of the minimise() user function.""" 175 176 # Loop over the data types. 177 for data in DATA_TYPES: 178 # Catch the bin and int arguments, and skip them. 179 if data[0] == 'bin' or data[0] == 'int': 180 continue 181 182 # The argument test. 183 self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 'Newton', max_iterations=data[1])
184 185
187 """The constraints arg test of the minimise() user function.""" 188 189 # Loop over the data types. 190 for data in DATA_TYPES: 191 # Catch the bool arguments, and skip them. 192 if data[0] == 'bool': 193 continue 194 195 # The argument test. 196 self.assertRaises(RelaxBoolError, self.minimisation_fns.minimise, 'Newton', constraints=data[1])
197 198
200 """The scaling arg test of the minimise() user function.""" 201 202 # Loop over the data types. 203 for data in DATA_TYPES: 204 # Catch the bool arguments, and skip them. 205 if data[0] == 'bool': 206 continue 207 208 # The argument test. 209 self.assertRaises(RelaxBoolError, self.minimisation_fns.minimise, 'Newton', scaling=data[1])
210 211
213 """The verbosity arg test of the minimise() user function.""" 214 215 # Loop over the data types. 216 for data in DATA_TYPES: 217 # Catch the bin and int arguments, and skip them. 218 if data[0] == 'bin' or data[0] == 'int': 219 continue 220 221 # The argument test. 222 self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 'Newton', verbosity=data[1])
223