Skip to content

Commit 6485e76

Browse files
committed
TST: Make website example tests more in-line with actual examples
1 parent 152ce10 commit 6485e76

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

sambo/_test.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,20 @@ class TestDocs(unittest.TestCase):
359359
def test_make_doc_plots(self):
360360
KWARGS = {
361361
'shgo': dict(n_init=30),
362-
'smbo': dict(n_init=30),
363362
'sceua': dict(n_complexes=3),
363+
'smbo': dict(n_init=30),
364364
}
365365
results = [
366366
minimize(
367367
rosen, bounds=[(-2., 2.)] * 2,
368368
constraints=lambda x: sum(x**2) <= 2**len(x),
369-
max_iter=100, method=method, rng=2,
369+
max_iter=50, method=method, rng=2,
370370
**KWARGS.get(method, {}),
371371
)
372372
for method in BUILTIN_METHODS
373373
]
374-
for res in results:
375-
self.assertAlmostEqual(res.fun, 0, places=0, msg=res)
374+
for i, res in enumerate(results):
375+
self.assertAlmostEqual(res.fun, 0, places=0, msg=(i, res))
376376

377377
PLOT_FUNCS = (
378378
plot_regret,
@@ -403,7 +403,7 @@ def test_website_example1(self):
403403
res = minimize(
404404
rosen, bounds=[(-2., 2.), ] * 2,
405405
constraints=lambda x: sum(x**2) <= 2**len(x),
406-
n_init=7, method='shgo', rng=0,
406+
method='shgo', rng=0,
407407
)
408408
print(type(res), res, sep='\n\n')
409409
self.assertAlmostEqual(res.fun, 0, places=0, msg=res)
@@ -417,10 +417,12 @@ def evaluate(x):
417417
return rosen(x)
418418

419419
results = []
420+
bounds = [(-2., 2.)] * 4 # 4D
420421
for estimator in BUILTIN_ESTIMATORS:
421-
optimizer = Optimizer(fun=None, bounds=[(-2, 2)] * 4, estimator=estimator, rng=0)
422+
optimizer = Optimizer(fun=None, bounds=bounds, estimator=estimator, rng=0)
422423

423-
for i in range(30):
424+
n_iter = 50
425+
for i in range(n_iter):
424426
suggested_x = optimizer.ask(n_candidates=1)
425427
y = [evaluate(x) for x in suggested_x]
426428
optimizer.tell(y)

0 commit comments

Comments
 (0)