From 900ca28242ae6d4f36fd056239d7ac03e03aace5 Mon Sep 17 00:00:00 2001 From: Ipuch Date: Wed, 19 Jul 2023 11:23:35 -0400 Subject: [PATCH 1/2] one test to cover show_bounds = True --- tests/test_plot_show_bounds.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test_plot_show_bounds.py diff --git a/tests/test_plot_show_bounds.py b/tests/test_plot_show_bounds.py new file mode 100644 index 000000000..47ead9d23 --- /dev/null +++ b/tests/test_plot_show_bounds.py @@ -0,0 +1,32 @@ +import os +from bioptim import BoundsList +from bioptim.limits.path_conditions import Bounds + + +def test_pendulum_show_bounds(): + """ + It doesn"t test that bounds are shown, b + but we test that the bounds are added to the plot" + """ + from bioptim.examples.sqp_method import pendulum as ocp_module + + bioptim_folder = os.path.dirname(ocp_module.__file__) + + ocp = ocp_module.prepare_ocp( + biorbd_model_path=bioptim_folder + "/models/pendulum.bioMod", + final_time=1, + n_shooting=30, + assume_phase_dynamics=True, + ) + # Test the keys in the dict ocp.nlp[0].plot + assert ['q_states', 'qdot_states', 'tau_controls'] == list(ocp.nlp[0].plot.keys()) + + for key, plot in ocp.nlp[0].plot.items(): + assert isinstance(plot.bounds, Bounds) + assert plot.bounds.shape == (2, 3) + if "states" in key: + state = key.split("_")[0] + assert ocp.nlp[0].x_bounds[state] == plot.bounds + elif "controls" in key: + control = key.split("_")[0] + assert ocp.nlp[0].u_bounds[control] == plot.bounds From af96943eaf42c8bf0717124c0cf0ed733f2fa5de Mon Sep 17 00:00:00 2001 From: Ipuch Date: Wed, 19 Jul 2023 11:24:38 -0400 Subject: [PATCH 2/2] black --- tests/test_plot_show_bounds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plot_show_bounds.py b/tests/test_plot_show_bounds.py index 47ead9d23..c34282e31 100644 --- a/tests/test_plot_show_bounds.py +++ b/tests/test_plot_show_bounds.py @@ -19,7 +19,7 @@ def test_pendulum_show_bounds(): assume_phase_dynamics=True, ) # Test the keys in the dict ocp.nlp[0].plot - assert ['q_states', 'qdot_states', 'tau_controls'] == list(ocp.nlp[0].plot.keys()) + assert ["q_states", "qdot_states", "tau_controls"] == list(ocp.nlp[0].plot.keys()) for key, plot in ocp.nlp[0].plot.items(): assert isinstance(plot.bounds, Bounds)