Skip to content

Commit

Permalink
tests: increase coverage, fix flaky threshold test.
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyPlanden committed Jul 20, 2024
1 parent 204b57a commit 7bae73c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,6 @@ $RECYCLE.BIN/
# Airspeed Velocity
*.asv/
results/

# Pycharm
*.idea/
17 changes: 15 additions & 2 deletions tests/unit/test_optimisation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import io
import sys
import warnings

import numpy as np
Expand Down Expand Up @@ -422,12 +424,23 @@ def test_halting(self, cost):
with pytest.raises(ValueError):
optim.set_max_evaluations(-1)

optim = pybop.Optimisation(cost=cost)
# Reset optim
optim = pybop.Optimisation(cost=cost, sigma0=0.015, verbose=True)

# Trigger threshold
# Confirm setting threshold == None
optim.set_threshold(None)
assert optim._threshold is None

# Confirm threshold halts
# Redirect stdout to capture print output
captured_output = io.StringIO()
sys.stdout = captured_output
optim.set_threshold(np.inf)
optim.run()
assert (
captured_output.getvalue().strip()
== "Halt: Objective function crossed threshold: inf."
)
optim.set_max_unchanged_iterations()

# Test callback and halting output
Expand Down

0 comments on commit 7bae73c

Please sign in to comment.