- Timestamp:
- 11/25/12 05:10:28 (3 years ago)
- Location:
- branches/decorate
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/test_wrapper.py
r598 r600 1 1 from wrapper import * 2 from mystic.math import almostEqual 2 3 3 4 def test_nested(): … … 155 156 from numpy import array, arange 156 157 x = range(11) 157 assert round(mean(set_mean(x, 5.0)), 15) == 5.0158 assert almostEqual(mean(set_mean(x, 5.0)), 5.0) 158 159 159 160 … … 181 182 discrete_squared.samples([1.0, 7.0]) 182 183 assert discrete_squared(5.6) == 7.0**2 184 185 186 def test_constrain(): 187 188 from mystic.math.measures import mean, spread 189 from mystic.math.measures import impose_mean, impose_spread 190 def mean_constraint(x): 191 return impose_mean(5.0, x) 192 193 def range_constraint(x): 194 return impose_spread(5.0, x) 195 196 @nested(inner=range_constraint) #XXX: @with_range(5.0) 197 @nested(inner=mean_constraint) #XXX: @with_mean(5.0) 198 def constraints(x): 199 return x 200 201 def cost(x): 202 return abs(sum(x) - 5.0) 203 204 from mystic.solvers import fmin_powell 205 from numpy import array 206 x = array([1,2,3,4,5]) 207 y = fmin_powell(cost, x, constraints=constraints, disp=False) 208 209 assert mean(y) == 5.0 210 assert spread(y) == 5.0 211 assert almostEqual(cost(y), 4*(5.0)) 183 212 184 213 … … 197 226 test_target_bounded() 198 227 test_bounce_bounded() 228 test_constrain() 199 229 200 230
Note: See TracChangeset
for help on using the changeset viewer.