From 17c732d94cc9c40671a9a7635177c2d5017f5902 Mon Sep 17 00:00:00 2001 From: NicolaCourtier <45851982+NicolaCourtier@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:00:44 +0000 Subject: [PATCH] Add test of StandaloneCosts --- tests/unit/test_optimisation.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/test_optimisation.py b/tests/unit/test_optimisation.py index b9d3b041..406c89ee 100644 --- a/tests/unit/test_optimisation.py +++ b/tests/unit/test_optimisation.py @@ -1,6 +1,7 @@ import pybop import numpy as np import pytest +from pybop.costs.standalone import StandaloneCost class TestOptimisation: @@ -8,6 +9,20 @@ class TestOptimisation: A class to test the optimisation class. """ + @pytest.mark.unit + def test_standalone(self): + # Build an Optimisation problem with a StandaloneCost + cost = StandaloneCost() + + opt = pybop.Optimisation(cost=cost, optimiser=pybop.NLoptOptimize) + + assert len(opt.x0) == opt.n_parameters + + x, final_cost = opt.run() + + np.testing.assert_allclose(x, 0, atol=1e-2) + np.testing.assert_allclose(final_cost, 42, atol=1e-2) + @pytest.mark.unit def test_prior_sampling(self): # Tests prior sampling