Skip to content

Commit

Permalink
Add test of StandaloneCosts
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaCourtier authored Nov 17, 2023
1 parent d46c3c3 commit 17c732d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/unit/test_optimisation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import pybop
import numpy as np
import pytest
from pybop.costs.standalone import StandaloneCost


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
Expand Down

0 comments on commit 17c732d

Please sign in to comment.