Skip to content

Commit 2985fbd

Browse files
committed
add test for boundsToRestraints
1 parent 71b8b4f commit 2985fbd

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/test_fitrecipe.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,40 @@ def testResidual(self):
297297

298298

299299
# ----------------------------------------------------------------------------
300+
def test_boundsToRestraints():
301+
recipe = FitRecipe("recipe")
302+
303+
# create a bounded variable
304+
recipe.create_new_variable("var1", 1)
305+
recipe.var1.bounds = (-1, 1)
306+
307+
# apply restraints from bounds
308+
recipe.boundsToRestraints(sig=2, scaled=True)
309+
restraints = list(recipe._restraints)
310+
assert len(restraints) == 1
311+
r = restraints[0]
312+
assert r.lb == -1
313+
assert r.ub == 1
314+
assert r.sig == 2
315+
assert r.scaled is True
316+
317+
318+
def test_convert_bounds_to_restraints():
319+
recipe = FitRecipe("recipe")
320+
# create a bounded variable
321+
recipe.create_new_variable("var1", 1)
322+
recipe.var1.bounds = (-1, 1)
323+
# apply restraints from bounds
324+
recipe.convert_bounds_to_restraints(sig=2, scaled=True)
325+
restraints = list(recipe._restraints)
326+
assert len(restraints) == 1
327+
r = restraints[0]
328+
assert r.lb == -1
329+
assert r.ub == 1
330+
assert r.sig == 2
331+
assert r.scaled is True
332+
333+
300334
def testPrintFitHook(capturestdout):
301335
"check output from default PrintFitHook."
302336
recipe = FitRecipe("recipe")

0 commit comments

Comments
 (0)